Manage Web test objects
In Katalon Studio, a test object is designed to follow the Page Object Model (POM) pattern to represent the structure of an application under test (AUT). A test object has identification properties and selection methods.
- How to create Web objects manually
- How to create Web objects in Script view
- How to validate Web objects
Create Web objects manually
You can manually create a Web test object in two ways:
- From the main menu, select File > New > Test Object
- Or, right-click on Object Repository and select New > Test Object
In the displayed New Test Object dialog, provide a name for the new test object, then click OK. Test objects created manually are stored under Object Repository.
Create object locator
Katalon Studio supports the following selection methods: XPath, Attributes, CSS, Image, and Smart Locator. See: Selection methods for Web objects.
When you create a test object manually, the Attributes (or properties) selection method is selected by default.
This section shows you how to add object properties and generate object locator with the Attributes selection method.
Manage parent object
Many web applications rendering elements in an iframe. Therefore, you have to tell your script how to traverse a website's iframes and select the correct iframe where the text and its object are present. To do so, you have to use the Switch To Frame keyword before interacting with the elements.
Katalon Studio supports an ability to define parent iframe object within the test object view. You only need to select the Parent iframe option, and the execution automatically switches to that iframe.
Create Web objects in script view
The following classes and methods might be useful when working with test objects:
Class | Method | Description |
---|---|---|
Test Object | addProperty(String name, ConditionType condition, String value) | Add a new property to the test object |
setProperties(List<TestObjectProperty> properties) | Set the properties of the test object | |
getObjectId() | Get an object ID | |
findPropertyValue(String name, boolean caseSensitive) | Find the value of a property using the property name | |
setSelectorMethod(SelectorMethod selectorMethod) | Set the selection method for the test object |
This example demonstrates how to define the Medicare option in the AUT using TestObject
, setSelectorMethod
, and addProperty()
classes.
Open a test case and switch to the Script View.
Depending on the selection method you want to use, copy and paste the script below accordingly:
Attributes:
import com.kms.katalon.core.testobject.SelectorMethod
// Create a new object programmatically
TestObject medicareOption = new TestObject('Medicare')
//Attributes
//Add property to Test Object, a property is defined by:
// property name,
// condition type,
// property value,
// a boolean value to indicate if the property will be used to identify the object during execution
medicareOption.setSelectorMethod(SelectorMethod.BASIC)
medicareOption.addProperty('xpath', "//*[@id=\"appointment\"]/div/div/form/div[3]/div/label[1]", true) //MedicareXPath:
import com.kms.katalon.core.testobject.SelectorMethod
// Create a new object programmatically
TestObject medicareOption = new TestObject('Medicare')
//XPATH selection method
myNewObject.setSelectorValue(SelectorMethod.XPATH,"//*[@id=\"appointment\"]/div/div/form/div[3]/div/label[1]") //Medicare
myNewObject.setSelectorMethod(SelectorMethod.XPATH)CSS:
import com.kms.katalon.core.testobject.SelectorMethod
// Create a new object programmatically
TestObject medicareOption = new TestObject('Medicare')
//CSS selection method
myNewObject.setSelectorValue(SelectorMethod.CSS,"#appointment > div > div > form > div:nth-child(3) > div > label:nth-child(1)") //Medicare
myNewObject.setSelectorMethod(SelectorMethod.CSS)