开发者

Capybara not finding javascript

开发者 https://www.devze.com 2023-02-15 09:05 出处:网络
开发者_Go百科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:

开发者_Go百科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 .feature file all you have to do is add this line before the scenario:

@javascript
Scenario:  My Scenario
  When blah blah blah
  ...

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:

Then show me the page
When I select the signin link

Which will open the page up for you in a new browser in that page's current state for your inspecting pleasure.

0

精彩评论

暂无评论...
验证码 换一张
取 消