Conquer the pain and drama of testing Salesforce releases | Learn how

How to Use Regular Expressions (RegEx) in Testim

When working with dynamic web applications, testers often encounter elements whose values change frequently—sometimes with every page load. These changes…

Use Regular Expressions
By Testim,

When working with dynamic web applications, testers often encounter elements whose values change frequently—sometimes with every page load. These changes can make it difficult to validate content using static values in automated tests. Fortunately, Testim provides a powerful solution: the ability to use regular expressions (RegEx) for flexible and intelligent validations.

RegEx allows you to define patterns that match a range of possible values, making it ideal for scenarios where only part of a string remains constant. This is especially useful when validating labels or text that include dynamic data, such as prices, dates, or user-generated content.

Example: Validating a Dynamic Price Label

Imagine you’re testing a travel booking application. On the confirmation page, you see a label like “Price: $1,250.00.” The numeric value will vary depending on the itinerary, time of booking, and other factors. If you hardcode the full string into your test, it will likely fail the next time the price changes.

Instead, you can use a RegEx pattern like /^Price/ in the Expected Value field of the test step within Testim. This pattern checks whether the text starts with the word “Price,” regardless of what follows. As long as the label begins with “Price,” the test will pass—even if the actual price value changes. This approach ensures your tests remain stable and relevant, even as the data evolves.

Why Use RegEx in Test Automation?

  • Flexibility: Match patterns instead of exact strings.
  • Resilience: Reduce test failures caused by minor, expected changes.
  • Efficiency: Avoid constant test maintenance due to dynamic content.

Common RegEx Patterns

  • ^ – Matches the beginning of a string.
  • $ – Matches the end of a string.
  • . – Matches any single character.
  • * – Matches zero or more of the preceding element.
  • \d – Matches any digit.

Learn More

For more examples and guidance on using RegEx in Testim, check out the resources below:

📘 https://docs.testim.io

Let me know if you’d like help applying RegEx to a specific test case!

 
 
 

https://help.testim.io/docs/validate-element-text

https://www.w3schools.com/jsref/jsref_obj_regexp.asp

https://regexone.com/