简体   繁体   中英

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

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' 

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM