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:

//div[@id='table']/table/tbody/tr[${row}]/td[${column}]

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:

//table[@id='DataTable_Name_${index}']/tbody/tr[${row}]/td[${column}]

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:

Leave a Reply

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

Recent Comments
  • How To Disable the Quicken Registration Prompt (26)
    • Denise Defoor: I have a Quicken SE Version 6 .. My computer crashed a few weeks ago and I finally got it up and running. Now Quicken is telling me I must registered it. What? I have had this program for 20 years. How can I disable the...
    • Greg: For me, holding the *LEFT* CTL + Shift then clicking Online, One Step Update worked. I originally tried holding the right CTL + Shift, and it didn’t work. I’m using Quicken 2006, so I don’t know if it will work...
    • Joe SR>: My monthly income is deposited into my Credit Union account. I use debit whenever possible. I write checks manually and mail them. I use Quicken 2012 off-line only. I have entered all my money and investment accounts. I...
    • Prtet: Never say never….every time I swear I will never use Quicken again, I discover that there are still no viable alternatives. Amazing that there is no decent personal finance software.
    • Joe D.: Holding CTRL + Shift keys and selecting On Line | One Step Update from the main menu worked for my Quicken 2004. I’m grateful that you wrote a synopsis (“Simply put, …”) just beneath the link to the blog...
    • Susan Long: I bought my quicken disc in the beginning and it came with a registration number. I rang the helpline and they gave me the code to put in and talked me through it. It you downloaded your version then you don’t own it...
    • Peter: You might consider running your old version of Quicken on an ancient computer. This is what I have done for years. The newer versions are fraught with problems- criminal, in my opinion. One version made mathmatical errors when...
  • Parsing Strings in Katalon – Split, Substring and Readlines (4)
    • Anjana: Hey thanks for the response It is quite strange but initializing variable for delimiter and it worked String splitFormat = ‘-‘ WebUI.println(var_CampaignDura tion.toString().split(splitFor mat)[0])...
    • Don Pedro: I’m not really sure what the difference is, but I don’t think the “-“ in the split is the same as the one in the date. String var_CampaignDuration = “05/13/2019-06/07/2019&# 8221; String[] parsedDateRange =...
    • Anjana: Hi, I tried the same thing to split the string, but does not work for me, Could you plz point out whats wrong Variable var_CampaignDuration has value “05/13/2019-06/07/2019&# 8221; String[] parsedDateRange =...
    • Ellen: Thanks for sharing!! I like your contributions to Katalon topics.
  • How to Block games by Title and Tag on Steam (2)
    • Marcus861: I made an acc just to say: Same bro
    • JACK: Thanks, same just wanted to block anime games in my discover
  • Create a new and random UUID for an API call (1)
    • Anonymous: Hi ! I found this blog few weeks ago and it’s really helping me out with my tests! Thanks a lot for the Katalon tips and tricks ! Keep up the good work 🙂
  • Working with Dates and Date Formatting in Katalon Studio (6)
    • Ajoo: Thank you for the details. How do i remove leading “0” from dates. i.e. while formatting i receive 04/21/2019, but i need 4/21/2019. (same applies for date)