在无头(无GUI)机器上运行Laravel Dusk

时间:2017-02-11 10:21:27

标签: php linux laravel laravel-5.4 laravel-dusk

随着Laravel 5.4的最近宣布,我想我会尝试一下。就像Reddit上的Ozymandias-X一样,我也对它感到沮丧。

我的设置

  • Windows 10作为主机;
  • CentOS 7作为访客(没有GUI安装,没有Vagrant)
  • Virtual Box的共享文件夹。

如果我打开机器并运行SwiftyUtils,我会收到以下信息:

php artisan dusk

我尝试关注Mike Smith's article,但手动执行[08:14 AM]-[root@php7]-[/var/www/html/admin]-[git master] # php artisan dusk PHPUnit 5.7.11 by Sebastian Bergmann and contributors. E 1 / 1 (100%) Time: 25.91 seconds, Memory: 10.00MB There was 1 error: 1) Tests\Browser\LoginTest::it_should_see_email_error_message Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"\/usr\/lib64\/chromium-browser\/chromedriver","args":["no-first-run"]}}} Operation timed out after 5001 milliseconds with 0 out of -1 bytes received /var/www/html/admin/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287 /var/www/html/admin/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121 /var/www/html/admin/tests/DuskTestCase.php:42 /var/www/html/admin/vendor/laravel/dusk/src/TestCase.php:180 /var/www/html/admin/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639 /var/www/html/admin/vendor/laravel/dusk/src/TestCase.php:181 /var/www/html/admin/vendor/laravel/dusk/src/TestCase.php:111 /var/www/html/admin/vendor/laravel/dusk/src/TestCase.php:85 /var/www/html/admin/tests/Browser/LoginTest.php:24 ERRORS! Tests: 1, Assertions: 1, Errors: 1. 并从DuskTestCase注释./vendor/laravel/dusk/bin/chromedriver-linux根本没有帮助。我也试过安装Xvfb并在port:0上手动运行它,同样的事情发生了。 最后,我尝试从static::startChromeDriver();(2.25)手动运行驱动程序,完全没有变化。

我正试图避免直接在Windows上运行它,因为我打算使用无头/无gui linux的CI进程,我将不得不设置我正在尝试的同样的事情。

3 个答案:

答案 0 :(得分:2)

注意:这不是可接受的答案,因为真正的问题在于Cent OS。这个答案只是一个建议,而我们没有为RedHat提供解决方案。

问题在于Cent OS。通过我在Ubuntu发行版上所做的一切,它很容易。基于This post om mediumthis gist足以让任何人前进。如果链接断开,我将在此突出显示一些要点。

依赖

# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps

运行Xvfb

Xvfb -ac :0 -screen 0 1280x1024x16 &

完成

答案 1 :(得分:2)

解决方案是使用no-sandbox 运行chrome,或者不以root身份运行。我创建了一个名为 dusk 的用户,在那个Dusk下工作没有任何问题。

login as: dusk
dusk@192.168.56.70's password:
Last login: Mon Mar  6 13:07:30 2017 from 192.168.56.1
[dusk@php7 ~]$ Xvfb -ac :0 -screen 0 1280x1024x16 &
[1] 2177
[dusk@php7 ~]$ cd /var/www/solucoesideais/laravel-dusk/
[dusk@php7 laravel-dusk]$ php artisan serve --host=127.0.0.1 --port=8000 --env=dusk.environment &
[2] 2186
[dusk@php7 laravel-dusk]$ Laravel development server started: <http://127.0.0.1:8000>

[dusk@php7 laravel-dusk]$ php artisan dusk
PHPUnit 5.7.15 by Sebastian Bergmann and contributors.

[Mon Mar  6 13:23:28 2017] 127.0.0.1:59146 [200]: /favicon.ico
.                                                                   1 / 1 (100%)

Time: 3.7 seconds, Memory: 10.00MB

OK (1 test, 1 assertion)
[dusk@php7 laravel-dusk]$

答案 2 :(得分:2)

对于其他在无头模式下遇到“黄昏”问题的人,请尝试一下:

DuskTestCase中,使用以下驱动程序功能:

/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--headless',
        '--no-sandbox',
    ]);

    return RemoteWebDriver::create(
            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )->setCapability('acceptInsecureCerts', TRUE)
    );
}

对我有用吗:-)