Manage Web Test Object
Estimated reading time: 4 minutes
Create a Test Object
Select File > New > Test Object from the main menu. The New Test Object dialog is displayed.
Provide a name for the new test object, then click OK button. The new test object is created under the Object Repository of Katalon Studio.
Add an object property
There cannot be two properties with similar names in the same test object.
- In the Test Object Editor, click Add.
- The Add property dialog is displayed.
- Name: The name of the object property. The drop-down list provides some standard options for your selection (XPath, CSS, class, id, title), or you can enter manually.
- Match condition: to search for the "actual" object in the AUT when executing automation tests.
- Value: to complete a match condition.
- The new property is added to the properties list as specified. You can also edit the properties' values here.
Manage parent object
Nowadays, there are 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, so you only need to select the parent iframe, and the execution automatically switches to that iframe.
Properties used for detecting an object
Read more about Selection Method.
Katalon Studio allows you to choose different ways to locate objects.
- Katalon Studio supports Relative XPath for better object recognition. If an element cannot be consistently located using its direct attributes, Katalon Studio identifies the element by using its more robust neighbors.
Katalon Studio automatically generates its XPath combined with object properties to locate the object. This XPath is displayed in Selector Editor.
A test object is typically built up by several properties. During test execution, Katalon Studio uses them to detect an object. Using the Detect object by field, you can determine which properties to be utilized for recognizing objects.
In the following example, Katalon Studio tries to find any object on AUT with both text and XPath to satisfy the defined criteria during execution.
- With CSS, you are allowed to input CSS locator for objects in Selector Editor manually.
Validate Test Object on AUT
You can add test objects to the Web Object Spy dialog to verify the detection in the application under test. Refer to Spy Web Utility (version 4.8 and below) for details regarding how to validate captured objects against the application under test.
To add an object to Web Object Spy, right-click on the item to open its context menu and select the option.
Test Objects in Scripting View
The test case Script View allows you to define Test Objects as needed programmatically. The following is a simple sample demonstrating how to define the Medicare option with the Attributes, XPath and CSS selection methods.
Step 1: Create a new object programmatically using TestObject class:
```groovy // Create a new object programmatically TestObject myNewObject = new TestObject('ObjectID') ```
With the Attributes selection method, add the property to an object using addProperty() method:
//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 myNewObject.setSelectorMethod(SelectorMethod.BASIC) myNewObject.addProperty('xpath', "//*[@id=\"appointment\"]/div/div/form/div/div/label", true) //Medicare
With XPath and CSS: Specify a selection method and set a value to the locator:
//XPATH myNewObject.setSelectorValue(SelectorMethod.XPATH,"//*[@id=\"appointment\"]/div/div/form/div/div/label") //Medicare myNewObject.setSelectorMethod(SelectorMethod.XPATH)
//CSS myNewObject.setSelectorValue(SelectorMethod.CSS,"#appointment > div > div > form > div:nth-child(3) > div > label:nth-child(1)") //Medicare myNewObject.setSelectorMethod(SelectorMethod.CSS)
The following API docs may prove useful when working with test objects:
|Test Object||addProperty(String name, ConditionType condition, String value)||Add a new property to the test object.|
||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.|