0


I am using Capybara and Selenium for testing my website. I also use with Site Prism for Page Object model. I can make every thing work now, however, I don't understand why sometimes actions with page elements donot work, while using "natively" Capybara work.
For example, I have a Page object:

class MyPage < SitePrism::Page
 element :sign_in_link, :css, 'a.signin-link'
 element :join_link, :css, "a.join-link"
end

and its implementation:

@mypage = MyPage.new
@mypage.sign_in_link.click
# It works at first, then after some repeated test round, it doesn't work sometimes, with error: NoMethodError <br>

While I use:

find(:css, 'a.signin-link').click #=> always work, but not Page Object model

So, why it happens? Have anyone experienced this problem?

Huy Do
  • 470
  • 1
  • 7
  • 19

1 Answers1

1

By default site_prism disables Capybaras implicit waiting behavior while finding elements. This means to have the same behavior as your capybara example you would need to do

@mypage = MyPage.new
@mypage.wait_for_sign_in_link
@mypage.sign_in_link.click

You can read more about this in the site_prism README under "Using Capybara Implicit Waits"

Another options is to use site prisms "Load Validations" feature to ensure pages are loaded before starting to click on their elements

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thank you @Tom, I will try this. – Huy Do Dec 14 '15 at 08:07
  • Load validations can be used with Rspec easily, but how can I apply it with cucumber? I have steps for each test scenario. – Huy Do Dec 14 '15 at 14:22
  • You can either wrap your steps with when_loaded for the page/sections the steps depend on, or you could have a step that calls when_loaded with an empty block - which will make that step wait until the load validations pass, or if you write your load validation with methods that wait for the elements to be on the page you could just have a step that calls loaded? on the page/sections – Thomas Walpole Dec 14 '15 at 16:59