Search code examples
rubywatirpageobjectspage-factory

Cannot set using Page Object Model in ruby


The user is already on LoginPage and wants to enter username using Page Object technique.

I have described the element in LoginPage class and using same element in step definition page.

I want to do some action on element using Page Object Model but when running using the feature files it throws error that "undefined methodset' for "":String . "`

class LoginPage

  text_field(:userfield, :name => 'email')
  text_field(:passfield, :name => 'password')
  button(:submit, :type => 'submit')
end

Step definition uses :

And(/^a user logs in$/) do

on LoginPage do |page|
    page.userfield.set "username"
end

Solution

  • For the Page-Object gem, the text field accessor adds a method #userfield that returns the current value of the text field. It doesn't return an actual element. For that, you would need to call #userfield_element.

    To set the field, you need the #userfield= method:

    page.userfield = "username"