Setting up a repeatable Search Method in Katalon Studio

Another one of my project goals was to extend functionality within tests by allowing a single task to be repeated multiple times for different criteria. Search is a good example.

In the original incarnation, my search test would look for one item, confirm it was returned and that was the end. Getting a result back was good enough to say the functionality was working. But the actual search function could look for multiple criteria and I was only looking for one. Could that code be extended to be more dynamic without adding a slew of bloat? Yes it can.

For my scenario, I want to search for a item by the state it’s located in, by the city it’s located in, or by it’s numerical code. For example, I can locate Warehouse 13 by searching for it by Arizona, or by AZ or by 13. All 3 criteria can be handled in one method.

The code below gets the job done. First, it will search for the given criteria. It will then read the text of the returned result and determine if the search criteria is contained within that returned text.

As an example, if I search for “Tallahassee”, that word needs to be in the name of the Warehouse.

If I search for AZ, that needs to be listed in the location.

If I search for 333, that number needs to be in the Warehouse description.
Since I am searching for known commodities, if I don’t get my expected result back, something is wrong. There will always be a result for Tallahassee. There will always be a result for 333. And there will always be a result for AZ.

Since I know the outcome, I can pass my search string and my result as parameters to confirm those are the results. Anything else means something is wrong.

This hard coding could be reduced by using a file or sheet, but that’s for another iteration. This still produces 9 more search tests and is easy to manage. If these pass, I’m quite confident the search function is in a working state.

def searchForWarehouse(String warehouseSearchCriteria, String nameOfWarehouse){
    /* Enter a Warehouse and confirm the Warehouse exists
     * @param warehouseSearchCriteria, search criteria of the Warehouse to look for
     * @param nameOfWarehouse, the text that should be returned for Warehouse details
     * @return that the Warehouse was found, otherwise an error
     */
    KeywordLogger log = new KeywordLogger()
    //Enter search criteria
    WebUI.setText(findTestObject('Project/Search Warehouse/input-Search Warehouse'), warehouseSearchCriteria)
    WebUI.delay(2)
    //Confirm there are results
    int returnedResults=WebUI.getText(findTestObject('Project/Search Warehouse/text-Warehouse Search - Results Found')).replaceAll("[^0-9]","").toInteger()
    if (returnedResults==0) {
        log.logWarning('ERROR: No results were returned. No Warehouse matches the search criteria.')
        log.logWarning('ERROR: The Warehouse ' + warehouseSearchCriteria + ' is not valid')
    } else {
    //Does the Warehouse result contain the expected criteria?
        String WarehouseName=WebUI.getText(findTestObject('Project/Search Warehouse/link-Name of Returned Warehouse'))
        log.logWarning('Warehouse Name= ' + WarehouseName)
        if (WarehouseName.contains(nameOfWarehouse)==true){
            log.logWarning('SUCCESS: The expected Warehouse Name was returned')
        } else {
            log.logError('ERROR: The expected Warehouse Name was not returned')
            KeywordUtil.markFailed('ERROR: The expected Warehouse Name was not returned')
        }
    }
}


//Look for several Warehouse locations and verify results are returned
//Search by City Name
searchForWarehouse('ukiah', 'Project Warehouse #111 UKIAH, CA')
searchForWarehouse('tallahassee', 'Project Warehouse #222 TALLAHASSEE, FL')
searchForWarehouse('worcester', 'Project Warehouse #333 WORCESTER, MA')

//Search by Warehouse Number
searchForWarehouse('646', 'Project Warehouse #646 W MILWAUKEE, WI')
searchForWarehouse('997','Project Warehouse #997 BILOXI, MS')
searchForWarehouse('999','This Warehouse does not exist')

//Search by State
searchForWarehouse('NY','NY')
searchForWarehouse('AZ','AZ')
searchForWarehouse('TX','TX')

searchForWarehouse on Github

Other articles of interest:

One Response to Setting up a repeatable Search Method in Katalon Studio

Leave a Reply

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

Recent Comments
  • Parsing Strings in Katalon – Split, Substring and Readlines (4)
    • Anjana: Hey thanks for the response It is quite strange but initializing variable for delimiter and it worked String splitFormat = ‘-‘ WebUI.println(var_CampaignDura tion.toString().split(splitFor mat)[0])...
    • Don Pedro: I’m not really sure what the difference is, but I don’t think the “-“ in the split is the same as the one in the date. String var_CampaignDuration = “05/13/2019-06/07/2019&# 8221; String[] parsedDateRange =...
    • Anjana: Hi, I tried the same thing to split the string, but does not work for me, Could you plz point out whats wrong Variable var_CampaignDuration has value “05/13/2019-06/07/2019&# 8221; String[] parsedDateRange =...
    • Ellen: Thanks for sharing!! I like your contributions to Katalon topics.
  • How to Block games by Title and Tag on Steam (2)
    • Marcus861: I made an acc just to say: Same bro
    • JACK: Thanks, same just wanted to block anime games in my discover
  • Create a new and random UUID for an API call (1)
    • Anonymous: Hi ! I found this blog few weeks ago and it’s really helping me out with my tests! Thanks a lot for the Katalon tips and tricks ! Keep up the good work 🙂
  • How To Disable the Quicken Registration Prompt (25)
    • Greg: For me, holding the *LEFT* CTL + Shift then clicking Online, One Step Update worked. I originally tried holding the right CTL + Shift, and it didn’t work. I’m using Quicken 2006, so I don’t know if it will work...
    • Joe SR>: My monthly income is deposited into my Credit Union account. I use debit whenever possible. I write checks manually and mail them. I use Quicken 2012 off-line only. I have entered all my money and investment accounts. I...
    • Prtet: Never say never….every time I swear I will never use Quicken again, I discover that there are still no viable alternatives. Amazing that there is no decent personal finance software.
    • Joe D.: Holding CTRL + Shift keys and selecting On Line | One Step Update from the main menu worked for my Quicken 2004. I’m grateful that you wrote a synopsis (“Simply put, …”) just beneath the link to the blog...
    • Susan Long: I bought my quicken disc in the beginning and it came with a registration number. I rang the helpline and they gave me the code to put in and talked me through it. It you downloaded your version then you don’t own it...
    • Peter: You might consider running your old version of Quicken on an ancient computer. This is what I have done for years. The newer versions are fraught with problems- criminal, in my opinion. One version made mathmatical errors when...
  • Working with Dates and Date Formatting in Katalon Studio (6)
    • Ajoo: Thank you for the details. How do i remove leading “0” from dates. i.e. while formatting i receive 04/21/2019, but i need 4/21/2019. (same applies for date)
  • What is Katalon Studio? A Distro of Selenium, Groovy and Eclipse (1)
    • Mahesh: Looking for more posts on katalon studio.your katalon stuffs are always exiting