A Custom Keyword to Verify a List of Product Categories

We recently implemented a change to the site that displays a different list of product categories based on the division a user is associated with. For example, if a User1 is associated with Division1, they see List1. User2 in Division 2 sees List2. User1 can’t see List 2 and vice versa. Since it’s important this list is correct for the user, it seemed a worthwhile to set it up as a test.

While putting the code together, I noted a couple of things:

– The table name may be different, but the list is always in a table
– The list is always 10 items
– The product names are always in the same order
– The list appears in 5 different places

Based on that, I decided to set up the code as a Custom Keyword so I could check the list regardless of where it showed up. Once the test was on the right page, a single call would check the list and then proceed with other tasks.

The basic structure of the Keyword needed the following:

– Read the list of products from a List
– Determine what division the user is in
– Compare the “division list” to the list read from the page
– Mark the test in error if the list doesn’t match

In order to make this Keyword as dynamic as possible, the object name would be passed as a String. The division the user is in would also be passed as a String.

The Keyword would then determine the correct list, read the 10 items from the table it was passed, then compare the two categories.

For the code below, two parameters are accepted,  the division the user is associated with and the Object Repository name.

Two lists are created representing the ‘Categories’ the user should see.

A blank ‘categoryList’ is created that will take on the category values of the users division.

A loop is created to read the category from the table using the name of the Object Repository item, which has Row and Column as parameters set up since it’s a table.

If the first row of the table equals the first item in the List, the next item is read and compared.

If row and List item don’t match, write out an error. The test could also be marked as Failed.

Within the Test Case itself, a variable is assigned the name of the Object Repository item using:

String katalonObject="productCategoryTableName"

The Keyword is called by the following command where the Division is the first parameter and the OR Object is the second.

verifyProductCategory('List1', katalonObject)

def verifyProductCategory(String divisionName, objectName){
    /* Confirm the category is correct for the user division
     * @param divisionName - The division to check, should be List1 or List2
     * @return - does not return a value
     */
    KeywordLogger log = new KeywordLogger()
    List division1Categories=['','Pink Hearts', 'Yellow Moon', 'Orange Stars', 'Green Clovers', 'Blue Diamonds', 'Purple Horseshoes', 'Red Balloons', 'Green Trees', 'Rainbows', 'Blue Moons']
    List division2Categories=['','One Fish', 'Two Fish', 'Red Fish', 'Blue Fish', 'Black Fish', 'Clever Fish', 'Old Fish', New Fish', 'Green Eggs and Ham', 'Fox in Sox', 
    List categoryList=[]
    if (divisionName=='List1'){
        categoryList=division1Categories
    } else {
        categoryList=division2Categories
    }
    for (int loop = 1; loop <=10; loop++) {
        String tempText=WebUI.getText(findTestObject(objectName, [('row') : loop, ('column') : 1]))
        if (tempText!=categoryList[loop]){
            log.logError('ERROR: Category is incorrect. The category should be ' + categoryList[loop])
        }
        log.logWarning('Category: ' + tempText)
    }
}

verifyProductCategory on Github

  • It should also be noted that both Lists start with a null,”, so that the row number and List item number will match. This makes row[1] equal List[1]

Other articles of interest:

Leave a Reply

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

Recent Comments
  • Custom Keywords for Custom Functions (1)
    • Sarah: Thank you for this. It helped me understand these better.
  • How To Disable the Quicken Registration Prompt (26)
    • Denise Defoor: I have a Quicken SE Version 6 .. My computer crashed a few weeks ago and I finally got it up and running. Now Quicken is telling me I must registered it. What? I have had this program for 20 years. How can I disable the...
    • 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...
  • 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 🙂
  • 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)