硒鼓ruby脚本完成后,如何打开浏览器
我正在使用带有selenium web-driver的ruby脚本,用于自动执行网页登录.问题是脚本完成后关闭浏览器.我想保持浏览器打开,即使脚本完成后.有什么办法,我可以保持浏览器打开后,测试做其他的浏览器窗口?
我这样做 if browser == "Firefox" driver = Selenium::WebDriver.for :firefox end if stack == "example.com" driver.get "http://www.example.com/tests/ end element = driver.find_element :name => "email" element.clear element.send_keys username element = driver.find_element :name => "password" element.clear element.send_keys password element = driver.find_element :name => "commit" element.submit ================================================== = 解决方法
我从来没有在这样的独立脚本中尝试过使用selenium-webdriver,但是在capybara / cucumber的上下文中,我遇到了同样的问题,使用selenium-webdriver.
看看capybara的源代码,我发现这个钩子在您的脚本完成后显式关闭浏览器.如果您没有使用selenium-webdriver与capybara,那么这可能没有帮助,但它对我有帮助… gems / capybara-1.1.1 / lib / capybara / selenium / driver.rb注册一个at_exit钩子,然后在浏览器对象上调用quit. require 'selenium-webdriver' class Capybara::Selenium::Driver < Capybara::Driver::Base ... def browser unless @browser @browser = Selenium::WebDriver.for(options[:browser],options.reject { |key,val| SPECIAL_OPTIONS.include?(key) }) main = Process.pid at_exit do # Store the exit status of the test run since it goes away after calling the at_exit proc... @exit_status = $!.status if $!.is_a?(SystemExit) quit if Process.pid == main exit @exit_status if @exit_status # Force exit with stored status end end @browser end 你应该能够对quit方法进行猴子补丁,使其不起作用,如下所示: Selenium::WebDriver::Driver.class_eval do def quit #STDOUT.puts "#{self.class}#quit: no-op" end end 注意:如果您使用Selenium :: WebDriver.for:chrome和chromedriver 所以我也不得不阻止这个服务进程停止,像这样: Selenium::WebDriver::Chrome::Service.class_eval do def stop #STDOUT.puts "#{self.class}#stop: no-op" end end 还有一个其他的问题我遇到,这可能不会影响你,除非你使用这个驱动程序与黄瓜…即使我得到它让浏览器打开,它将在“关于:空白页.看起来这是由这个钩子触发的: 宝石/水豚-1.1.1 / lib目录/豚/ cucumber.rb: After do Capybara.reset_sessions! end 哪些调用gems / capybara-1.1.1 / lib / capybara / session.rb:70:在`reset!’“ 哪个调用gems / capybara-1.1.1 / lib / capybara / selenium / driver.rb:80:在`reset!’“ def reset! ... @browser.navigate.to('about:blank') ... end 我用另一个猴子补丁解决了这个问题: Capybara::Selenium::Driver.class_eval do def reset! end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 火云开发课堂 - 《使用Cocos2d-x 开发3D游戏》系
- React Native Error:无法解析node_modules / re
- react-native – React Native获取SectionList中
- 如何快速删除Cisco Flash中包含文件的目录?
- vue+echarts实现可拖动节点的折线图(支持拖动方
- ruby – Windows上的Heroku给出错误:内容无效的
- 内存管理 – 多进程内核驱动程序中的内存池
- ruby-on-rails – 迁移DATA – 不仅仅是模式,Rai
- ehcache.xml配置文件详解
- c# – Web应用程序中IronPython内存泄漏的问题