15
13

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.

docker-composeでlaravel duskを動かす

Posted at

前提

  • composer を使って laravel/dusk をインストール済み。
  • ServiceProvider に Dusk を登録済み。
  • php artisan dusk:install を実行済み

こちらを参考にhttps://qiita.com/amymd/items/0a5f2705e29972d0d22e

コンテナにgoogle chromeをインストールしないと以下のようなエラーが出てしまう。

Facebook\WebDriver\Exception\UnknownServerException: unknown error: cannot find Chrome binary

seleniumコンテナを使うと簡単

docker-compose.yml
version: '2'
services:
  web:
    //省略

  db:
    //省略

  selenium:
    image: selenium/standalone-chrome
    ports:
      - 4444:4444

baseUrlをhttp://【webサーバーのサービス名】に変更
ここでは【web】です

docker-compose.yml
version: '2'
services:
  web: // ← これ

seleniumを使用するので以下のように変更

tests\DuskTestCase.php

// baseUrlを上書きする
// これを設定しないとchromeが「Site can't be reached」となり何をやってもエラーになってしまう。
protected function baseUrl()
{
     return 'http://web';
}


public static function prepare()
{
    // コメントアウト static::startChromeDriver();
}

//省略

protected function driver()
{
     return RemoteWebDriver::create(
        'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()
      );
}

これで成功しました

php artisan exec web bash php artisan dusk
15
13
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
15
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?