3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel DuskをDockerコンテナ内で起動するまで

Last updated at Posted at 2017-12-05

Laravel DuskをDocker内で起動するまで

とりあえずDockerfile書く。

Dockerfile
FROM laradock/php-fpm:1.4-70

RUN apt-get -y update && apt-get -y install chromium libgconf-2-4

諸々インストールしたら、 --no-sandbox フラグを追加。 Dockerだとrootで起動することになるため必要。

tests/DuskTestCase.php
<?php

namespace Tests;

use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
        static::startChromeDriver();
    }

    /**
     * Create the RemoteWebDriver instance.
     *
     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox', // <-- これ追加
        ]);

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

経緯

こんなエラーが出た。

1) Tests\Browser\ExampleTest::testBasicExample                                         
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"A
NY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--no-sandbox"]}}}
                                                                          
Failed to connect to localhost port 9515: Connection refused                  

Dockerfileでのlibgconf が盲点。

ldd ./vendor/laravel/dusk/bin/chromedriver-linux で気付いた。

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?