2

I'm attempting to set up Cucumber testing on a Jquery Mobile app, but testing clicks is throwing an unexpected error. Here is the scenario:

problems.feature

Scenario: Clicking problem when not signed in
  When I go to the wall page for The Beast
  Then I should see "Blue"
  When I click the problem "Blue"
  Then I go to the sign up page

And the relevant step implemented to capture the second to last line is as follows:

steps.rb

When /^I click the problem "(.*)"$/ do |problem_name|
  find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
end

Everything passes fine up until that point. When it gets to clicking the problem, the following error is thrown:

When I click the problem "Blue"
  You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.each (ActionView::Template::Error)

I have also tried including a debugger immediately before the find().click call in steps.rb. When I then run the find command manually, it does indeed return the following:

(rdb:1) p find(:xpath, "//h3[text() = 'Blue']/parent::a")
  #<Capybara::Element tag="a" path="/html/body/div/div[2]/ul/li[2]/a">

And then running in debugger with the '.click' on the end produces the following:

(rdb:1) p find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
  ActionView::Template::Error Exception: You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.each
(rdb:1) p find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
  nil

So it appears that Capybara can find the right element, but then when attempting to click it somehow sets it to nil? I'd like to know how I can properly execute the click that I'm looking to execute using Capybara.

1
  • have try to use: "Then show me the page" step to debug the problem. Aug 31, 2011 at 5:32

1 Answer 1

2

I don't think there is a problem with Capybara. Right now I have the same problem and I think the problem is that you need to use a driver for test JavaScript actions such as selenium and run your tests using this driver.

I think your button is executing the action and refreshing the page without the all the objects it need. This will not happen if you use JavaScript

1
  • You were right with the idea - specifically you need to add '@javascript' to the line above each Scenario.
    – IanWhalen
    Sep 29, 2011 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.