Skip to end of metadata
Go to start of metadata

Create a Test Object

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


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

 

Add an object property

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

 

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


  2. The Add property dialog is displayed. 

    where:

    FieldDescription
    NameThe name of the object property. The dropdownlist provide some common option for your selection (xpath, css, class, id, title) or you can enter manually if wanted.
    Match conditionThe condition which will be used to search for the “actual” object in the application under test when executing automation tests.
    ValueThe value which will be used to search for the “actual” object in the application under test when executing automation tests.

    Click OK when you finish with configuring.

  3. The new property is added to properties list as specified.

Manage parent object

Nowadays, there are many web applications which render 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 does support the ability to define parent iframe object within test object view, so you just only need to select the parent iframe and the execution will automatically switches to that iframe.

Properties used for detecting object

A test object is typically built up by a number of properties. During test execution, Katalon Studio bases on such information in order to detect an object. Using Detect object by field, you can determine the properties to be utilized for recognizing objects.

In the following example, if during execution, Katalon Studio could find any object on AUT with both href and class that satisfy the defined criteria, then that object will be recognized as the a_Free Download object.

 

Validate Test Object on AUT

You can add test objects to Web Object Spy dialog to verify whether they are still correctly detected in the application under test. Refer to Web Object Spy 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 user with the ability to handle dynamic objects (Objects that have some particular properties 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 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 is displayed. Expand the Object Parameters section and declare your expected dynamic properties. These properties will be used 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 Script View of the Test Case and adjust how the value of the property to be perceived. (Typically, users will want to pass property value as variables or make reference to datafiles according to their situation).

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

    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 variable for value of dynamic property


    + Using variable for value in test object:

Test Objects in Scripting View

The Script View of Test Case allows you to programmatically define and handle Test Objects as needed. Following is a simple sample showing you 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 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:

ClassMethodDescription
Test ObjectaddProperty(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 object ID.
findPropertyValue(String name, boolean caseSensitive)Find the value of a property using the property name

 

 

  • No labels