如何在Jenkins Server(Linux)上运行Cucumber无头测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Jenkins Server(Linux)上运行Cucumber无头测试相关的知识,希望对你有一定的参考价值。
如何在Jenkins Server(Linux)上运行Cucumber无头测试?
在Jenkins上使用'无头'宝石执行Cucumber / Watir-Webdriver测试的正确方法是什么?
第一次尝试:我的env.rb中有这个:
require 'rubygems'
require 'cucumber'
require 'rest_client'
require 'json'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'allure-cucumber'
require 'rspec'
require 'data_magic'
require 'fig_newton'
require 'yaml'
require 'headless'
require 'phantomjs'
ENVT = FigNewton.load('staging.yml')
DATA = DataMagic.load('data.yml')
KBA = YAML.load_file('config/data/kba.yml')
#Actions performed before each scenario
headless = Headless.new
headless.start
browser = Watir::Browser.start
Before do
@browser = browser
end
at_exit do
browser.close
headless.destroy
end
World(PageObject::PageFactory)
这是我得到的输出:
wrong number of arguments (0 for 1+) (ArgumentError)
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:28:in `start'
/var/lib/jenkins/jobs/idme_revelator/workspace/features/support/env.rb:24:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/rb_support/rb_language.rb:95:in `load'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/rb_support/rb_language.rb:95:in `load_code_file'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:180:in `load_file'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:82:in `each'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime.rb:184:in `load_step_definitions'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/runtime.rb:42:in `run!'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/lib/cucumber/cli/main.rb:47:in `execute!'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.3.18/bin/cucumber:13:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.1.0/bin/cucumber:23:in `load'
/var/lib/jenkins/.rbenv/versions/2.1.0/bin/cucumber:23:in `<main>'
Build step 'Execute shell' marked build as failure
Finished: FAILURE
第二次尝试:当我在此行的env文件中进行一次更改时:
browser = Watir::Browser.start
至
browser = Watir::Browser.new
然后我得到这个输出,但仍然是错误:
Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= (Selenium::WebDriver::Error::WebDriverError)
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
/var/lib/jenkins/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.45.0.dev3/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
第三次尝试:
如果我将我的env.rb文件更改为:
require 'rubygems'
require 'cucumber'
require 'rest_client'
require 'json'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'allure-cucumber'
require 'rspec'
require 'data_magic'
require 'fig_newton'
require 'yaml'
require 'headless'
require 'phantomjs'
ENVT = FigNewton.load('staging.yml')
DATA = DataMagic.load('data.yml')
KBA = YAML.load_file('config/data/kba.yml')
#Actions performed before each scenario
headless = Headless.new
headless.start
# browser = Watir::Browser.start
Before do
@browser = headless
end
at_exit do
#browser.close
headless.destroy
end
World(PageObject::PageFactory)
它看起来好多了但仍然失败:
WARN: Unresolved specs during Gem::Specification.reset:
mini_portile (~> 0.6.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Using the default profile...
@regression @hlp @hlp_admin
Feature: Test the HLP DocumentPage functionality
Background: # features/HLP_features/hlp_DocumentPage.feature:4
* I visit the Hosted Landing Page Admin tool # features/step_definitions/hlp/hlp_admin/hlp_admin_step_defs.rb:1
Unable to pick a platform for the provided browser. (RuntimeError)
./features/step_definitions/hlp/hlp_admin/hlp_admin_step_defs.rb:2:in `/^I visit the Hosted Landing Page Admin tool$/'
features/HLP_features/hlp_DocumentPage.feature:5:in `* I visit the Hosted Landing Page Admin tool'
* I login to the Hosted Landing Page Admin # features/step_definitions/hlp/hlp_admin/hlp_admin_step_defs.rb:5
* I visit the Add DocumentPage page # features/step_definitions/hlp/hlp_admin/hlp_admin_document_step_defs.rb:1
undefined method `window' for #<Headless:0x007f47cb1854b0> (NoMethodError)
/var/lib/jenkins/jobs/revelator/workspace/features/support/hooks.rb:23:in `After'
undefined method `driver' for #<Headless:0x007f47cb1854b0> (NoMethodError)
/var/lib/jenkins/jobs/revelator/workspace/features/support/hooks.rb:16:in `After'
Scenario: Add a new DocumentPage # features/HLP_features/hlp_DocumentPage.feature:9
* I create a new DocumentPage # features/step_definitions/hlp/hlp_admin/hlp_admin_document_step_defs.rb:5
* I should see DocumentPage edit page elements # features/step_definitions/hlp/hlp_admin/hlp_admin_document_step_defs.rb:10
* I delete the "DocumentPage" # features/step_definitions/hlp/hlp_admin/hlp_admin_edit_shared_step_defs.rb:1
那么在Jenkins上使用'无头'宝石执行Cucumber / Watir-Webdriver测试的正确方法是什么?
更新:如何使用Xvfb和Watir?
我的env.rb:
require 'rubygems'
require 'cucumber'
require 'json'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'allure-cucumber'
require 'rspec'
require 'data_magic'
require 'fig_newton'
require 'yaml'
require 'phantomjs'
require 'headless'
ENVT = FigNewton.load('staging.yml')
DATA = DataMagic.load('data.yml')
KBA = YAML.load_file('config/data/kba.yml')
headless = Headless.new
headless.start
browser = Watir::Browser.new
Before do
@browser = browser
end
at_exit do
@browser.close
end
World(PageObject::PageFactory)
我工作的最后一个地方我们没有使用无头宝石,我们刚刚在Jenkins脚本中启动了运行测试的XVFB,然后它发出了启动测试的黄瓜命令。并使用Firefox作为浏览器。 Thaat还允许我们在失败的测试中截取屏幕截图以帮助调试故障。
如果我还在那里工作,我会尝试使用phantomjs并查看它是否有效,然后使用哪个更可靠,和/或更快。
env.rb中没有什么不同,我们用于jenkins的本地运行的文件也是如此。
编辑:2017年末更新..随着近期的变化,目前推荐的无头浏览最佳解决方案是使用铬以及镀铬和镀铬的新无头选项。
第三个错误是因为Headless
不是浏览器,只是一个虚拟帧缓冲区。 @browser = headless
不会起作用,因为它应该是一个Watir::Browser
对象。虚拟帧缓冲区是您的浏览器(如Firefox或Chrome)绘制对象的位置。
根据您的require
s列表,您似乎正在尝试使用PhantomJS。 Watir::Browser.start
requires a URL to navigate to as an argument,默认情况下会尝试启动Firefox,如果你没有传入:phantomjs,除了url
作为参数。
@base_url = "https://my-test-domain.com"
@browser = Watir::Browser.start @base_url, :phantomjs
Watir::Browser.new
默认运行浏览器为:firefox
。如果你想使用PhantomJS,请传递:phantomjs
作为参数。
browser = Watir::Browser.new :phantomjs
如果你打算使用PhantomJS作为你的浏览器,you likely don't need Headless
宝石,并可以从你的env.rb
删除。
以上是关于如何在Jenkins Server(Linux)上运行Cucumber无头测试的主要内容,如果未能解决你的问题,请参考以下文章
如何在CentOS 7上使用Nginx安装Jenkins Automation Server
jenkins publish .net core application to linux server