Katalon Studio

Creating and Restoring Syntax Highlighting in Katalon Studio

While Katalon Studio comes with some formatting and syntax highlighting, it’s very beneficial to set up your own. The time investment will be worth it later when you can focus in on your code based on it’s color without having to read each and every line.

Katalon has two areas where you can set formatting options. Both are under Preferences.

The first is under General > Appearance > Colors and Fonts.

This handles the main font style, color and size of the editor window.

The other, related to syntax highlighting is located under: ​Java > Editor > Syntax Coloring

You will then have Java, JavaDocs, and Comments.

Java contains most of the options you will be interested in and you will see an example of your syntax highlighting in the Preview window.

Once this is set, it’s awesome, however, when you upgrade Katalon, those formatting options will be overwritten. This is not awesome.

But, it’s easily handled by making a copy of the files and restoring them after the upgrade.

The files for syntax highlighting can be found in:

/Applications/Katalon Studio.app/Contents/MacOS/config/.metadata/.plugins/org.eclipse.core.runtime/.settings

In there, you will find files by the name of:

com.kms.katalon.application.prefs
org.eclipse.jdt.ui.prefs
org.eclipse.ui.workbench.prefs
Etc.

I copy the entire directory and store it on my iCloud Drive. After upgrading, I copy the files back to the same location, overwriting what’s already there.

Keep in mind, you will need to start Katalon Studio at least once after the upgrade to create the correct folder structure and write the new files. I have noticed they don’t exists if you go straight in after upgrading.

You should now be able to set up your syntax highlighting and keep it between upgrades.

ks-syntax-coloring

Other articles of interest:

QA Regression Suite coming together

My automation project is progressing faster than I expected. I added the code to check for results, added code to count rows, and removed all the hard coded values I put in place.

The QA Execution Profile is now in place with the correct data values for that environment. I even swapped some of the String values for Lists so multiple values could be checked in a single pass.

I cleaned up the navigation code so the tests can either click the links they need, or they navigate to the correct location then call each other in the proper order.

I have just put together the QA Regression test suite and have been testing it against the site. It contains 21 tests, chained together, that run from start to finish.

With everything running together, I made a few adjustments to my data values, picked some better customers to work with, added a couple of checks to make sure objects were visible before starting, and added logging for a couple of events.

It’s not a comprehensive site validation suite, but it does perform one hundred actions or so, and completes in around 7 minutes. For me to perform the same actions is closer to 40 minutes.

At this point, I need to try different kinds of users and see the how the tests react. Do they fail gracefully? Do customers have data I didn’t anticipate? Are they missing something I need?

For next week, I will try this for a few dozen customers we have and see things work. Once that is completed, I will be ready to duplicate this Test Suite as the Prod version and go through the same process of trying it against the real Prod site.

I am very much on target to use this as for the after deployment smoke test we have scheduled at the end of the month.

Other articles of interest:

Waiting on elements to appear using While Loops

Timing is everything. Certainly so when it comes to automation and waiting for elements to appear before moving on to the next step. While Katalon has several wait methods, including the new smart wait, there are times when you have to wait for a text change. In this case, we aren't waiting for an object, we are waiting for a condition to change. For example, we need the number of search results to increase or decrease. Or we already have a list of names, but the one we want isn't available yet.

In these cases we will use the while loop to get our status and add a delay until what we are searching for is available.

In the example below, we are waiting for a status change. We have previously created an item and now we need for the status to show as "Sold." When that happens, we can proceed with the next step.

The first thing we need to do is search for our item and read the status. If it already shows as "Sold," we can move on. If not, we reset our search criteria and search for the item again. We also add a 1 second delay. We keep repeating this until we get our "Sold" status.

itemStatus = WebUI.getText(findTestObject('select-Status Action'))
while (itemStatus.contains("Sold")!=true){
    //If the item is not set to Sold, search for it again to refresh the results
    WebUI.setText(findTestObject('input-Search Name'), GlobalVariable.itemList)
    WebUI.click(findTestObject('btn-Go Search'))
    WebUI.click(findTestObject('btn-Filter-All'))
    WebUI.delay(1)
    itemStatus = WebUI.getText(findTestObject('select-Status Action'))
}

This will certainly work, but there's a problem. If the status doesn't change, we have an endless loop. What we need is to check the condition and implement a counter. We can then check that our condition is met AND we haven't tried too many time. This can be done using the AND (&&) as part of our loop.

In this case, if we don't find the user name AND we try 20 times, it's time to bail out and fail the test.

In the example below, we are searching for a user. Since we already have a table of names, we can't wait for an element, because it's already visible. We also can't assume the first name we is correct since it may not have changed correctly and we will get a false positive.

We read the first name in the list to see if it's the one we want. If not, we add a delay of 1 second, then read the name again.

Additionally, we have added a counter that will increment up to 20 times. This equates to 20 seconds, which should be more than enough time for the name to appear.

If for some reason it doesn't, we won't be able to proceed, so the test is marked as Failed and stopped.

    //User Name in column 1, User Role in column 5
    userName=WebUI.getText(findTestObject('table-User Role Details', [('row') : 1, ('column') : 1]))
    while(userName!=GlobalVariable.UserName && counter<=20) {
        if (counter>=20){
            log.logError('ERROR: Login and User Name DO NOT match')
            log.logError('Could not find user: ' + GlobalVariable.UserName)
            KeywordUtil.markFailedAndStop('ERROR: Login and User Name DO NOT match')
        }
        WebUI.delay(1)
        userName=WebUI.getText(findTestObject('table-User Role Details', [('row') : 1, ('column') : 1]))
        counter++
    }

These are simple examples, but they show the process of waiting for something to change that isn't based on elements. In many cases, the page is loaded, we just need to wait for a certain piece of information to change. This is better than a forced delay WebUI.delay(1) because we can still have a dynamic test.

In one run it might take only a second for the status to change. In another run it might take 5 or even 10 seconds for the change to occur. With the while loop, we can handle both without the test waiting when the condition is actually correct.

Other articles of interest:

Connecting Katalon Studio into XLS and CSV files

Since reading from external source files has become an important part of how we get data, I wanted to put together some simple examples to show reading data from a CSV file, an XLS file and from a Database source. All three are very similar and since Katalon handles most of the work, it's easy to grab data from a file with just a few lines of code.

We start by using the TestData library and reference the "Test Data File" from the "Data Files" object in the project. That is done with:
TestData csvData = findTestData("Data Files/Data Source Name")

Once we have that, we can use some of the built in Katalon keywords to get the number of rows in the file and the column names.
int rowCount=csvData.getRowNumbers()
List columnNamesList=csvData.getColumnNames()

Once we have that information we know how many rows we can read and how many columns. We then use getValue to read our piece of information.
temp1=csvData.getValue(columnName, rowNumber)

When working with a database, there is one small addition. We can use getAllData to retrieve all the items that have been returned from the query. This isn't a necessary step since we can still get the number of rows and parse through the data. However, if the entire block of data is needed, getAllData can be used.
List resultSet=dbData.getAllData()

In such a case, your data will be returned in this format:
[[04GA, 61], [04OC, 93], [02OC, 334]]

For the above we have the SKU followed by the quantity.

Again, Katalon provides a very simple way of connecting into different kids of data sources and retrieving information. This has certainly improved my Test Cases and opened up a variety of test possibilities.

Read data from CSV file

TestData csvData = findTestData("Data Files/csvDataSource")

int rowCount=csvData.getRowNumbers()
println rowCount
int rowNumber=1
List columnNamesList=csvData.getColumnNames()

columnName=columnNamesList.indexOf("columnName")+1
println columnName
temp1=csvData.getValue(columnName, rowNumber)
println temp1
Read data from XLS file

TestData xlsData = findTestData("Data Files/Inventory Items")

int rowCount=xlsData.getRowNumbers()
println rowCount
int rowNumber=1
List columnNamesList=xlsData.getColumnNames()

columnName=columnNamesList.indexOf("Item Name")+1
println columnName
temp1=xlsData.getValue(columnName, rowNumber)
println temp1
Read data from Database

TestData dbData = findTestData("Data Files/PostgresDB")
numOfResults=dbData.getRowNumbers()
List columnNamesList=dbData.getColumnNames()
println columnNamesList
List resultSet=dbData.getAllData()
for (loop = 0; loop <=(numOfResults-1); loop++) {
    println(resultSet[loop])
}

temp1=dbData.getValue(2, 1)
println temp1
temp2=dbData.getValue(3, 1)
println temp2
columnName=columnNamesList.indexOf("column name")
println "column Position:" + columnName

Other articles of interest:

Adding Timing Flags to Test Cases within Katalon

I've made reference to this before, but due to the success I've had using it, I wanted to bring it up again.

Within my tests cases I have been adding markers to time how long it takes to complete an action. This is usually connected with the Save action or something similar. For example, how long does it takes to save the form data? Or how long does it take to move from one page to another.

Using the "feature flag" idea, I place the start of the code right before there is an action to click the button. After the click action, there is a waitForElementVisible action, which waits for an email address input field to become visible. Once we can take action on it, the Save action is complete and we can record the time between those two events.

if (timedTest==true){
    timeStart = new Date()
}
WebUI.click(findTestObject('btn-Save Cart))
WebUI.waitForElementVisible(findTestObject(input-Email Address'), 90)
if (timedTest==true){
    timeStop = new Date()
    TimeDuration duration = TimeCategory.minus(timeStop, timeStart)
    log.logWarning("Execution Time: " + duration)
}

The same process works when moving through pages. Click the link or button that moves to the next page and wait for an item to appear that proves the page has been loaded. Take the time between those two events and output it.

Additionally, I have been outputting these times to a text file so I can gather some benchmark data. As an example, the following is listed within the timedTest flag.

    File file1 = new File('/FileLocation/savetimes.txt')
    file1 << "Execution Time: " + timeStop +"," + duration"

This has been a huge benefit for our performance testing. I can run the same test dozens of times of and record how long it takes. I don't have to guess or write it all down manually. It all becomes part of the test and gets tracked over time.

After we make a change, I run the same tests again and record the new results. This easily creates the Before and After benchmarks.

You can even add a small bit of code to give you a visual cue things are going south.

    String timeCounter=duration
    timeCounter=timeCounter.replaceAll(' seconds','')
    float timeValue=Float.valueOf(timeCounter)
    if (timeValue>15){
        log.logError('ERROR: The save time for the item is higher than expected')
        KeywordUtil.markError('ERROR: The save time for the item is higher than expected')
    }

Katalon Studio may not be a performance or load balancing tool, but you can easily track metrics and show processes that are taking longer than normal. This probably isn't part of a regression test, but by combining the feature flags with the TimeDuration library you can record all sorts of metrics about your test which can be incredibly value.

Other articles of interest:

Recent Comments

  • Enter dates into a date picker for Chrome and Firefox (1)
    • Prasanna: Hello, How to enter a previous month FIRST day and LAST day from the system date. Thanks Prasanna
  • How To Disable the Quicken Registration Prompt (31)
    • Juani: Hi, I have a registered Quicken 2016 and now my files are being held hostage by Intuit, cannot log in with my ID unless I upgrade therefore buy a subscription, I need to access my files, please HELP. Thanks
    • David: A BIG Thank you! I regularly reinstall Windows OS’s using different hardware configs. In short, Quicken 2011 (it’s March of 2020 as I write this) has been a program I’ve been very happy with and continue to use....
    • Karen L: Today I rang Reckon Australia again, got a different guy and he talked me through the process of getting me a new product key to enter since I already had the licence and it had been extended. Reckon have only extended it by 1...
    • Karen L: I have Australian Quicken 2008 on Windows 8.1. It keeps asking me to renew my licence which Reckon did for me however the activation won’t work. I tried this to disable the registration prompt however it did not stop the...
  • Building Relationships with Developers (1)
    • Carlos Herrera: Ah yes. I have a team of software developers and it is genuinely so hard to keep them in the loop during projects. Though the more we work the better the communication becomes and we go from a trail and error process to a...
  • Integrating DevonAgent Pro with Alfred (1)
    • J. Garr: Beautiful, sweet, and simple. I love it; thanks for posting this solution.
  • Round and Round with the For..Next in Katalon Studio (1)
    • Sweet Ophaline Labador: Hello can you help me how to loop this scenario. Checking the elements is just the same. I want to check that the following function is available in www.siacargo.com: Track Shipment – clicking on this can...
  • Parsing Strings in Katalon – Split, Substring and Readlines (6)
    • Don Pedro: String tempText=”Date Month January. Revenue $1,355,721.00″ println(tempText.split(“ \$”)[1]) You need to escape the $ with \$ The [1] on the split captures characters on the right of the split [0]...
    • Prasad: Hi, I need to get the substring from the below string ‘Date Month January. Revenue $1,355,721.00’ I want to extract text after $ value. Please help Thank you
  • Working with Dates and Date Formatting in Katalon Studio (15)
    • Sangeethaa: How to get previous day’s date(Yesterday’s date)? Actually I was using today.previous() before,it was working fine till today morning.Now its not retrieving right date. Can anyone please guide me on this.
    • Don Pedro: That could be a little tricky. First, is the text/format always going to be the same? You will need to do some parsing. Separate the first but of text at 2019. After that, split the text again to get rid of Central Standard...
    • Don Pedro: It should be of the same Date type as today. You could then do some calendar trickery with Calendar /*Calendar c = Calendar.getInstance(); //c.set(Calendar.MONTH, 1) //Set the month, 0=January, 11=December println...
  • Output status messages and test information by writing to the Log File Viewer in Katalon Studio (6)
    • Saranya: Good One. Could you plz share link to access all your katalon related blogs. ThankQ
    • Rodrigo Calabretta: I’m using the KeywordUtil.markFailed or KeywordUtil.markError and my test stops is being shown as Error and If I use in the @afterTestCase the testCaseContext.getTestCaseSta tus() to show the status test case...