2

I would like to use the page-objects gem in my selenium test projects, but before I can do that I need to get a small proof of concept project working so I can play around with it.

I have been following the Get Started Now! guide on github, but for the life of me I can not figure out what I am doing wrong. Admittedly, I am a ruby newbie and there is probably a very big "duh" moment coming up.

Here is my practice page.rb:

require 'page-object'
class SearchPage 
 include PageObject
 text_field(:searchBar, :id => 'q') 
 button(:submitSearch, :name => 'btnK')
 def search(query)
 self.searchBar = query
 submitSearch
 end
 def open()
 @browser.get 'https://www.google.com'
 end
 def close()
 @browser.close()
 end
end

And here is my practice test.rb:

require_relative 'page'
require 'selenium-webdriver'
require 'test/unit'
class SearchPageTest < Test::Unit::TestCase
 def test_search_page
 @browser = Selenium::WebDriver.for :chrome
 search_page = SearchPage.new(@browser)
 search_page.open()
 search_page.search('page-objects')
 sleep 5
 search_page.close()
 end
end

This fails at line 10 in the test (search_page.search...) with the error

NoMethodError: undefined method `text_field' for #Selenium::WebDriver::Chrome::Driver:0x007fd37c1c1838

Here is the full stack trace:

Nates-MacBook-Air:Practice natesmith$ ruby test.rb 
Loaded suite test
Started
E
================================================================================
Error: test_search_page(SearchPageTest): NoMethodError: undefined method `text_field' for #<Selenium::WebDriver::Chrome::Driver:0x007fe64d2c60d8>
/Users/natesmith/.rvm/gems/ruby-2.4.1/gems/page-object-2.2/lib/page-object/platforms/watir/page_object.rb:1067:in `instance_eval'
/Users/natesmith/.rvm/gems/ruby-2.4.1/gems/page-object-2.2/lib/page-object/platforms/watir/page_object.rb:1067:in `instance_eval'
/Users/natesmith/.rvm/gems/ruby-2.4.1/gems/page-object-2.2/lib/page-object/platforms/watir/page_object.rb:1067:in `process_watir_call'
/Users/natesmith/.rvm/gems/ruby-2.4.1/gems/page-object-2.2/lib/page-object/platforms/watir/page_object.rb:216:in `text_field_value_set'
/Users/natesmith/.rvm/gems/ruby-2.4.1/gems/page-object-2.2/lib/page-object/accessors.rb:203:in `block in text_field'
/Users/natesmith/Desktop/Ruby/Practice/page.rb:10:in `search'
test.rb:10:in `test_search_page'
 7: @browser = Selenium::WebDriver.for :chrome
 8: search_page = SearchPage.new(@browser)
 9: search_page.open()
 => 10: search_page.search('page-objects')
 11: sleep 5
 12: search_page.close()
 13: end
================================================================================
Finished in 2.875252 seconds.
--------------------------------------------------------------------------------
1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
--------------------------------------------------------------------------------
0.35 tests/s, 0.00 assertions/s

Help, what am I doing wrong?

asked Aug 14, 2017 at 21:09
4
  • Does the browser correctly open and navigate to google.com prior to the failure? Commented Aug 16, 2017 at 19:09
  • Yes the browser opens, and it appears to be navigating to the google homepage but quits before anything is visible Commented Aug 17, 2017 at 16:00
  • Could you include the stack trace? There are a number of possibilities, but I think if you give the stack trace I could probably figure out why it is erroring. Commented Aug 17, 2017 at 20:01
  • @SamWoods I have included them now in the question. Commented Aug 17, 2017 at 21:40

1 Answer 1

1

It looks like page-object is using the Watir implementation instead of the Webdriver implementation, and since Webdriver does not have a text_field property (while Watir does) it is failing. I am not sure why it is trying to use Watir since your implementation matches the documentation for the page-object gem. It looks like someone is having a similar issue with the latest version: https://github.com/cheezy/page-object/issues/439. You might try using an older version of the page-object gem until that gets resolved.

answered Aug 18, 2017 at 16:45
1
  • Thanks for your help. I followed the link to the issue and they have now resolved this issue. After updating the gem it is working as I would expect now Commented Aug 24, 2017 at 22:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.