Laravel Dusk でブラウザを立ち上げず、テストケースを流したいと思い、
設定した内容です。
ヘッドレス実行というもので、最新バージョンではヘッドレス実行が初期設定されているようなのですが、
Laravel Duskのバージョンが「1.0」だったため、入っておらず、対応しました。
実行環境
Laravel5.5
MacOS High Sierra 10.13.2
PHP 7.1
Docker 18.06.0
設定内容
DuskTestCase.php ファイルの記載を以下に変更します。
use Facebook\WebDriver\Chrome\ChromeOptions;
abstract class DuskTestCase extends BaseTestCase
・・・
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--lang=ja_JP',
'--window-size=1920,1920',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
つまづいたところ (2箇所)
つまづいたところ 1つ目
以下のエラーが発生したので、
Error: Class 'Tests\ChromeOptions' not found
こちらを追記しました。
use Facebook\WebDriver\Chrome\ChromeOptions;
つまづいたところ 2つ目
以下のエラーが発生したので、
Facebook\WebDriver\Exception\UnknownServerException: unknown error: Element is not clickable at point (1008, 432)
(Session info: headless chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.13.2 x86_64)
こちらを追記しました。
--window-size=1920,1920