0

I'm writing some tests in calabash, and trying to use the page function inside a helper class.

I have my steps file

Given /^I am on my page$/ do
   mypage = page(MyPage)
   MyPageHelper.DoMultiActionStep()
end

And my page file

class MyPage < Calabash::ABase
    def my_element_exists
       element_exists(MY_ELEMENT_QUERY)
    end
end

And my helper file

class MyPageHelper
   def self.DoMultiActionStep
      mypage = page(MyPage) 
      mypage.do_action_one
      mypage.my_element_exists
   end
end

When I run this though I get the error

undefined method 'page' for MyPageHelper:Class (NoMethodError)

The page function works fine in the steps file, but it just seems to have a problem being called from the MyPageHelper class. Is it possible to do this? Is there a using statement that I need to add in?

Thanks!

rozza
  • 927
  • 2
  • 11
  • 24
  • calabash-ios is in the tags, but you are using Calabash::ABase which is from calabash-android. Is this the problem? – jmoody Jul 01 '14 at 03:06
  • ah, very possibly. I have android and ios tests. What should I use in the ios tests instead of ABase? – rozza Jul 01 '14 at 15:01
  • I changed it to IBase and re-ran it, but still got the same problem. – rozza Jul 01 '14 at 15:21

1 Answers1

1

I am afraid that I don't know how to answer your question directly.

At the risk of being flamed, I recommend an alternative approach.

Option 1: If you don't need the helper class, don't bother with it.

I realize that your actual code is probably more complex, but do you need the helper here? Why not implement do_multi_action_step in the MyPage class as a method?

def do_multi_action_step
     my_element_exists
     my_other_method
end

Option 2: Pass an instance of MyPage

In your step you created an instance of MyPage. You should use that instance instead of creating a new one in MyPageHelper.do_multi_action_step.

def self.do_multi_action_step(my_page)
  my_page.my_element_exists
  my_page.my_other_method
end

Example:

# my_page_steps.rb
Given /^I am on my page$/ do
  # use the await method to wait for your page
  my_page = page(MyPage).await

  # pass an instance instead of creating a new one
  MyPageHelper.do_multi_action_step(my_page)

  # or just use a method on the MyPage instance
  my_page.do_multi_action_step
end

# my_page_helper.rb
class MyPageHelper
  # pass the page as an object
  def self.do_multi_action_step(my_page)
    my_page.my_element_exists
    my_page.my_other_method
  end
end

# my_page.rb
require 'calabash-cucumber/ibase'

class MyPage < Calabash::IBase

  # some view that is unique to this page
  def trait
    "view marked:'some mark'"
  end

  def my_element_exists
    element_exists("view marked:'foo'")
  end

  def my_other_method
    puts 'do something else'
  end

  # why not do this instead?
  def do_multi_action_step
    my_element_exists
    my_other_method
  end
end
jmoody
  • 2,480
  • 1
  • 16
  • 22