Speedychuck
Speedychuck

Reputation: 400

Ruby Watir - How do I call Page Objects in Test scripts?

I am wondering how I call page objects from the page object class into my test class from a different directory? New to ruby! In java I would just import the class at the top of the class file and that would allow me to access the methods and objects from that class file in a different folder/package. My Directory structure is like so below:

enter image description here

I want to be able to access the page objects in the page object class to use in my A_Test class. How do I achieve this?

page_object.rb code:

require 'rubygems'
require 'cucumber'
require 'watir'
require 'page-object'
require 'test/unit/assertions'
include Test::Unit::Assertions

class screen
    include PageObject
    radio_button(:yes, id: '')
    radio_button(:no, id: '')
    button(:next_button, id: '')
    link(:back, :text => "")
end 

A_test.rb code:

require 'rubygems'
require 'cucumber'
require 'page-object'
require 'watir'
require 'date'

Given(/^$/) do |no|

   screen.next_button.click

end 

Upvotes: 0

Views: 141

Answers (1)

Justin Ko
Justin Ko

Reputation: 46846

You need to:

  • Create a page object instance
  • Note that you also need the class to be a constant - so it needs to be class Screen (ie capitalized)

For example:

Given(/^$/) do |no|
  page = Screen.new(browser)
  page.next_button
end 

Upvotes: 1

Related Questions