One ReplaceAll Statement to Rule Them All!

Well, sort of. In reviewing my code to make it more efficient, I noticed I have several variations on the .replaceAll() statement. In some case I'm trying to remove the $ and , from a value. In others I'm trying to remove the newline and CRLF characters. For another the goal was to remove the ( and ) from a value. And yet another was for the \ in a date. On top of this, I called replace several times in a row in order to remove specific characters or a string. While those work, there is a way to accomplish this in a single call and return just the number I'm really looking for. For example, I have the value $5,573,127 and want just the integer value. That can be done with: tempText=tempText.replaceAll("[^0-9]","").toInteger() Everything that isn't a number will be removed and I'll have 5573127 as an Integer. This includes ()[]$,. and -. If the value is -$5,573,127.35 and […]

Call the same Test Case twice with a Custom Keyword

I recently had cause to run a series of tests where I needed to call the same Test Case multiple times, something Katalon Studio does not inherently support. For my test, I wanted to enter several pieces of information into a form, then perform the same validation steps to check table data. The validation steps are the same each time, so I wanted to reuse the test case. No such luck, Katalon Studio does not allow you to add the same Test Case name to the Test Suite. My first thought was to duplicate each Test Case multiple times, putting a number in front. That seemed awkward and wasteful. I then noted I could go into the Test Suite XML file itself and repeatedly add the same Test Case name multiple times. While interesting, each Test Case is tied to a GUID, so I would need to make a fake one and that's by no means to maintain. And if […]

Selenium based Custom Keyword to Count Pagination in Katalon Studio

Another common task when working with web pages is to count the number of page results returned from a table. In most cases this means using the Webdriver to count the number of UL/LI elements in an object. This corresponds to the number of pages. Like counting the rows in a table, this can be set up as a Custom Keyword and called from any Test Case. For the websites we develop, the pagination also contains extra buttons. There is usually an extra button to jump to the first entry and another for the last. There is also one to move forward by one page, and one to go back. Depending on how the pagination is put together there may be extra “pages” that aren’t actually part of the result set. This means if there are 10 pages in the pagination area, and there are 4 navigation buttons, the actual number of pages you can get to is 6. The […]

Selenium based Custom Keyword to Count Table Rows in Katalon Studio

When working with tables, one of the most common tasks is to count the number of rows in that table. Even though Katalon has the ability to create a parameterized version of the table object, you still need to know the number of rows or columns available. The most common way is through the Webdriver, get a List of the returned objects and then get the size. After doing that a couple of times, I’ve switched over to calling that code from a Custom Keyword and simply call it from the Test Case. To make it dynamic, the xpath of the table is passed. This builds on the idea of passing the Katalon Object as a String. In this case, the xpath is passed as a String so it can be used anywhere. The basic Keyword is quite simple and looks like this: public class selenium { KeywordLogger log = new KeywordLogger() @Keyword def countRowsPerPage(String xpath){ WebDriver driver = DriverFactory.getWebDriver() […]

Creating and Calling Methods for Test Cases in Katalon Studio

While it’s possible, and encouraged to set up Custom Keywords to perform repeatable code blocks, the same thing can be done within the Test Case itself. Methods can be defined with the Test Case and called as many times as needed. As an example, let’s say there are 5 filter boxes on the site. Each filter has a value for a certain type of result. A simple test would be to click each filter and confirm the results in the table match the filter type. Using the brute force method, there would be 5 code blocks with almost identical code. We would want to read the type of filter, perhaps count the results, click the filter, then confirm the values in table of results. If we built a method within the Test Case, we could pass in the filter object details, then capture the information we need. To create the Method, we set it up the same way as it […]