【问题标题】:Watir webdriver; window.close is closing entire browser?Watir 网络驱动程序; window.close 正在关闭整个浏览器?
【发布时间】:2016-10-13 20:43:50
【问题描述】:

我正在运行一个测试,我将一个链接复制/粘贴到一个新标签中。完成后,我希望将其关闭,然后继续运行规范内的其他测试。目前的问题是,当我使用window.close 时,它正在关闭整个浏览器实例,而不仅仅是那个特定的窗口。
这是我的通用代码:

# Method for the window
def this_window
    page = @browser.window(:title, 'Foobar')
    return page
end

# Helper method for copy/paste in new tab
def copy_paste_in_new_tab
    @browser.send_keys [:command, 't']
    @browser.send_keys [:command, 'v']
    @browser.send_keys [:return]
end

# How it appears in the spec
it 'goes to new page' do
    copy_paste_in_new_tab
    sleep 1
    this_window.use
end
it 'interacts with new window' do
    # runs some tests on new window correctly
end
it 'closes the window' do
    this_window.close
    sleep 2
end
it 'continues to other tests' do
    # by this point the entire session has closed
end

这是我在终端中遇到的错误:

An error occurred in an `after(:context)` hook.
Errno::ECONNREFUSED: Connection refused - connect(2) for "127.0.0.1" port 7055
occurred at /Users/foo/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

我仅在尝试在关闭最后一个窗口之后执行代码 时遇到问题。如果我使用this_window.close 作为我的最后一个代码,那么它可以正常工作
关于导致这种情况的任何想法?

【问题讨论】:

    标签: rspec tabs watir-webdriver


    【解决方案1】:

    Mozilla 不支持也不会支持与 Firefox 中的选项卡进行交互。 https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/3380

    【讨论】:

    • 考虑到这一点,在新的窗口中自动打开来运行测试是否更适用?
    • 是的,使用窗口而不是选项卡,它应该可以工作。 :)
    猜你喜欢
    • 2012-10-30
    • 2018-06-04
    • 2021-11-27
    • 2017-04-16
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    相关资源
    最近更新 更多