0

I'm working in a cucumber-ruby framework and we're using Capybara and SitePrism to drive the browser.

I've got a situation where I want to retry a bunch of steps if an error happens, so I was putting a method with logic to cover this within a SitePrism page as follows:

steps %Q{
When I click on the back button
And I enter my reference number
Then I am able to complete the action successfully
}

The problem I'm finding is that when this part of code is reached, the execution fails with:

    undefined method `steps' for #<MySitePrismPage:0x000000063be5b0 @loaded=false> (NoMethodError)

Any idea if there's a way for me to use steps within SitePrism pages?

Thanks!

mickael
  • 2,033
  • 7
  • 25
  • 38
  • I thought it was a problem with SitePrism pages, but I've just tried with a standard class or even a module and I keep on getting the same issue about 'undefined method steps'. If anyone has a suggestion that I could try pls? – mickael Apr 13 '17 at 12:20

2 Answers2

0

Credit to 'Jonas Maturana Larsen' in a google group. Similar problem with a different example, but passing 'world' to the class fixed the problem for me as well.

step is defined in Cucumbers RbWorld module.

You need to pass in the world instance from where ever you're creating the TestRubyCallStep class.

In your case you might actually want to make a module instead of a class if you just need a place to keep shared methods.

class TestRubyCallStep   
    include Calabash::Android::Operations   

    def initialize(world)
        @world = world   
    end   

    def callMethod
        @world.step %Q{my customized steps in custom_step.rb}   
    end 
end      

The context in which the step definition is executed is the world :)

Try this:

Then /^I call a step from Ruby class "([^\"]*)"$/ do |world|   
    testObj = TestRubyCallStep.new(self)   
    testObj.callMethod 
end
mickael
  • 2,033
  • 7
  • 25
  • 38
0

Old question but providing answer

Using steps as a method call is considered an anti-pattern and is being deprecated / removed going forwards in cucumber.

It is highly advisable to instead extract out the common behaviour into Helper Modules / Classes, and then call the methods on those.

Furthermore as you've found out. Running inside the Cucumber World, extends all of the cucumber methods into a top level DSL, so simply calling steps will work. Whereas that DSL is never mixed into any SitePrism context, so you cannot do it.

TL;DR - Don't do what you're trying to do. Do something like this.

module MyReusableHelper
  def click_back
    # verbose code here
  end

  def enter_reference_number
    # verbose code here
  end

  def complete_action # Note this method name probably needs a rethink
    # verbose code here
  end

Then simply include this module into whichever class/es need it.

If you have any more queries, ask here or if you're convinced something is broke post on the Official GH page.

Luke Hill
  • 460
  • 2
  • 10