Question

I am using Cheezy's PageObject to setup some cucumber tests. I have everything pretty much setup like Jeff Morgan's book "Cucumber & Cheese".

Right now I have a page object "PublishPage" setup that has a method that sets a variable @tag. For example I have in the file publish_page.rb

Class PublishPage
  def tag
  #some steps left out
  @tag = "123"
  end

  def verify_tag
  #some steps left out
  @tag.should include "2"
  end
end

In the Cucumber steps, for one of the steps i have on_page(PublishPage).tag, and then in another step i have on_page(PublishPage).verify_tag. In my env.rb file I have require 'rspec-expectations'.

The problem is that when I run this code I get an error that says undefined method 'include' for #<PublishPage:xxxxxx>. But if I move the code inside the verify_tag method into the steps everything works except it does not have access to @tag...

Was it helpful?

Solution

This should be as simple as adding

include RSpec::Matchers

to your page object.

The other alternative would be to expose @tag through some method and then in your Cucumber step say something like

on_page(PublishPage).the_displayed_tag.should include("2")

OTHER TIPS

Every time you invoke on_page(PublishPage), it will instantiate a new page object. You are most likely getting the "cannot convert nil to string" error because you are referencing an instance variable from a new object, hence it's value being nil. You should no longer get that error if you instantiate your page object only once, between calling page.tag and page.verify_tag.

Doing things this way will use one instance of your page object, allowing you to persist between step definitions.

When /I publish a tag/ do
   #on_page(PublishPage).tag
   @publish_page = PublishPage.new @browser
   @publish_page.tag
end

Then /I should have my tag/ do
   @publish_page.verify_tag 
end

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top