无法从Jenkins CI启动浏览器

时间:2016-04-28 17:42:21

标签: selenium-webdriver jenkins continuous-integration cucumber watir-webdriver

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

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'

2 个答案:

答案 0 :(得分:0)

其他人有类似的问题,解决方案看起来确保你有稳定版的Capybara和最新的selenium webdriver

unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

如果此解决方案有帮助,请告诉我们。

答案 1 :(得分:0)

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

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

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

No protocol specified

XDG_RUNTIME_DIR not set in the environment

Error: cannot open display: :0

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

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