Help us understand the problem. What is going on with this article?

E2E testをheroku ciで実施する

More than 1 year has passed since last update.

heroku ciでe2eテストを実施

構成

  • heroku ci
  • php7
  • phpunit
  • facebook/webdriver
  • chromedriver

Setting

  • heroku のbuildpackで提供されるgoogle chromeはbinaryの場所が環境変数GOOGLE_CHROME_SHIMで定義されているディレクトリにあるのでwebdriverにsetする必要がある
  • seleniumで入力などのオペレーションさせたい場合はheroku-buildpack-xvfb-google-chromeを使う
  • heroku-buildpack-xvfb-google-chromeを使う場合はheroku-16のstackでは動かないcedar-14を使う

Heroku settings

composer.json
{
  "name": "e2e",
  "description": "This app does one little thing",
  "stack": "cedar-14",
  "env": {
    "GOOGLE_CHROME_CHANNEL":"stable"
  },
  "environments": {
    "stack": "cedar-14",
    "test": {
      "buildpacks": [
        { "url": "heroku/php" },
        { "url": "https://github.com/heroku/heroku-buildpack-chromedriver" },
        { "url": "https://github.com/heroku/heroku-buildpack-xvfb-google-chrome" }
      ],
      "scripts": {
        "test": "phpunit tests"
      }
    }
  }
}

Test example

E2eTest.php
<?php
use PHPUnit\Framework\TestCase;
use Facebook\WebDriver\Chrome\ChromeDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
class E2eTest extends TestCase
{

    protected $driver;

    protected function setUp()
    {
        putenv('webdriver.chrome.driver=/app/.chromedriver/bin/chromedriver');

        $options = new ChromeOptions();

        $chromeBinary = getenv("GOOGLE_CHROME_SHIM");

        $options->setBinary($chromeBinary);

        $capabilities = DesiredCapabilities::chrome();

        $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);

        $this->driver = ChromeDriver::start($capabilities);
    }

    /**
     * @large
     */
    public function testTitle()
    {
        $this->driver->get('https://www.google.co.jp/');
        $title = $this->driver->getTitle();
        $this->assertEquals($title, 'Google');
    }
}
?>
composer.json
{
  "require": {
    "php": ">=7.1.0",
    "facebook/webdriver": "^1.5"
  },
  "require-dev": {
      "phpunit/phpunit": ">=7.0"
  }
}

medewi
freelance engineer language:[scala,node.js,java] database:[mongodb,mysql,redshift,dynamodb] other:[aws,cloudformation,lambdafunction,opsworks] like:[surfing,camera,driving]
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away