I am new to Capybara testing and am having a few issues.
I have a scenario I am trying to run, and this is the step implementation:
When /^I select the signin link$/ do
click_link 'Sign in'
end
I have tried to access this link with xpath, css, and tried the within implementation as well. Capybara cannot seem to find it, and returns a Capybara::ElementNotFound exception in all cases.
When I load the webpage without JavaScript, the link is not visible, and I’m wondering if this is why Capybara cannot find it. I found a trigger method, but am unsure how it works. Does anyone have a working example of trigger, or any other ideas for what I should do?
Are you using the selenium webdriver to run this test? It sounds like you are trying to run a scenario that requires javascript to see certain elements, without using a driver that supports javascript.
In your
.featurefile all you have to do is add this line before the scenario:The @javascript tag tells capybara to use selenium-webdriver to run the test. It’ll fire up firefox and go through the test – allowing all javascript functionality to work. This slows tests down considerably so only use it when absolutely necessary to test ajax-y and javascript-y behavior.
If that still doesn’t work you can use this step:
Which will open the page up for you in a new browser in that page’s current state for your inspecting pleasure.