Manage Test Object

Estimated reading time: 6 minutes

Create a Test Object

  1. Select File > New > Test Object from the main menu. The New Test Object dialog will display.

  2. Provide the name for the new test object, then click OK button. A new test object is created under the Object Repository of Katalon Studio.

Add an object property

There cannot be two properties with the same name in the same test object.

  1. In the Test Object Editor, click on the Add command.

  2. The Add property dialog will display. 


    Field Description
    Name The name of the object property. The drop-down list provides some common options for your selection (XPath, CSS, class, id, title) or you can enter manually.
    Match condition The condition used to search for the "actual" object in the application under test when executing automation tests.
  3. The new property is added to the properties list as specified. Provide the value to be used to search for the "actual" object in the application under test when executing automation tests.

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. In order to do so, you have to use 'Switch To Frame' keyword before interacting with the elements. 

Katalon Studio supports the ability to define parent iframe object within test object view, so you only need to select the parent iframe and the execution will automatically switch to that iframe.

Properties used for detecting an object

Selection Method

Read more about Selection Method.

Katalon Studio allows you to choose different ways to locate objects.

  • XPath
    • Katalon Studio supports Relative XPath for better object recognition. If an element cannot be consistently located using its direct attributes, Katalon Studio will identify the element by using its more robust neighbors.
  • Attributes
    • Katalon Studio will automatically generate its XPath combined with object properties to locate the object. This XPath will be displayed in Selector Editor
    • A test object is typically built up by a number of properties. During test execution, Katalon Studio bases such information to detect an object. Using Detect object by field, you can determine the properties to be utilized for recognizing objects.
      In the following example, Katalon Studio will try to find any object on AUT with both text and XPath tp satisfy the defined criteria during execution.
  • CSS
    • When selected, users are allowed to manually input CSS locator for objects in Selector Editor.

Validate Test Object on AUT

You can add test objects to Web Object Spy dialog to verify 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.

  1. To add an object to Web Object Spy, simply right-click on the item to open its context menu and select the option.

Parameterizing Test Object

Katalon Studio provides the user with the ability to handle dynamic objects (Objects that have some particular property change due to certain business rules). By supporting a way to parameterize test objects, users can leverage this approach to control objects dynamically. The example below describes the basic steps to do this:

  1. Open your Test Case in Manual View and double-click on the object that you want to parameterize its properties. 

  2. The Test Object Input dialog will display. Expand the Object Parameters section and declare your expected dynamic properties to identify the test object during execution. For this example, Katalon Studio will make use of the 'id' property with its value when finding the 'txt_UserName' object.

  3. Once the property is declared, you can switch to the test case Script View and adjust the value of the property to be perceived. (Typically, users will want to pass property value as variables or make reference to data files according to their situation.)

    The general syntax to find a test object using a dynamic property is as follows:

    findTestObject('{your test object}', [('{property}') : '{value of property}'])

    For example: 

    + One dynamic property:

    findTestObject('Page_Login/txtUserName', ['id' : '48415648'])

    + Two dynamic properties:

    findTestObject('Page_Login/txtUserName', ['id' : '48415648', [('name') : 'controler14585']])

    + Using the variable for the value of the dynamic property:

    + Using the variable for value in test object:

Test Objects in Scripting View

The test case Script View allows you to programmatically define and handle Test Objects as needed. The following is a simple sample demonstrating how to do that:

  1. Refer to existing objects using the findTestObject() method:

    // Find an object which was defined already in Object Repository
    myPredefinedObject = findTestObject('Page_Katalon Studio/a_Free Download')
  2. Create a new object programmatically using TestObject class:

    // Create a new object programmatically
    myNewObject = new TestObject("TheObjectName")
  3. Add the property to an object using addProperty() method:

    // 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", ConditionType.EQUALS, "//html/body", true)

The following API docs may prove 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 properties) Set the properties of the test object
getObjectId() Get object ID.
findPropertyValue(String name, boolean caseSensitive) Find the value of a property using the property name

User Contributed Notes