Manage Web Test Objects in Katalon Studio
In Manual View
Create a test object
You can create a 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. The new test object is created under the Object Repository of Katalon Studio.
Moreover, you can capture objects using Spy Web Utility in Katalon Studio or Record web utility in Katalon Studio.
Create an object's locator
You can add multiple locators to an object but you must select one of them as a default locator. The default locator is used for detecting the object during test execution. From version 7.6.0, you can use Self-healing mechanism to utilize multiple locators of an object.
Katalon Studio supports the following selection methods: XPath, Attributes, CSS and Image. You can freely switch from one selection method to another. The detailed content of each selection method is saved automatically.
- XPath/CSS: Enter a desired XPath locator in Selected Locator.
- Image: Browse an image to compose an image locator for the object. Learn more
Attributes: Check on one or multiple Detect object by in the Object's Properties table to compose a Selected Locator of this method for the object.
You can add multiple object properties to the Object's Properties table. The object properties cannot share the same name in an object.
- In a Test Object's view, select Attributes as the default Selection Method.
- In the Object's Properties table, click Add.
- In the displayed Add property dialog, specify the required information:
- Name: The object property's name. You can select one of the provided options (class, css, id, name, title, xpath) or enter a name manually.
- Match condition: The condition is used for detecting the target object during execution.
Value: The value to complete a match condition.
The new property is added to the properties list as configured above. You can also change 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.
In script view
Script View allows defining Test Objects programmatically.
The following example shows you how to define the Medicare option with the Attributes, XPath and CSS selection methods.
Create a new object programmatically using the
// Create a new object programmatically
TestObject myNewObject = new TestObject('ObjectID')
- Add an object locator
With the Attributes selection method, add a property to an object using the
//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.addProperty('xpath', "//*[@id=\"appointment\"]/div/div/form/div/div/label", true) //Medicare
With XPath or CSS selection method: Specify a selection method and set a value to the locator:
myNewObject.setSelectorValue(SelectorMethod.CSS,"#appointment > div > div > form > div:nth-child(3) > div > label:nth-child(1)") //Medicare
The following classes and methods might be useful when working with test objects:
|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.|
Validate a test object
You can add test objects to the Web Object Spy dialog to verify the detection in 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.
Verify and Highlight
Katalon Studio Object Properties has a built-in Verify and Highlight feature to help users double-check if the web objects can be located. Katalon Studio will display the message on how many elements are found or NOT found with generated XPath locator. If the object is found, it is be highlighted with the red border.
Once finished, click Save to add the object to Object Repository as normal.
Visual object recognition
Image locators allow you to identify test objects with images and perform web image-based testing. Learn more at Web Image-based Testing.
Enable image-based object recognition
From version 7.6.0 onwards, image-based object recognition is enabled by default for web test execution in Project > Settings > Self-healing > Web UI. See Self-healing tests in Katalon Studio.
Capture screenshot and create screenshot property of an object
The ingredients required for the image-based object location to work include:
- Target screenshots of a web element
- The screenshot property of that element
There are two ways to create the required ingredients:
In Tests Explorer, under the Screenshots folder, you can see the Matched Elements and Targets folders.
- The Matched Elements folder contains objects that are located by Katalon Studio based on the target images.
- The Targets folder is for containing the images that Katalon Studio uses for locating objects.
- For a sample project, download from our GitHub repository: image-recognition-web
Factors affecting image comparison
Screen Resolution: The screen resolutions of tests executing machines and screenshots capturing machines may affect the effectiveness of image comparison. We recommend capturing screenshots and executing tests on the same machine for a better result.
Capture Tool: To capture screenshots associated with your preferred web elements, we recommend using the built-in screen-capturing feature in Web Recorder and Spy Tools. Particularly, on the expanded view after clicking Show Captured Objects, select the Add Screenshot button on the bottom right corner.