chrome browser closes automatically after the program finishes in ruby using watir

故事扮演 提交于 2019-12-12 03:34:12

问题


I am using chrome 56, chrome driver 2.27(latest release) with selenium web driver 3.1.0. Referring to the issue(https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1811) where chrome closes all the instances once the program finishes and it does not give me a chance to debug. I just want to know if this is fixed then why it is still happening ? or i am missing something ? I am using the following code. Any help is appreciated.

require "uri"
require "net/http"
require 'watir-webdriver'
require 'selenium-webdriver'

@b = Watir::Browser.new :chrome
@b.goto 'http://www.google.com'

回答1:


Firstly, watir-webdriver gem is deprecated. The updated code is in the watir gem. Also, you shouldn't need to require any of those other gems directly.

The chromedriver service is stopped when the ruby process exits. If you do not want the browsers that were started by chromedriver to close as well, you need to use the detach parameter. Currently this is done like so:

require 'watir'

caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps[:chrome_options] = {detach: true}
@b = Watir::Browser.new :chrome, desired_capabilities: caps



回答2:


Declare these

caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" =>  {'detach' => true})
browser = Watir::Browser.new :chrome, desired_capabilities: caps 

On a side note! this might give a problem when you are running multiple scenario tests, chromedriver will actively refuse connection in case an other test initiates in the same chrome session. Ensure you have browser.close whenever required.



来源:https://stackoverflow.com/questions/42354533/chrome-browser-closes-automatically-after-the-program-finishes-in-ruby-using-wat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!