Skip to main content

Quality Assurance

Understanding Java Enum ConditionType in Katalon Studio. Pt2

Business Man Using Computer Hand Close Up Futuristic Cyber Space And Decentralized Finance Coding Background, Business Data Analytics Programming Online Network Metaverse Digital World Technology

Introduction

In this follow-up blog, we will explore the remaining condition types available in the ConditionType enum. Understanding these additional condition types will further enhance your ability to create robust and flexible test automation scripts in Katalon Studio. Each condition type serves a unique purpose in defining criteria for identifying and interacting with web elements, ensuring the reliability and accuracy of your automated tests.

 

ConditionType Overview

MATCHES_REGEX

The MATCHES_REGEX condition type checks if a web element’s attribute or text content matches a specific regular expression pattern. This is similar to the EXPRESSION condition type but allows you to use a pre-defined regular expression instead of creating a custom expression.

Example: To check if a text input field’s value matches a phone number format, you can use the MATCHES_REGEX condition type:

TestObject phoneField = new TestObject("phoneInput");

phoneField.addProperty("value", ConditionType.MATCHES_REGEX, "^\\d{3}-\\d{3}-\\d{4}$");

 

In this example, Katalon Studio will verify if the phone input field’s value matches the pattern XXX-XXX-XXXX.

 

NOT_CONTAIN

The NOT_CONTAIN condition type is the opposite of the CONTAINS condition type. It checks if a web element’s attribute or text content does not contain a specific value.

Example: To ensure that a button’s text does not contain the word “Cancel”, use the NOT_CONTAIN condition type:

TestObject button = new TestObject("submitButton");

button.addProperty("text", ConditionType.NOT_CONTAIN, "Cancel");

 

Here, Katalon Studio will identify buttons whose text does not include the word “Cancel”.

 

NOT_EQUAL

The NOT_EQUAL condition type is the opposite of the EQUALS condition type. It checks if a web element’s attribute or text content does not exactly match a specific value.

Example: To verify that a text input field’s value is not “John Doe”, use the NOT_EQUAL condition type:

TestObject nameField = new TestObject("nameInput");

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

 

In this scenario, Katalon Studio will ensure that the input field’s value is not “John Doe”.

 

NOT_MATCH_REGEX

The NOT_MATCH_REGEX condition type is the opposite of the MATCHES_REGEX condition type. It checks if a web element’s attribute or text content does not match a specific regular expression pattern.

Example: To ensure that a text input field’s value does not match a phone number format, use the NOT_MATCH_REGEX condition type:

TestObject phoneField = new TestObject("phoneInput");

phoneField.addProperty("value", ConditionType.NOT_MATCH_REGEX, "^\\d{3}-\\d{3}-\\d{4}$");

 

Here, Katalon Studio will verify that the phone input field’s value does not match the pattern XXX-XXX-XXXX.

 

STARTS_WITH

The STARTS_WITH condition type checks if a web element’s attribute or text content starts with a specific value. This can be useful for verifying that an element’s content has a specific prefix.

Example: To check if a link’s URL starts with “https://”, use the STARTS_WITH condition type:

TestObject link = new TestObject("websiteLink");

link.addProperty("href", ConditionType.STARTS_WITH, "https://");

 

In this example, Katalon Studio will identify link elements whose href attribute starts with “https://”.

 

Practical Examples

Let’s explore some comprehensive practical examples that demonstrate how to use these condition types in real-world scenarios.

Scenario 1: Validate Phone Number Format

You need to verify that a phone number input field matches the format XXX-XXX-XXXX.

TestObject phoneField = new TestObject("phoneInput");

phoneField.addProperty("value", ConditionType.MATCHES_REGEX, "^\\d{3}-\\d{3}-\\d{4}$");

WebUI.verifyElementPresent(phoneField, 10);

 

Scenario 2: Ensure Button Text Excludes Specific Word

To ensure that a button’s text does not contain the word “Cancel”, use the NOT_CONTAIN condition type.

TestObject button = new TestObject("submitButton");

button.addProperty("text", ConditionType.NOT_CONTAIN, "Cancel");

WebUI.verifyElementPresent(button, 10);

 

Scenario 3: Verify Non-Matching Input Value

To check that a text input field’s value is not “John Doe”, use the NOT_EQUAL condition type.

TestObject nameField = new TestObject("nameInput");

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

WebUI.verifyElementPresent(nameField, 10);

 

Scenario 4: Validate Non-Matching Pattern

Ensure that a text input field’s value does not match a specific phone number pattern.

TestObject phoneField = new TestObject("phoneInput");

phoneField.addProperty("value", ConditionType.NOT_MATCH_REGEX, "^\\d{3}-\\d{3}-\\d{4}$");

WebUI.verifyElementPresent(phoneField, 10);

 

Scenario 5: Check URL Prefix

To verify that a link’s URL starts with “https://”, use the STARTS_WITH condition type.

TestObject link = new TestObject("websiteLink");

link.addProperty("href", ConditionType.STARTS_WITH, "https://");

WebUI.verifyElementPresent(link, 10);

 

Best Practices

To maximize the effectiveness of the ConditionType enum in Katalon Studio, follow these best practices:

  • Clear Naming: Name your TestObject instances descriptively 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 Tests: Provide comments and documentation for complex condition types to aid future maintenance.

 

Conclusion

The additional ConditionType options in Katalon Studio provide even more flexibility and precision in defining criteria for identifying and interacting with web elements. By understanding and effectively utilizing these condition types, you can create more robust and reliable 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