Passing Object Names as String Variables in Katalon Studio

While working on a Custom Keyword, I noted the code could be even more modular if I was able to pass in the object name. It doesn’t need to be an object, just the path to the object in the Object Repository. As a simple example, take the code to read the value from a Select or Input field. The code is the same except for the referenced object. The code would look like: int resultsPerPage=WebUI.getAttribute(findTestObject(‘Sales Data/Sales Table/select-Results Per Page’),’value’).toInteger() With that in mind, we could create a variable with the path, then call the Custom Keyword with that variable. The code would then look like: objectPath=”Sales Data/Sales Table/select-Results Per Page” CustomKeywords.’commonCode.DataCollection.getResults'(objectPath) We could then change the path and call the Keyword again, still using the same code. As a slightly more involved example, we have a page with three sets of filters. Each row has a different definition which meant three objects in the repository. When setting up code […]

Enter dates into a date picker for Chrome and Firefox

I’m not a fan of, nor am I versed in handling the latest trend of using date picker calendars so I was trying to cheat my way around it by entering a date in the input field. But, this lead to another problem, at least for the date picker we were using. It also lead to two interesting answers on how to solve it. When entering the date, Chrome and Firefox need the date information passed in two completely different ways. Not just the format of the date, but the commands themselves. For Firefox, the setText command worked as expected. For Chrome, sendKeys was needed. Additionally, Firefox needed the year to come first. This means the code isn’t interchangeable and generates an error when used with the wrong browser. Since there two different commands are needed, how do you handle the right case for the right browser? Here are the two commands for entering the date into the text field […]

Currency Formatting with getCurrencyInstance()

One of my normal practices is to strip all the formatting from a site value, simulate the site calculations, then compare my calculated value to the site value and display the results in the log file. But without formatting, the results can be hard to read as they go scrolling by. To add the formatting back is a relatively simply process. We can use the NumberFormat package and the format option to put the $ and , where they belong. Thus, 16384 becomes $16,384. To use the formatting, import the following libraries, which sets the formatting based on locale. import java.text.NumberFormat import java.util.Locale Next, create reference to the NumberFormat library: NumberFormat defaultFormat = NumberFormat.getCurrencyInstance() Finally, format the number back to a dollar figure: log.logWarning(‘Total amount in dollars is:’ + defaultFormat.format(totalAmount)) One thing to note, the value to format must be an integer, float, double or big decimal value. Basically, anything other than a string. As a basic example: import com.kms.katalon.core.logging.KeywordLogger […]

Boostnote for Code Snippets

After working with Katalon Studio for several months, I have a wealth of code snippets and examples. And with my collection growing each day, where to store them all for easy access? The most common examples are in TypeIt4Me, but the rest need a good storage place that is easily searchable. There are quite a few code snippet tools available such as Quiver and Snippetslab, but I recently got hooked up with Boostnote and find it’s just what I’m looking for. Boostnote is a Markdown editor with syntax highlighting for dozens of languages with Groovy, Java, HTML and CSS right there in the mix. Code can be organized into different folders and each snippet can be tagged for further grouping and easier search. Each snippet can have multiple tabs, so examples, links and other pieces of information can be found under a single header. For example you can have getText and setText examples for Katalon and Selenium tied together. Boostnote […]

Using the Katalon Automation Recorder to find Objects

While Katalon Studio has the built in SpyWeb tool, and it works quite well to capture objects and build a repository, I don’t find myself using it that much. Instead, I rely on the Katalon Automation Recorder, the replacement for the Selenium IDE. I find it quicker to start, and runs alongside the web page. I also find it easier to pick from multiple styles of object paths without all of them being assigned to the object itself. For those who worked with the Selenium IDE, the interface and usage are almost identical and comes as a Firefox or Chrome plugin. Once running, it’s just a matter of clicking the Inspect button then selecting the object in question. When hovering over an object, it will turn yellow, and when selected, the XPATH will appear. If you want more choices of that object is defined, click the dropdown arrow and additional choices, if available, will be listed. You can also enter […]