问题
Folks, I am using watir+cucumber in my tests and for each feature I am reusing the instance of the browser, that is I create the instance of @@browser = Watir::Browser.new
and then reuse this through out my tests, I am using watir-webdriver
, my tests where running fine till now, I just added another scenario and I consistently get the below error message:
Connection refused - connect(2) (Errno::ECONNREFUSED)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `open'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:542:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1035:in `request'
回答1:
Just create an instance variable named @browser
in your env.rb file, and then you can access it via @browser
in your cucumber steps.
回答2:
I run today in to the same issue, and I spent lot of time analysing it.
It happens only with Explorer and Chrome.
In the end, my conclusions are as follows:
- To close the browser after Cucumber tests, I used the at_exit global hook (as recommended in http://cukes.info ).
- I saw that the also Watir-webdriver (and probably Selenium) chain the same hook to close the chomedriver.exe process (or similar for IE).
- after some trial (maybe because I have no deep experience in Ruby) I found that the order you use to chain to at_exit is critical.
As Exit event is signalled to webdriver, its processes are closed, but your closing routine is excuted, that tries to do the same but it finds webdriver closed so it returns an exeception and it leaves the software interface still open. So, you have to put the code this way:
AfterConfiguration do |config|
yourCodeStartUp() # Put your SETUP code here including the launch of webdriver
at_exit
yourCodeTearDown() # Put your CLOSING routine here
puts 'stopped'
end
end
This way your routine at_exit code is executed before the one of Webdriver and it can orderly shutdown the system.
来源:https://stackoverflow.com/questions/9023273/watircucumber-connection-refused