【问题标题】:How to restart browser in Cucumber + Selenium Webdriver + Page-Object?如何在 Cucumber + Selenium Webdriver + Page-Object 中重启浏览器?
【发布时间】:2015-04-03 14:19:35
【问题描述】:

我使用的是 Chrome 和 IE 浏览器。我需要重新启动当前浏览器并继续执行。 当我重新启动浏览器时,当前浏览器关闭并使用给定的 url 启动新浏览器但抛出此错误:

没有这样的会话(驱动程序信息:chromedriver=2.10.267521,platform=Windows NT 6.2 x86_64)

脚本是:

$log.info("Due to exception '#{ex}' the current browser is being restarted")  
@browser = EHR::BrowserSettings.restart_browser
sleep 10
@browser.navigate.to(DESKTOP_APP_URL)
sleep 3

在此之后,将执行登录脚本。如何解决错误?

【问题讨论】:

  • 第一件事是 selenium 总是在浏览器关闭后从新会话开始。所以我认为如果您重新启动浏览器,您将不得不再次登录。
  • 实际上我能够使用 url 启动新浏览器,但它没有采用当前的 @browser 对象值,这就是它抛出“没有这样的错误”的原因。
  • 我告诉过你..一旦浏览器关闭然后会话结束..
  • 我明白了。启动新浏览器的脚本应该放在 hooks.rb 文件中。不是它的工作正常。

标签: selenium-webdriver cucumber


【解决方案1】:

不确定您是否正在使用 watir-webdriver,但您可以尝试:

@browser.close
@browser = Watir::Browser.new

【讨论】:

    【解决方案2】:
    No actually the script is After block : 
    if scenario.failed?
      $log.info("Due to exception the current browser is being restarted")
      @browser = nil
      @browser = EHR::BrowserSettings.restart_browser
      @browser.navigate.to(DESKTOP_APP_URL)
    .....
    this script is working (its relaunching the browser with the given URL).
    Im trying to close the browser window in at_exit() hook and here im not able to get the @browser object value and hence could not close the browser.
    I jst need to close it in the at_exit block. Is there any way to do it.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      相关资源
      最近更新 更多