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
  • Filling forms with random numbers in Katalon Studio (2)
    • Don Pedro: randomNumber is the variable that holds the result of generating a new random number. Depending on how things work on your site, you might need to convert the number to a String before it’s recognized correctly....
    • Seth: When you are setting up randomNumber is this a new keyword or a new variable? I am trying to randomly generate unique socials and can’t seem to connect my generator to my Set Text.
  • Working with Dates and Date Formatting in Katalon Studio (5)
    • Ann: THANK YOU ! That worked perfectly !
    • Don Pedro: import groovy.time.TimeCategory currentDate = new Date() println currentDate use( TimeCategory ) { after30Mins = currentDate + 30.minutes } println after30Mins https://stackoverflow.com/ques tions/21166927/incrementing...
    • ricky julianto nugroho: hay can u gave me an example for plus a hour in the time ? example : now is 15 pm i want to print 16 in the text thank you
    • Don Pedro: formattedDate=mydate.format(&# 8220;MMM”) – Nov formattedDate=mydate.format(&# 8220;MMMM”) – November
    • Ann: This was a huge help. Thank you ! Do you have something for capturing the month spelled out? and abreiveiated? Example November Nov Thanks !
  • Boostnote for Code Snippets (1)
    • Manual: Hi Don, Regarding the code snippets and examples that you have created. Is there any GitHub repo or something that can be shared? Thanks
  • Using TypeIt4Me with Katalon Studio (3)
    • Manual: That’s great thanks for sharing.
    • Don Pedro: Added a screenshot to show some examples of how I have shortcuts configured for Groovy code. TypeIt4Me supports groups, so you can create shortcuts related to Groovy, Selenium, and other topics to keep them organized. You can...
    • Manual: Hi Don, I like the idea of using the TypeIt4Me for scripting test code. Could you please share how I can create. I also like the idea of creating code templates to use with code editors. Thanks, Manual
  • Another success with Katalon Studio (2)
    • Don Pedro: Since Katalon is free, a very practical demonstration of what it can would be to create the code needed to fill in forms. That was one of my first tasks as Katalon could fill in a lengthy form in seconds versus the minute or...
  • How To Disable the Quicken Registration Prompt (18)
    • Susan Long: I have Quicken personal 2012 which I only use to enter and retrieve data. It suits my needs perfect. Now they have blocked my access and want me to re register. I don’t want to upgrade as it I am comfortable with this...
    • Stewart: I have been using Quicken 200 basic since it was introduced but I now have a new PC using windows 10 and can’t get rid of the registration prompt. I have tried the above control/shift trick but to no avail. Any ideas
  • 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:...