本文介绍了无法从Jenkins CI启动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins构建之后,通过调用rake任务触发黄瓜测试时,我无法在CI服务器(在本例中为Linux上的localhost)上启动浏览器。 Jenkins控制台日志如下。我很确定一切设置正确,因为我可以在服务器上通过命令行运行它成功。

I am unable to start the browser on the CI server (localhost on Linux in my case) when triggering a cucumber test via invoking a rake task after build from Jenkins. Jenkins console log is as below. I am pretty sure everything is set up properly, as I can run it successfully on the server via command line.

01:26:43 [cucumber] $ /usr/local/rvm/scripts/gems/ruby-2.3.0/bin/rake schedule_win_job:features --trace

01:26:43 ** Invoke schedule_win_job:features (first_time)

01:26:43 ** Execute schedule_win_job:features

01:26:43 /usr/local/rvm/scripts/rubies/ruby-2.3.0/bin/ruby -S bundle exec cucumber --tag @schedule_job --profile dev

**01:27:45 unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)**

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/firefox/launcher.rb:90:in `connect_until_stable'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/firefox/launcher.rb:55:in `block in launch'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/socket_lock.rb:43:in `locked'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/firefox/launcher.rb:51:in `launch'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/firefox/bridge.rb:43:in `initialize'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/driver.rb:53:in `new'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/driver.rb:53:in `for'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver.rb:84:in `for'

01:27:45 /usr/local/rvm/scripts/gems/ruby-2.3.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/browser.rb:46:in `initialize'


推荐答案

证明Jenkins用户的帐户性质不允许它在Jenkins服务器中运行GUI测试。

It turns out the account nature of Jenkins user does not allow it to run GUI tests within the Jenkins server.

Firefox是一个GUI应用程序,它需要连接到X服务器以发送其命令来绘制窗口等。通常,Jenkins设置为作为后台系统守护程序运行,无法访问任何X服务器会话。

Firefox is a GUI application and it needs to connect to an X server to send its commands to draw windows and such. Usually Jenkins is set up to run as a background system daemon that has no access to any X server session.

这是在尝试使用shell命令/ usr / bin / firefox在Jenkins构建中启动firefox时出现以下错误的原因。

This is the reason for below error when trying to launch firefox in a Jenkins build using shell command /usr/bin/firefox.

未指定协议

XDG_RUNTIME_DIR未在环境中设置

错误:无法打开display::0

因此,一个可能的解决方案是使用 pkexec 命令来触发具有root权限的测试(可能添加Jenkins用户到sudo组,以便它可以成功运行命令,但不建议由于安全问题,我试过它没有工作)。

Hence a possible solution would be to use pkexec command to trigger the test with root privilege (it might be possible to add the Jenkins user to the sudo group such that it can run the commands successfully, but not recommended due to security concern, and I tried it didn't work).

要通过 pkexec 实现全自动化,需要一些其他设置,例如禁用身份验证提示。我将更新一个更详细的答案,一旦我有逐步解决方案准备好。

To achieve full automation with pkexec needs some other settings, e.g. disable authentication prompts. I will update with a more detailed answer once I have the step-wise solution ready.

这篇关于无法从Jenkins CI启动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:27