1

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.

Community
  • 1
  • 1
Daryn
  • 3,394
  • 5
  • 30
  • 41
  • I've also asked the same question some time ago [here](http://stackoverflow.com/questions/29286772/difference-between-using-page-find-and-find) ... I've given up using the page variable as my specs look a lot cleaner now. I still have no idea what the difference is in terms of what it is really used for. – Phil Jun 25 '15 at 21:32

1 Answers1

1

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)
iskvmk
  • 392
  • 4
  • 13