The Issue

When we need to check that an exact string is found on a page or in the text of an element, we can use the ruby method ‘include?’. This is incorporated with our Watir Webdriver/Selenium scripts, and is commonly used in the last lines of a test script to validate that the script has reached a certain page, or produced a desired output. Lets take a look at an example of how to use ‘include?’.

The Code

We place the include to check if there is any text that is a match for the defined target. If there is a match, we may see an output like this:

The Takeaway

The include? Ruby method is a commonly used, foundational tool that is essential to validation in your test automation. Become comfortable incorporating it into your Watir Webdriver/Selenium scripts, as you’ll soon find out it is used almost everywhere!