Passing multiple variables to an object in Katalon Studio
With the success of our first automation project, work has begun on automating another site. Based on the techniques already learned, solutions are being code a lot quicker than the first time around. One of the new methods to employ for this project is to create multi-parameter objects. For the first project there were lots of individual objects defined to retrieve specific pieces of information. This worked just fine, but it made for a lot of objects and a lot of maintenance. The goal this time is to try and slim that down.
The most common multi-parameter object is for a table where the row and column can be passed.
The object definition should look familiar and is represented by:
To read a cell from the table, the row and column can be passed as numbers, such as:
tempText = WebUI.getText(findTestObject('table-DataTable', [('row') : 1, ('column') : 3]))
To read the entire table, variables are passed in a set of FOR loops, one for row, one for column:
tempText = WebUI.getText(findTestObject('table-DataTable', [('row') : row, ('column') : column]))
The parameter can be used for the name of an object as well. For a particular set up we have, there are 4 filters. Each filter has a corresponding table. It’s now possible to make one object that represents all 4 tables and set up parameters for the table name, rows and columns.
The table is defined in the following way, where the name gets a parameter:
To select the correct table, it’s index number is passed for the variable, “index”. The first table on the site has a number of 0. For the code below, the table number is chosen, then column 3 of each row is read and stored.
tempText=WebUI.getText(findTestObject('table-DataTable', [('index') : 0, ('row') : loop, ('column') : 3]))
The same method can be used for Tabs, Click actions and List Items.
For example, a button object is created to take a parameter for “buttonIndex”. There are 4 buttons on the page, so to pick the correct one, the value is passed in. In this example, the second button on the page is clicked.
WebUI.click(findTestObject('buttonName',[('buttonIndex') : 2]))
Instead of making separate objects for each column, button, or set of tabs, a single object can be created that accepts multiple parameters. This cuts down on both the number of objects and the amount of code needed to interact with those objects. It’s merely an extension of passing a variable to an object, but the exact syntax can be a little tricky until you see exactly what it looks like.
Other articles of interest:
- Get the xpath of an object in the Object Repository using findPropertyValue(‘xpath’)
- A Custom Keyword to Verify a List of Product Categories
- Creating and Calling Methods for Test Cases in Katalon Studio
- Round and Round with the For..Next in Katalon Studio
- Working with Tables using the Selenium WebDriver and Katalon Studio
- Passing Object Names as String Variables in Katalon Studio
- Katalon Studio – Creating Objects
- Entering and reading text GetText, SetText and SendKeys in Katalon Studio
- Selenium based Custom Keyword to Count Table Rows in Katalon Studio
- Waiting on elements to appear using While Loops