Create a Dynamic Object at Runtime
I'm not quite at the point to need to make an object outside of the Object Repository, but I've seen reference to it multiple times and wanted to put together a simple example because who knows when it might come up. There have been several comments about keeping the size of the Object Repository small so it's better to programmatically create a one-off object rather than commit it to the project.
Katalon Studio allows creating objects during runtime through the TestObject library.
import com.kms.katalon.core.testobject.TestObject as TestObject
The object is created by giving it a name and associating a property to it. In the very simple example below, "xpath" is set with the location of a tab on the page.
TestObject is created with the name
"dynamicObject" is given an xpath value that equals the contents of the xpath String
Once the object has been created, it can then be clicked.
The main work is done through this command:
TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', ConditionType.EQUALS, xpath, true)
TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', ConditionType.EQUALS, xpathOfObject, true)
There is one important thing to note, since this object is not part of the project Object Repository, the call to manipulate it is slightly different. Note there is no, findTestObject, or the path of the object as part of the command. If the object were part of the project, the command would look like this:
The same would be true if this object were passed to a Custom Keyword:
Again, I don't know that I have a use case for this scenario, but others have brought it up, and Katalon fully supports it. A dynamic object is quite an easy thing to create and the only real change is how the object is referenced by telling Katalon not to look in the Object Repository, but "locally" if you will.
Other articles of interest:
- Passing Katalon Objects with Parameters to Custom Keywords
- Checking for the presence of an object without throwing an error
- Entering and reading text GetText, SetText and SendKeys in Katalon Studio
- Katalon Studio – Creating Objects
- Clicking Buttons, Links and Drop downs in Katalon Studio
- Get the xpath of an object in the Object Repository using findPropertyValue(‘xpath’)
- New Libraries to Import into Katalon Studio
- To markFailedAndStop or Not To markFailedAndStop?
- Working with Tables using the Selenium WebDriver and Katalon Studio
- Using the Katalon Automation Recorder to find Objects