Use Regular Expressions in Test Automation

Extracting dynamic text is made a lot easier with regular expressions

Zhimin Zhan
5 min readOct 31, 2021

--

This article is included in my “How to in Selenium WebDriver” series.

Regular Expressions are patterns used to match character combinations in strings. To put it simply in the context of test automation, I use regular expressions to find or extract dynamic text in strings. In this article, I will illustrate with a couple of examples.

Regular expression originated in 1951, is widely used in Unix programs. Most programming languages, if not all, have built-in support for Regular expression, a medium-level programmer should be comfortable with it. However, few test engineers I have met knew about Regular Expression.

Let me share a funny story first. After I explained my test scripts to Nick, a newly hired senior tester (in a government project many years ago), Nick said this to me: “Oh, Regular Expression, I know it. It is specific to Ruby.😱 ” This ‘senior automated tester’ claimed had developed over 10,000 IBM RFT automated tests; of course, he did not, as I never saw him writing a single automated test for 6+ months (until I left the project). In fact, he had been sabotaging test automation. I often use this real story to warn companies to be aware of fake test automation engineers.

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.