繁体   English   中英

浏览器的黄昏测试“DevToolsActivePort 文件不存在”

[英]Dusk Test for Browser “DevToolsActivePort file doesn't exist”

我正在为浏览器运行 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()
    );
}

}

这是错误:

    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)

这与问题没有直接关系,但由于我没有轻易找到对 Laravel 7+ 和 Homestead 10.0.0 上发生的相同错误的任何修复,我将在数小时的研究后提出我想出的解决方案,并试图希望它将帮助其他人遇到这个问题。

宅基地配置

Homestead 似乎不再支持 Dusk 了。 要安装使用 Chromium 的先决条件,您必须将 webdriver 功能添加到您的homestead.yaml

 features:
     - webdriver: true

然后通过运行homestead halt && homestead up --provision重新配置。

DuskTestCase 类

之后,通过在tests/DuskTestCase.phpdriverChrome()方法中添加其他参数,确保 Chromium 以无头模式启动:

    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标志,但是在使用安装google-chrome-stable而不是chromium-browser的 webdriver 功能正确配置 homestead 后,不需要这些让我正确运行。

您可以尝试从官方 ChromeDriver 下载页面手动下载 ChromeDriver。

wget https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip
unzip chromedriver_linux64.zip    
./chromedriver

就我而言,我发现我需要将--no-sandbox添加到tests/DuskTestCase.php因为我在 lxd 容器上以 root 身份运行。

我通过运行: vendor/laravel/dusk/bin/chromedriver-linux --log-level=ALL并在另一个运行php artisan dusk终端中发现了错误。 它将显示日志,我能够从那里推断出问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM