无法从 Jenkins 启动浏览器 CI
Unable to start browser from Jenkins CI
在从 Jenkins 构建后通过调用 rake 任务触发黄瓜测试时,我无法在 CI 服务器(在我的例子中是 Linux 上的本地主机)上启动浏览器。 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'
其他人遇到了类似的问题,解决方案看起来是为了确保您拥有稳定版本的 Capybara 和最新的 selenium webdriver
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
如果此解决方案有帮助,请告诉我!
事实证明,Jenkins 用户的帐户性质不允许它在 Jenkins 服务器内进行 运行 GUI 测试。
Firefox 是一个 GUI 应用程序,它需要连接到 X 服务器以发送其命令来绘制 windows 等。通常 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 实现完全自动化需要一些其他设置,例如禁用身份验证提示。准备好分步解决方案后,我将更新更详细的答案。
在从 Jenkins 构建后通过调用 rake 任务触发黄瓜测试时,我无法在 CI 服务器(在我的例子中是 Linux 上的本地主机)上启动浏览器。 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'
其他人遇到了类似的问题,解决方案看起来是为了确保您拥有稳定版本的 Capybara 和最新的 selenium webdriver
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
如果此解决方案有帮助,请告诉我!
事实证明,Jenkins 用户的帐户性质不允许它在 Jenkins 服务器内进行 运行 GUI 测试。
Firefox 是一个 GUI 应用程序,它需要连接到 X 服务器以发送其命令来绘制 windows 等。通常 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 实现完全自动化需要一些其他设置,例如禁用身份验证提示。准备好分步解决方案后,我将更新更详细的答案。