Stripping away characters with ReplaceAll in Katalon Studio

After reading in text, it’s a common need to replace some of the text or get rid of it entirely. There may be a need to remove a comma, a dollar sign, take off a parenthesis etc. While ReplaceAll is a simple command, there are some tricks to it, especially when using special characters like $ and (). As an example, almost all the values on the site I’m working with have $ , and % in the number. In order to manipulate them, those characters need to be removed. It’s common that after a GetText command, there is a ReplaceAll command. Since the $ is a special character, the Groovy interpreter needs to know it’s coming by using a \ before the $ To remove a $ and , from a dollar figure, the following ReplaceAll will work. tempText=tempText.replaceAll(“[\$,]”, “”) – The $ must have a single \ in front. The same will be true for other characters like […]

Parsing Strings in Katalon – Split, Substring and Readlines

Once text has been read from the page, it’s time to do something with it. In many cases, only a portion of the text is needed. For example, you may need the first part of a text string, or the last part. An example text string would be: (1/26/2018 – DAY 19 OF 22) The first thing is to read in the entire string into a variable: importDate = WebUI.getText(findTestObject(‘Page_/Sales Dashboard/mtd_Sales_Dashboard_Import_Date’)) Since I want the text to the left of the hyphen, I can use that in my split command. The [0] at the end indicates I want text to the left. If I change it to [1] it would be text to the right. parsedDate = (importDate.split(‘ – ‘)[0]) – returns (1/26/2018 parsedDate = (importDate.split(‘ – ‘)[1]) – returns DAY 19 OF 22) From there I can manipulate the text further for my needs. It’s also possible to break the line at the hyphen and return the resulting two […]

Clicking Buttons, Links and Drop downs in Katalon Studio

Along with entering and reading text, clicking on objects will make up many commands within a script. This includes clicking buttons, links, tabs and drop downs. There are multiple click style objects and several ways to define them. Some involve an XPATH notation, while others use a TAG and HREF notation. For example, to save a Prospect there is an Add button at the bottom of the form. When using the Katalon Recorder, the path to the button is defined as: //div[@id=’newProspects’]/button When defining that button as btn-Add New Prospect, the XPATH Equals //div[@id=’newProspects’]/button. The button can then be clicked using the following command. WebUI.click(findTestObject(‘Page_/Sales Plan Budget/New Prospect/btn-Add New Prospect’)) While most buttons will use an XPATH reference, links on the page may use the TAG and HREF to define them. For the site I’m working on, we have links for By Month, By Customer, By Category and the path looks like link=byCustomer. How does that translate into Katalon? It […]

Entering and reading text GetText, SetText and SendKeys in Katalon Studio

To get started with actual scripting, let’s look at two of the more commonly used functions, getting text from the website and putting text into a field or input box. From the Selenium IDE, these were referred to as storeText and type. StoreText is now GetText and Type is now SetText. There was also the SendKeys command, which is still available in Katalon. Going back to a previous example, here is a small dashboard with sales figures. In this example, I have defined the first cell of the table with the XPATH reference and created an object called Daily Sales Figure Main Dashboard. In order to retrieve that first value and store it in a variable, I can use the following command: dailySalesFigure = WebUI.getText(findTestObject(‘Page_/Sales Dashboard/Daily Sales Figure Main Dashboard’)) The variable dailySalesFigure will take on the value $44,931 and will be defined as a String. Using our Inventory Search field example, I have the following item on the page: […]

Global Variables – How to define your test environment

Before we get too deep into creating scripts I wanted to point out the use of Global Variables since several of the screenshots already reference something called GlobalVariable.baseurl + "/tasks" or something similar. I saw this referenced in several Katalon examples, but the reason for doing it wasn’t clear. If you recall from the Selenium IDE, there was a field where you could enter the base URL of the site. This meant you could run the same tests in QA and Production with just a change to the URL. This accomplishes the same functionality in Katalon Studio. The base URL is set for QA 99% of the time and when you want to run tests in Production, simply change the value of the Global Variable and all tests that reference that variable will use the new site address. In this example, I’m creating a variable called "baseurl". This contains the URL of my site in the QA environment. Click the […]