Reputation: 3768
When using Capybara, what is the difference between calling page.find('#name')
and find('#name')
.
Is it that same thing, as this answer states What's the meaning of page and page.body in Capybara
I am just looking for more of an explanation and when I would need to use page
outside of asserts.
Upvotes: 1
Views: 647
Reputation: 392
As it is described in source code:
# Shortcut to accessing the current session.
# @return [Capybara::Session] The current session object
def page
Capybara.current_session
end
When you do find('#name')
current session's find
method is called. So there is no difference between calling page.find('#name')
and find('#name')
.
I guess this shortcut was created just to keep asserts code intuitive and understandable:
expect(page).to have_css(#name)
looks better than
expect(Capybara.current_session).to have_css(#name)
Upvotes: 1