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 strings into a List.

String[] parsedDate = importDate.split(‘ – ‘)

Since it is now a list, it can be referenced by index:

importDate = parsedDate[0] Рsets importDate to the text  (1/26/2018

businessDays = parsedDate[1] – set businessDays to the text DAY 19 OF 22)

The above commands accomplish the same thing, the the first uses a single variable, the second uses a List.

The List comes in handy for something like an address. If the address is Charlotte, NC 28203, the address can be split at the comma.

String[] splitAddress=branchAddress.split(‘, ‘)

splitAddress[0] – set to Charlotte

splitAddress[1] – set to NC 28203

Instead of splitting a string at a predetermined character, you may need to split the string after a certain number of characters. For example, Branches are listed as:

Branch #123 – Charlotte, NC

Branch #140 – Huntersville, NC

Branch #005 – Rock Hill, SC

For this example, I need the Branch number. Since the first part of the string is always the same, the Substring command can be used to retrieve X number of characters. Substring starts at position 0.

branchName=tempBranchName.substring(0,11) – Returns 11 characters – Branch #005

If I only wanted the number of the branch, I would start at position 7, the space after branch and read to position 11, the end of number.

branchName=tempBranchName.substring(7,11) – Returns – #005

The .readlines() command performs parsing on multiple lines worth of text from a cell and breaks them into individual lines. An address in a textbox would be a use of .readlines()

For example, the full text would be:

1313 Mockingbird Ln

Charlotte NC, 28203

Since all of that comes in as one block of text, it needs to be parsed into lines. Once the text has been set to a variable using the GetText command, the following commands can parse through it.

branchAddress=WebUI.getText(findTestObject(‘Page_/Search Branch/Branch Profile Address’))

//Get the Branch Profile Address from the return results and parse it into multiple lines

//The address will be compared to the address from the Search Results page

branchProfileAddress = branchAddress.readLines() – Is a list consisting of the two lines of the address

branchProfileStreetAddress=branchProfileAddress[0] – Returns 1313 Mockingbird Ln

branchProfileCityState=branchProfileAddress[1] – Charlotte NC, 28203

Other articles of interest:

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments
  • 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:...
  • How To Disable the Quicken Registration Prompt (16)
    • Dave: Works for Quicken 2007 too. Thanks, Gina!
    • Charlie Fellenbaum: Yay, thanks, and that worked for Quicken 2006 as well.
    • Ken: This didn’t work for me. I have 2006. I installed on a new laptop. I must have registered before, don’t remember. I tried to register this time, but got an error message. I’d rather not registered, though. I use...
    • Neil Murphy: I discovered that early on. I’m using 2001.
    • Jeremy: Thank you so so so much. I am still using Quicken 2010 because Intuit didn’t want to properly support users abroad anymore (never mind that they only link to US banks for transaction downloads; they didn’t want my...
  • Quasi Performance/Load Testing with Katalon Studio (1)
    • Anthony: I have done this with 100 plus machines at the same time and it worked well and provided some useful feedback.
  • A Try Catch example in Katalon Studio (3)
    • Venkatesh: Hi Don Pedro Can you share me sample project ….which consist of basic to advanced stuff…If your github or gitlab url aso present please share… As I am beginer to this I need to learn lot
    • Don Pedro: Hi Lucas. Thank you for the kind comments. I would be happy to help. Let me know how I could be of assistance.
    • Lucas: Thanks for sharing a lot of Katalon tips and tricks. The Katalon team highly appreciate your support and feedback. To make Katalon Studio better and be the best free automation solution for testing community, we wish to coordinate...
  • Securely storing passwords and login details with Set Encrypted Text in Katalon Studio (1)
    • Agus: Hi Don, Is there a way to set the encrypted text to be used in the ‘WebUI.authenticate̵ 7; method? Basically I am trying to encrypt the password that is passed to the ‘WebUI.authenticate̵ 7; method. Thank you.
  • Katalon Studio – Manual View – The start of a test script (2)
    • ben: Hello Don Great Website. Keep up the work. I learnt a lot. cheers Ben.
    • Lucas: Hi Don Pedro, Thanks for sharing a lot of great articles related to Katalon Studio and Selenium. I am Lucas from Katalon team. From your point of view, we’ve learnt alot to improve our product and add more valuable features...
  • Another success with Katalon Studio (1)
    • Mahesh Joshi: Hi Don, I just started following your blog in regards to katalon. I want to introduce katalon studio at my work we do manual testing at work at the moment. What approach I should use for proof of concept with katalon for...
  • What went wrong with Crime City? (34)
    • G D: One thing I have noticed is the awkwardness of items and the attack points and how you can earn them. I was pretty pathetic with attack points and then I played that limited time boss and got weapons that had attack points in the...