LoginSignup
0
0

More than 3 years have passed since last update.

DockerでつまづくLaravel Dusk何なのお前

Last updated at Posted at 2020-06-03

はじめに

色々事情があってブラウザテストすることになったんですよ。
そう言えばLaravelには「Dusk」っていうイカしたブラウザテストユニットがあったなとか思い出して、試しに使ってみました。
https://readouble.com/laravel/5.5/ja/dusk.html

↑のドキュメント通り、duskをインストールし、動かしてみたら

# php artisan dusk
Cannot load Xdebug - it was already loaded
Cannot load Xdebug - it was already loaded
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 1.29 seconds, Memory: 16.00MB

There was 1 error:


1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.19.76-linuxkit x86_64)

は? chromeのバイナリがないだと?

いい忘れてたけど、環境

OS/ミドルウェア/FW バージョン
CentOS 7.5
Apache 2.4.6
php 7.2.28
Laravel 5.5.46

これをDockerで組んでます。

chromeを入れてみる

んじゃ、素直に入れてみますかね。
CentOSはepel入れるとchromiumを入れることができるようになります。

$ yum install -y epel-release
$ yum install -y chromium 

よしよし、うごかしてみっかー。んー、なかなか応答が返ってこないなー、、、お、今度は /session がダメとか言ってくるなー。

1) Tests\Browser\AdminTest::testTop
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless"]}}}

--no-sandbox を入れてみる

なんか調べども調べども seleniumコンテナ入れろ みたいなのばっかなんですよね。なんか負けたような気がするじゃないですか。気の所為でしょうけど。

んで、たどり着いたのはこちら。
Laravel DuskをDockerコンテナ内で起動するまで

なんと、 --no-sandbox フラグを付けるだけだと……!?

DuskTestCase.phpに追記しましょ。

DuskTestCase.php
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox', //追記
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }

よし、これで動いた!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0