Katalon Studio – Creating Objects

The first thing to understand with Katalon Studio is that it’s object oriented. That means that every item you want to interact with on the page should have an object created for it. For example, if you want to enter text on a form, that input field would be an object referencing the path to find it. If you want to click the OK or Submit button on a page, there should be an object with the path to the button.
At first, that may seem like extra work and perhaps even a waste of time. But in the long run, it’s very beneficial. You have to reference the object anyway, but this method gives it a friendly name and again, if the path to the object changes, it only needs to be changed in one place.
As an example, let’s say you wanted to enter text into a form. Here is an input field on a real Inventory Search page I’m working with.
image

Using Katalon, the input field has a referenced of:
css=input.form-control
//div[@id=’wrap’]/div/div/div/div/input
The first is the CSS method to name the object, while the second is the XPATH notation. In Katalon Studio, under the Object Repository folder, I make a new Test Object and call it:
input-Inventory Search
I then add either the CSS reference, the XPATH reference or both. You can toggle the Detect Object By option as to which reference should be used.

image

With that input field now defined, I can enter the name of the product into the Inventory Search using the following command:
WebUI.setText(findTestObject(‘Page_/Search Inventory/input-Inventory Search’), ‘shingle saw’)
The line above is broken into several parts:
WebUI.setText – The command to enter text into a field
findTestObject(‘Page_/Search Inventory/input-Inventory Search’) – The page to the location of the object within the Object Repository. This is equivalent to the folder and pathname of a file.
‘shingle saw’ – The actual text I want to pass to the setText command. This enters the text, "shingle saw" into the input field.
This is a simple example, but demonstrates the idea.
Now let’s take this New Prospect Form:
image
Each field would be an object. There would also be an object definition for the New Prospect button itself, the GO button, the Save Button and the Cancel link. Within the code I would Click the button reference or setText for the input field reference. And to keep things organized, I would make a folder called Prospect Search in my Object Repository and place all the objects for the page in that folder.
Here is the New Prospect folder within Katalon Studio. Each object maps to a field on the form with the XPATH to the input field or button.
image
To fill in the form, I would use the following code:
//The following fills in the fields of the form
WebUI.click(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/btn-Create New Prospect Button’))

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Company Name’), ‘Amazing New Company’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-First Name Last Name’), ‘john Smith’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Address Line 1’), ‘1313 Mockingbird Ln’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-City’), ‘Charlotte’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-State’), ‘NC’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Zip Code’), ‘28203’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Phone Number’), ‘9805551212’)

WebUI.setText(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Email Address’), ‘testcustomer@domain.com’)

WebUI.click(findTestObject(‘Page_/Prospect Page Objects/New Prospect Fields/Prospect-Save Button’))
The first link Clicks the button for New Prospect.
The following lines enter information for each field corresponding to name, address, city, state, etc.
The last line in the code clicks the Save button.
The code reads far better and makes more sense than a slew of references like:
//div[@id=’add-prospect’]/form/input[3] or
name=add1
In my projects, I have objects defined for
Buttons
Tables cells
Links
Headers
Input fields
Labels
Checkboxes
Links
And just about everything else.
The main way to reference an object is using:
ID
Xpath
Name
CSS
As a final comment, it took me forever to find how to reference items in a table using variables. For example, I have the following "table" of numbers. I want to read the text from each cell and do something with it. I don’t have to define each "cell" as an object. I can substitute a ‘variable’ into the XPATH to make it more dynamic.
image
The XPATH for the table looks like: //div[@id=’wrap’]/div/div[3]/div[${Variable}]/div/p
Note the Variable reference in the braces. This should look familiar for those who used the Selenium IDE to reference variable names. It can be any name, I simply chose the word Variable.
To read through the 9 numbers that make up the cells, I can use the following code:
for (loop = 1; loop <= 9; loop++) {
    dailySalesDetails = WebUI.getText(findTestObject(‘Page_/Sales Dashboard/Daily Details/Daily Sales Details Sales Header’,[(‘Variable’) : loop]))
The getText should look familiar, but it’s the part at the end that creates the magic. It passes the value of ‘loop’ which is my counter for the FOR loop, to the defined object at the location where Variable is defined. In this case, it’s for the DIV.
As the loop progresses, the line above would become:
//div[@id=’wrap’]/div/div[3]/div[1]/div/p
//div[@id=’wrap’]/div/div[3]/div[2]/div/p
//div[@id=’wrap’]/div/div[3]/div[3]/div/p

//div[@id=’wrap’]/div/div[3]/div[9]/div/p
The object oriented aspect of Katalon is actually extremely handy. It makes the code more readable and if something changes, I don’t have to change it in every test. Every test referencing the object will automatically use the new path.
Variables can be added to XPATH references which makes it efficient for reading tables and columns of data. This was a buried nugget of information, so hopefully others will find it useful.

Other articles of interest:

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments
  • Conditional Statements – IF .. ELSE IF in Katalon Studio (1)
    • Allyson: I used this : elementVisible=WebUI.verifyEle mentPresent… but it failed because “FAILED because (of) Unable to verify object ‘Object Repository/Homepage/b_vaolopho c’ is present (Root cause:...
  • How To Disable the Quicken Registration Prompt (16)
    • Dave: Works for Quicken 2007 too. Thanks, Gina!
    • Charlie Fellenbaum: Yay, thanks, and that worked for Quicken 2006 as well.
    • Ken: This didn’t work for me. I have 2006. I installed on a new laptop. I must have registered before, don’t remember. I tried to register this time, but got an error message. I’d rather not registered, though. I use...
    • Neil Murphy: I discovered that early on. I’m using 2001.
    • Jeremy: Thank you so so so much. I am still using Quicken 2010 because Intuit didn’t want to properly support users abroad anymore (never mind that they only link to US banks for transaction downloads; they didn’t want my...
  • Quasi Performance/Load Testing with Katalon Studio (1)
    • Anthony: I have done this with 100 plus machines at the same time and it worked well and provided some useful feedback.
  • A Try Catch example in Katalon Studio (3)
    • Venkatesh: Hi Don Pedro Can you share me sample project ….which consist of basic to advanced stuff…If your github or gitlab url aso present please share… As I am beginer to this I need to learn lot
    • Don Pedro: Hi Lucas. Thank you for the kind comments. I would be happy to help. Let me know how I could be of assistance.
    • Lucas: Thanks for sharing a lot of Katalon tips and tricks. The Katalon team highly appreciate your support and feedback. To make Katalon Studio better and be the best free automation solution for testing community, we wish to coordinate...
  • Securely storing passwords and login details with Set Encrypted Text in Katalon Studio (1)
    • Agus: Hi Don, Is there a way to set the encrypted text to be used in the ‘WebUI.authenticate̵ 7; method? Basically I am trying to encrypt the password that is passed to the ‘WebUI.authenticate̵ 7; method. Thank you.
  • Katalon Studio – Manual View – The start of a test script (2)
    • ben: Hello Don Great Website. Keep up the work. I learnt a lot. cheers Ben.
    • Lucas: Hi Don Pedro, Thanks for sharing a lot of great articles related to Katalon Studio and Selenium. I am Lucas from Katalon team. From your point of view, we’ve learnt alot to improve our product and add more valuable features...
  • Another success with Katalon Studio (1)
    • Mahesh Joshi: Hi Don, I just started following your blog in regards to katalon. I want to introduce katalon studio at my work we do manual testing at work at the moment. What approach I should use for proof of concept with katalon for...
  • What went wrong with Crime City? (34)
    • G D: One thing I have noticed is the awkwardness of items and the attack points and how you can earn them. I was pretty pathetic with attack points and then I played that limited time boss and got weapons that had attack points in the...