title: How to call a page-object from a class.rb at Support folder
body: <p>I am using the page-object gem. Suppose i have a page-object on <code>features/bussines/pages/booking_page.rb</code> for a page like:</p>
  
  <pre><code>class Booking
  
     include PageObject
  
     span(:txtFirstName,   :id =&gt; 'details_first_name')
  
  end
  </code></pre>
  
  <p>...and i use a "tools" class located at <code>features/support/tools.rb</code> with something like:</p>
  
  <pre><code>class MyTools
  
    def call_to_page_object
      on Booking do |page|
         puts page.txtFirstName
      end
    end
  end
  </code></pre>
  
  <p>...but this approach fails because calling to the object from the class is not allowed:</p>
  
  <pre><code>undefined method `on' for #&lt;Booking:0x108f5b0c8&gt; (NoMethodError)
  </code></pre>
  
  <p>Pretty sure i'm missing some concept on the way to use the page-object from a class but don't realize whats the problem. Can you please give me an idea about what could be wrong here, please?</p>
  
  <p>Thank you very much!</p>
  
  <p>============================</p>
  
  <p>Justin found the reason why the call to the class crash. The final class code results:</p>
  
  <pre><code>class MyTools
  
    #Include this module so that the class has the 'on' method
    include PageObject::PageFactory
  
    def initialize(browser)
      #Assign a browser object to @browser, which the 'on' method assumes to exist
      @browser = browser
    end
  
    def getCurrentRewards
      on Booking do |page|
        rewards_text = page.rewards_amount
        rewards_amount = rewards_text.match(/(\d+.*\d*)/)[1].to_f
        puts "The current rewards amount are: #{rewards_amount}."
        return rewards_amount
      end
    end
  
  end
  </code></pre>
  
  <p>And the call to the function:</p>
  
  <pre><code>user_rewards = UserData.new(@browser).getCurrentRewards
  </code></pre>
  
  <p>Why it did not work me? Two main reasons:</p>
  
  <ul>
  <li>I didn't pass the browser object to the class &lt;== REQUIRED</li>
  <li>I didn't include the PageObject::PageFactory in the class &lt;== REQUIRED for the "on" method.</li>
  </ul>
  
  <p>Thanks all!</p>