# Using Page Object Model
# What is a Page Object?
Page Object Model is a design pattern that helps users write better tests and less code. It makes an object-oriented class that represents a page in your AUT (Application Under Test). Instead of rewriting the same code over and over again, you can describe your page once and share that description with many different tests. If your page changes, you can make the change is one place instead of many tests. Additionally, with Gondola's ILocator, you can use the same Page Object for the web, Android and iOS versions of an application.
# Creating a Page Object in GTD
- Navigate to the directory
- Right click on the
pagesdirectory and click
New Gondola Page
- GTD will open with the default template for Page Object
A Page Object Model contains only methods and locators
- Enter the locators and methods
- Click the save icon in the top right hand corner.
- Enter the name of your Page Object
- A new file named
YourPageObject'sName.tswill appear in the pages folder
# Working with Page Objects
Page Objects consist of two sections:
- Locators define the elements of your app you wish to interact with
- Methods allow you to interact with those elements
# Defining Locators
Locators are defined on the LOCATORS section in GTD.
[element locator] [name:<name of locator>] [locator:<value>]
Please go here or to the Gondola API article for more information on Element locator.
# Defining Methods
Methods are defined under the Methods section when viewing a Page Object in GTD. Here is a template:
Just like ABT tests, ABT Page Objects only support executable keywords that are understood by Gondola For a list of keywords, refer to the Gondola API As an advanced user, you may create more complex Page Objects in TypeScript, however those Page Objects might not display properly in GTD.
# Using the Page Object in Test Module
- Your Page Object will automatically be imported to your test when you use one of its methods.
- Predictive text selectbox will appear while typing. It's a useful tool for selecting correct method as it shows all information about highlighted method such as keyword and location.
- A new line which imports Page Object class aka method's location will appear if user opens the saved test file in TypeScript mode
import loginPage from "../pages/loginSamplePage";