Question

I am trying to get my first page object to work. I am new to ruby and cucumber so i am not sure what i am doing wrong. Its a very simple program so far. My goal is to go to google and search for 'bacon'

I have my page_object's folder inside my support folder (i think that's where it should go not sure)

I feel like include PageObject is not doing the include correctly.

HomePage.rb

class HomePage
  include PageObject


   text_field(:search_box, :id=> 'gbqfq')
   button(:search_button, :id=> 'btnG')

end

stepdeffs.rb

Given /^on google$/ do
 @BROWSER.goto 'www.google.com'
end


When /^i search for bacon$/ do
 @home_page.search_for('Bacon')
end



Then /^BACON!!!!!!$/ do
 @BROWSER.text.include? 'Bacon'
end

env.rb

require 'watir-webdriver'
require 'rubygems'
require 'page-object/page_factory'

World(PageObject::PageFactory)

Before do
  @BROWSER = Watir::Browser.new
  @home_page = HomePage.new(@BROWSER)
end

GemFile

source 'https://rubygems.org'

group :test do
  gem 'cucumber'
  gem 'watir'
  gem 'page-object'
end

Error i am getting:

undefined method `text_field' for HomePage:Class (NoMethodError)
C:/ihateautomation/watir/features/support/page_objects/homepage.rb:6:in `<class:HomePage>'
C:/ihateautomation/watir/features/support/page_objects/homepage.rb:2:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_language.rb:122:in `load'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-
Was it helpful?

Solution

Try it in the following order

require 'watir-webdriver' require "page-object" require "page-object/page_factory"

works for me...

OTHER TIPS

Sorry figured it out.

require 'page-object/page_factory' was breaking it for some reason

require 'page-object' works just fine.

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