Osc*_*ses 5 php testing laravel-dusk
我正在为浏览器运行 Laravel Dusk 的示例测试,但是当我执行php artisan dusk时出现错误
使用: * Ubuntu 18 * Laravel 5.8 * Dusk 5.1 * ChromeDriver 74 * apache2
这是我的 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',
'--window-size=1920,1080',
'--disable-dev-shm-usage',
'--no-sandbox'
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
// 'http://localhost:9515', DesiredCapabilities::phantomjs()
// 'http://localhost:9515', DesiredCapabilities::chrome()
);
}
Run Code Online (Sandbox Code Playgroud)
}
这是错误:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /snap/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.18.0-20-generic x86_64)
Run Code Online (Sandbox Code Playgroud)
小智 6
就我而言,我发现我需要添加,--no-sandbox因为tests/DuskTestCase.php我在 lxd 容器上以 root 身份运行。
我通过运行发现了错误:vendor/laravel/dusk/bin/chromedriver-linux --log-level=ALL并在另一个终端中运行php artisan dusk. 它将显示日志,我能够从那里推断出问题。
这与问题没有直接关系,但由于我没有轻易找到对 Laravel 7+ 和 Homestead 10.0.0 上发生的相同错误的任何修复,我将介绍经过数小时的研究并尝试希望得到的解决方案它将帮助其他遇到此问题的人。
Homestead 似乎不再支持 Dusk 开箱即用。要安装使用 Chromium 的先决条件,您必须将 webdriver 功能添加到您的homestead.yaml:
features:
- webdriver: true
Run Code Online (Sandbox Code Playgroud)
然后通过运行重新配置homestead halt && homestead up --provision。
driverChrome()之后,通过在方法中添加其他参数来确保 Chromium 以无头模式启动tests/DuskTestCase.php:
features:
- webdriver: true
Run Code Online (Sandbox Code Playgroud)
大多数人也会建议使用--no-sandbox和--disable-dev-shm-usage标志,但是在使用安装的 webdriver 功能(google-chrome-stable而不是 )正确配置 homestead 后chromium-browser,我不需要这些来正确运行。
| 归档时间: |
|
| 查看次数: |
3870 次 |
| 最近记录: |