我正在为浏览器运行Laravel Dusk的示例测试,但是当我执行 php artisan dusk 时,我得到了一个错误
使用: * Ubuntu 18 Laravel 5.8 *黄昏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()
);
}
}
这是错误:
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)
答案 0 :(得分:0)
这与问题没有直接关系,但是由于我不容易找到针对Laravel 7+和Homestead 10.0.0上发生的同一错误的任何修复程序,因此我将介绍经过数小时研究得出的解决方案并希望它能帮助其他人解决此问题。
Homestead似乎不再支持Dusk。要安装使用Chromium的前提条件,您必须将Webdriver功能添加到import hudson.model.*
def thr = Thread.currentThread()
def build = thr?.executable
def jobname_param = "JOB_NAME"
def resolver = build.buildVariableResolver
def jobname = 'TEST/'+ resolver.resolve(jobname_param)
println "found jobname: '${jobname}'"
def project_url_param = "GITLAB_REPOSITORY_URL"
def resolver2 = build.buildVariableResolver
def project_url = resolver2.resolve(project_url_param)
println "found project_url: '${project_url}'"
def repoUrl = "https://example.com/gitlab/repoA/jenkinsfile-repo.git"
pipelineJob(jobname) {
parameters {
stringParam('GITLAB_REPOSITORY_URL', '', 'Set the Gitlab repository URL')
}
logRotator {
numToKeep(5)
daysToKeep(5)
}
definition {
cpsScm {
scm {
git {
remote {
url(repoUrl)
credentials('gitlab-test')
}
branches('master')
extensions {
cleanBeforeCheckout()
}
}
}
scriptPath("Jenkinsfile")
}
}
}
:
homestead.yaml
,然后通过运行 features:
- webdriver: true
重新设置。
之后,通过在homestead halt && homestead up --provision
的{{1}}方法中添加其他参数,确保Chromium以无头模式启动:
driverChrome()
大多数人会建议也使用tests/DuskTestCase.php
和 protected function driverChrome()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options)
);
}
标志,但是在使用安装了--no-sandbox
而不是--disable-dev-shm-usage
的webdriver功能正确配置Homestead之后,这些并不是我才能正常运行。
答案 1 :(得分:0)
您可以尝试从以下位置手动下载ChromeDriver official ChromeDriver downloads page。
wget https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
./chromedriver
答案 2 :(得分:0)
就我而言,我发现我需要将 --no-sandbox
添加到 tests/DuskTestCase.php
,因为我在 lxd 容器上以 root 身份运行。
我通过运行:vendor/laravel/dusk/bin/chromedriver-linux --log-level=ALL
并在另一个运行 php artisan dusk
的终端中发现了错误。它将显示日志,我能够从那里推断出问题。