-
Notifications
You must be signed in to change notification settings - Fork 4
Pages
A new page, generated with WatirCraft’s page generator, will have this skeleton:
module projectname class SomePage < ::Taza::Page end end
For each page, you can define its url, elements and fields. You can then
identify or manipulate them while testing.
Define the page url, relative to the environment URL (optional):
url 'pageurl'
Defining a url is optional, and won’t work for all pages. But if this is defined,
you can navigate to the page in your tests:
some_page.goto
To add elements you want to manipulate:
element(:next_button) {browser.button(:value, 'Next')}
In your test you can then access this element:
some_page.next_button.click
Elements are optional with WatirCraft. You can continue always use Watir commands
directly with the browser object. But elements can often make your tests
easier to read and maintain.
Fields are elements on a page with values. They are defined exactly like
elements.
field(:name) {browser.text_field(:name, 'user_name')}
However, they are used differently from elements in tests. Fields allow you
to directly access the value of the underlying element.
some_page.name.should == 'Bernie Madoff'
Nearly any element can be defined as a field. The value of a field is defined
to be the user-visible text associated with the element.
If the field is an input element, you can also directly set its value:
some_page.name = 'Tim Geithner'
The following types of input elements can be assigned in this fashion:
- text_field (both text boxes and text areas)
- hidden
- file_field
- select_list
- checkbox
The values for all fields are strings except for checkboxes, which are true or
false.
WatirCraft automatically defines an element for each field. You can access
this directly if you need to.
some_page.name_field.should be_enabled some_page.name_field.should exist
It is not possible to use :class
as the name of an element or field. This is a reserved word in Ruby.