Cucumber headless xvfb ubuntu

2019-04-11 15:13发布

问题:

I'm trying to setup a Jenkins build server on Amazon EC2. I'm planning on running my cucumber test suite in headless mode. I was successfully able to run headless in IRB

require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start
b = Watir::Browser.new(:chrome)
b.goto("www.google.com")
b.title
b.close
headless.destroy

but if I add the following to my env.rb

if ENV['HEADLESS']
  require 'headless'
  headless = Headless.new
  headless.start
  at_exit do
    headless.destroy
  end
end

and run

cucumber ENV=HEADLESS features/test.feature:25

I get the following error.

 end of file reached (EOFError)
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/protocol.rb:141:in `read_nonblock'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1293:in `request'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:745:in `start'
 /var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1284:in `request'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in `response_for'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:in `request'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:92:in `create_session'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/chrome/bridge.rb:29:in `initialize'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/driver.rb:37:in `new'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/driver.rb:37:in `for'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver.rb:65:in `for'
 /var/lib/jenkins/.rvm/gems/ruby-1.9.3-p286@cucumber/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:35:in `initialize'
 /var/lib/jenkins/automation/features/support/hooks.rb:9:in `new'
 /var/lib/jenkins/automation/features/support/hooks.rb:9:in `Before'
    Given I am on the login page
    And login as a blogger
    Then I must see the text "Blog List"
      undefined method `driver' for nil:NilClass (NoMethodError)
      /var/lib/jenkins/automation/features/support/hooks.rb:27:in `After'
      undefined method `close' for nil:NilClass (NoMethodError)
      /var/lib/jenkins/automation/features/support/hooks.rb:17:in `After'

Any help will be appreciated. Thanks!!

回答1:

The problem was in the command line env parameter

cucumber HEADLESS=true features/test.feature:25 

instead of

cucumber ENV=HEADLESS features/test.feature:25