【问题标题】:Running Laravel Dusk on Headless (no GUI) machine在 Headless(无 GUI)机器上运行 Laravel Dusk
【发布时间】:2017-06-29 17:00:28
【问题描述】:

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

我的设置

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

如果我只是打开我的机器并运行php artisan dusk,我会得到以下信息:

[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.

我尝试关注Mike Smith's article,但手动执行./vendor/laravel/dusk/bin/chromedriver-linux 并从 DuskTestCase 中注释掉static::startChromeDriver(); 一点帮助都没有。我也尝试安装 Xvfb 并手动在端口 :0 上运行它,同样的事情发生了。 最后,我尝试从/usr/lib64/chromium-browser/chromedriver (2.25) 手动运行驱动程序,完全没有任何变化。

我试图避免直接从 Windows 运行它,因为我打算使用一个无头/无 gui linux 的 CI 进程,我必须设置我现在正在尝试的相同的东西。

【问题讨论】:

  • Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Super UserUnix & Linux Stack Exchange 会是一个更好的提问地方。另见Where do I post questions about Dev Ops?
  • @jww 您提供的元链接的最佳答案以“StackOverflow 上应该允许 DevOps 问题”结尾。这个问题显然是关于每天在 SO 上讨论的广为人知的 PHP 框架,它旨在解决用这种框架(以及它的新特性)编写 TDD 的问题。对我的代表贡献最大的问题之一也不是关于修复代码行,而是设置一个 PHP 环境,旨在克服我们每天在工作中面临的问题 (stackoverflow.com/questions/35223926/…)

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


【解决方案1】:

注意:这不是公认的答案,因为真正的问题在于 Cent OS。这个答案只是一个建议,我们没有针对 RedHat 的解决方案。

问题出在 Cent 操作系统上。通过做我在 Ubuntu 发行版上所做的一切,它很容易工作。 This post om medium 基于this 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 &

完成

【讨论】:

    【解决方案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]$
    

    【讨论】:

      【解决方案3】:

      对于在无头模式下遇到 Dusk 问题的其他人,试试这个:

      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)
          );
      }
      

      为我做了诀窍:-)

      【讨论】:

      • 谢谢,acceptInsecureCerts 在 Centos7 虚拟机上成功了。
      猜你喜欢
      • 2017-09-06
      • 1970-01-01
      • 2018-04-02
      • 2018-03-07
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多