Capybara测试中的页面变量是什么?

时间:2015-06-24 15:03:14

标签: ruby cucumber capybara

使用Capybara时,调用page.find('#name')find('#name')之间有什么区别。

同样的事情,这个答案陈述What's the meaning of page and page.body in Capybara

我只是在寻找更多解释,何时需要在断言之外使用page

1 个答案:

答案 0 :(得分:1)

如源代码中所述:

# Shortcut to accessing the current session.
# @return [Capybara::Session] The current session object

def page
  Capybara.current_session
end

当您find('#name')当前会话的find方法被调用时。因此,调用page.find('#name')find('#name')之间没有区别。
我想这个快捷方式的创建只是为了让断言代码直观易懂:

expect(page).to have_css(#name)

看起来比

expect(Capybara.current_session).to have_css(#name)