rspec 对新 window 的断言

rspec assertions on new window

我正在使用 watir-webdriver 和 rspec 来编写断言。我正在 运行 解决一些问题 运行 对新 window 的元素进行断言。
这是我正在使用的方法:

def open_window
    foobar = @browser.window(:title, 'Foo View')
    return foobar
end

这就是我编写规范的方式:

describe 'testing a new window' do
    it 'opens a new window' do
        open_window.use
        sleep 2 # hackey way of getting it to work so far
    end
    it 'sees elements on page' do
        # code for expectations of elements
        # Several more it blocks
    end
end

发生了什么: 除非我在不确定的时间内输入 sleep 命令,否则 window 似乎会在 运行 通过所有断言之前关闭。是否有某种 wait 可用于在整个规范中保持新的 window 开放?

还不能评论。

当 window 可用时,假设您没有在页面上执行操作,只需在它关闭之前将所有内容推送到一个实例变量中,然后 运行 您的断言就可以了?

不理想,但可能有效。

进行了一些重构,现在可以正常工作了——本质上,这是一个设置问题,可以按照 #when_present.use