Skip to main content

Quality Assurance

Understanding Java Enum ConditionType in Katalon Studio. Pt1

Istock 1403897241

Introduction

Katalon Studio’s ConditionType enum is a key feature that allows testers to define specific criteria for interacting with web elements. This flexibility is crucial for creating robust and reliable automated tests. The ConditionType enum provides a variety of condition types, each serving a unique purpose in the identification and interaction with web elements.

We’ll understand various condition types available in the ConditionType enum, illustrating their usage with practical examples. By the end of this post, you’ll have understanding of how to leverage these condition types to enhance your Katalon Studio projects.

 

ConditionType Overview

CONTAINS

The CONTAINS condition type checks if a web element’s attribute or text content includes a specific value. This is particularly useful for verifying that a certain string or substring exists within the element’s content.

TestObject button = new TestObject("submitButton");

button.addProperty("xpath", ConditionType.CONTAINS, "//button[contains(text(), 'Submit')]");

 

Example: Suppose you want to check if a button’s text contains the word “Submit”. You can use the CONTAINS condition type as follows:

In this example, Katalon Studio will look for a button element whose text contains the word “Submit”.

 

ENDS_WITH

The ENDS_WITH condition type is used to verify if a web element’s attribute or text content ends with a particular value. This is useful for checking specific suffixes in an element’s content.

Example: To check if a link’s URL ends with a .pdf extension, you can use the ENDS_WITH condition type:

TestObject link = new TestObject("pdfLink");

link.addProperty("href", ConditionType.ENDS_WITH, ".pdf");

 

Here, Katalon Studio will identify link elements whose href attribute ends with .pdf.

 

EQUALS

The EQUALS condition type is employed to verify if a web element’s attribute or text content exactly matches a specific value. This is useful for precise match comparisons.

Example: To check if a text input field’s value is exactly “John Doe”, use the EQUALS condition type:

TestObject nameField = new TestObject("nameInput");

nameField.addProperty("value", ConditionType.EQUALS, "John Doe");

 

In this scenario, Katalon Studio will search for an input field whose value attribute is exactly “John Doe”.

EXPRESSION

The EXPRESSION condition type allows for the use of custom expressions to define the matching criteria for a web element. This is a powerful feature for creating more complex and specific conditions.

Example: To check if a table cell’s value is a valid email address, you can use the EXPRESSION condition type with a regular expression:

TestObject emailCell = new TestObject("emailTableCell");

emailCell.addProperty("text", ConditionType.EXPRESSION, "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");

 

In this example, Katalon Studio will look for table cells whose text matches the given email address pattern.

 

Practical Examples

To solidify your understanding, let’s explore more comprehensive practical examples that demonstrate how to use these condition types in real-world scenarios.

 

Scenario 1: Verify Login Button Presence

Suppose you’re testing a login page and need to verify the presence of a login button that contains the text “Login”.

TestObject loginButton = new TestObject("loginButton");

loginButton.addProperty("xpath", ConditionType.CONTAINS, "//button[contains(text(), 'Login')]");

WebUI.verifyElementPresent(loginButton, 10);

 

Scenario 2: Check File Download Link

You need to verify that a download link for a PDF file is correctly displayed on a page.

TestObject pdfDownloadLink = new TestObject("pdfDownloadLink");

pdfDownloadLink.addProperty("href", ConditionType.ENDS_WITH, ".pdf");

WebUI.verifyElementPresent(pdfDownloadLink, 10);

 

Best Practices

To make the most of the ConditionType enum in Katalon Studio, consider the following best practices:

  • Use Descriptive Names: Name your TestObject instances clearly to reflect their purpose.
  • Combine Conditions: Use multiple properties and condition types to refine element identification.
  • Validate Regularly: Regularly validate your tests to ensure condition types are correctly implemented.
  • Optimize Performance: Avoid overly complex expressions that might impact test execution performance.
  • Document Your Tests: Provide comments and documentation for complex condition types to aid future maintenance.

 

Conclusion

The ConditionType enum in Katalon Studio provides a versatile set of predefined condition types that significantly enhance your ability to define criteria for identifying and interacting with web elements. By understanding and effectively utilizing these condition types, you can create more robust and flexible automated tests.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sanket Dudhe

Sanket Dudhe is a Technical Consultant at Perficient. He has an experience of 4+ years as SDET. He loves technology and hence is curious to learn about new emerging technologies #lovefortechnology.

More from this Author

Categories
Follow Us