Skip to content

Get me started right now!

cheezy edited this page Jul 24, 2011 · 12 revisions

So you want to use the page-object gem. Here is what you need to do.

Create your page

The first thing you must do is create your pages. These are simple ruby classes that include the PageObject Module.

class RegistrationPage
  include PageObject
end

By including the PageObject Module you have added a lot of power to your page. Let's take a look at how we might use some of that right now.

Describe your page

After you create your class you need to describe the web page this class represents. The RegistrationPage example might look like this:

class RegistrationPage
  include PageObject

  text_field(:name, :id => 'name')
  text_field(:email, :id => 'email')
  button(:register, :value => 'Register')
end

By calling these methods, the PageObject module will add several additional methods for you. To learn about what methods are available and the generated methods please see this page.

Use your page

Now that we have a basic page object defined it is time to put it to use. You can use either watir-webdriver or selenium-webdriver as the driven gem. Just pass them into the constructor.

browser = Watir::Browser.new :firefox
registration_page = RegistrationPage.new(browser)

or

browser = Selenium::Webdriver.for :firefox
registration_page = RegistrationPage.new(browser)

Once created, you can interact with the page using the generated methods.

registration_page.name = 'Test User'
registration_page.email = 'test@example.com'
registration_page.register

That is all there is to getting started with this gem. The good news is that there is a lot of additional functionality that was not covered in this brief introduction. Please go back to the page-object top level page to learn more.