Table of contents
1.
Introduction
2.
Parameterized Mobile test object properties
2.1.
To parameterize test objects in Mobile testing
2.2.
Escaping special characters
2.3.
Image-based Testing
3.
Set-Up
3.1.
macOS
3.2.
Linux
4.
Capture Images
5.
Capture Tool and Storage
6.
Frequently Asked Questions
6.1.
What are dynamic objects?
6.2.
How does Image-Based Testing happen in Katalon Studio?
6.3.
What is the acceptance threshold to define the possible outcome of image comparison in Katalon?
7.
Conclusion
Last Updated: Mar 27, 2024

Create, Parameterize, and test the test cases in Katalon studio

Author Anmol Punetha
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
OG Image

Introduction

By parameterizing the test objects, we can dynamically update the test objects’ locators by using either global or local variables. Katalon Studio aids in parameterizing the properties of test objects to handle dynamic things.

Katalon Studio furnishes an image locator method to identify Test Objects with images. Image-based testing for Mobile in Katalon Studio depends on Appium's finding image objects.

Parameterized Mobile test object properties

The advantage of parameterizing mobile test objects is similar to that of web test objects.

To parameterize test objects in Mobile testing

  • Open a sample project of testing on Android devices by 
    • going to File
    • New Sample Project 
    • Sample Android Mobile Tests Project
       
  • Then go to Object Repository/Application/android.widget.TextView -App in the test explorer 
     
  • Open the test object view of the android.widget.TextView - App whose properties will be parametrized. 

 

In this article, we are going to use the example where we find out an object that has “ [(text() = 'demokatalon' or . = 'demokatalon')] ” as its selector. The steps to apply this feature are as follows:

  1. Parameterizing the test object’s dynamic property.
     
  2. Create a property whose value is a variable with the following syntax: ${Variable_name}. For our example, in the Object's Properties panel, we add an object's property with:
    • Name: text
    • Value: ${text}
    • The selector locator is generated as follows:
    • //*[(text() = '${text}' or . = '${text}')]
    • And gets identified at runtime by passing data.

 

Object Properties katalon

Source: Katalon

3. Using the parameterized test object in a test case

In Manual view

Inside the Verify Correct Alarm Message test case, double-click on the test object that contains the parameterized property i.e., android.widget.TextView - App. 

In the variables panel, we add new variables with the following properties:

  • Param Type: Type of the variable (Default type being a string)
  • Param: The variable name was given to the property created in step 1.
  • Value Type: It is the type of the variable’s value.
  • Value: A particular value to the variable.
Test object input screenshot

Source: Katalon

In Script View

We also can switch to the Scripting Mode of the ongoing Test Case to adjust the property's value at any time. The determining variable is automatically mapped when we select a mobile object from the manual mode and hence doesn’t need to be defined again manually.

Call the findTestObject method within a keyword:

In our example, the tap keyword is performed on our test object with the text value as the one that we have just specified.

Escaping special characters

To be able to use special characters like ‘ \ ’or  $ as normal characters in any place that is using parameterized test objects, we prepend it with a backslash ( \ ) or escape character.

Example:

{
   "productName": ${GlobalVariable.productName},
   "unit": "\\bottle\",
   "quantity": 50,
   "discount": ${ if (productName == "wine") { return 30 } else { return 0}}
   "note": "Currency unit of ${GlobalVariable.productName} is \$."
}

 

Without ‘ \ ' Currency unit of ${GlobalVariable.productName} is $.

With ‘ \ ’ Currency unit of wine is $.

Image-based Testing

Commencing with version 7.2, image-based testing has been available for Katalon Studio enterprise users.

Image-based testing allows us to interact with Mobile objects and locate them by their images. It is especially helpful in the following use cases:

  • Objects in a canvas of a 2D or 3D game.
  • Dynamic test objects with no unique selectors.

 

Image-based testing for Mobile in Katalon Studio depends on Appium's finding image objects. Katalon Studio will automatically encode images to Base64 for reference during test execution. 

Set-Up

Windows:

  1. Download and install CMake.
  2. Once installed, add the CMake folder to PATH in Environment variables.

SetUp path variable windows

Source: Katalon

 

3. Run the below commands:

npm install -g appium
npm install -g windows-build-tools
npm install -g opencv4nodejs

macOS

  1. Download and install CMake.
  2. Run the below commands:
brew update
brew install cmake
npm install -g appium
npm install -g opencv4nodejs

Linux

  1. Download and install CMake.
  2. Once installed, add the CMake folder to PATH in Environment variables.
  3. Run the below commands:
npm install -g appium
npm install -g opencv4nodejs

Capture Images

The steps to capture an image of the desired Mobile elements for interaction during test executions:

  1. Initialize your AUT with Mobile Spy/Recorder. Have the mobile device connected to Katalon Studio.
  2. Capture an image of the screen by clicking on Capture Object.
  3. Crop the recognition area from the screenshot that the Katalon Studio will use for searching similar elements during the test execution.

Capture Tool and Storage

It is suggested to take a screenshot by Appium Driver in Mobile Spy/Recorder, as those screenshots automatically resize. The image's size and resolution significantly affect the visual element comparison.

To find the captured screenshots:

In Windows: Katalon Studio\config\screenshot.

In macOS: /Applications/Katalon Studio.app/Contents/MacOS/screenshot/

Frequently Asked Questions

What are dynamic objects?

Dynamic objects are those objects that have some specific changes in their properties based on specific business rules. To handle such dynamic objects, Katalon Studio provides Parameterizing Test Object properties. 

How does Image-Based Testing happen in Katalon Studio?

Katalon Studio encodes images to Base64 for referencing during test execution.  The reference images will then be used for searching the most matching area of the screen, which implies that the key to successfully finding visual elements is capturing reference images.

What is the acceptance threshold to define the possible outcome of image comparison in Katalon?

The acceptance threshold defined by Katalon Studio for image comparison is set at 0.4 by default, implying that any image with a similarity measure less than 0.4 will get rejected. We can customize the acceptance threshold. 

Conclusion

So, with this, we saw how to create, parameterize and test the test cases in Katalon Studio. I hope that the blog was informative.

See Basics of C++ with Data StructureDBMS, and Operating System by Coding Ninjas, and keep practicing on our platform Coding Ninjas Studio.

If you think you are ready for the tech giants company, check out the mock test series on code studio.

You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and AlgorithmsCompetitive ProgrammingAptitude, and many more! You can also prepare for tech giants companies like Amazon, Microsoft, Uber, etc., by looking for the questions asked by them in recent interviews. If you want to prepare for placements, refer to the interview bundle. If you are nervous about your interviews, you can see interview experiences to get ideas about these companies' questions.

Nevertheless, you may consider our premium courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Thank you image

Live masterclass