Using Node.js Assert Library and Custom Assertions
One approach to add pass/fail criteria to Webdriver IO tests is by using the built-in Node.js assert library and creating custom assertions to validate specific conditions. This method allows you to establish criteria that determine whether a test passes or fails based on the state of the web application being tested.
let browserTitle = await browser.getTitle() assert.equal(browserTitle, "\"Hello, World!\" program - Wikipedia")
Here is an example test that uses the above code snippet.
In the code snippet above, we find a heading element. Once we have the heading element, we retrieve its text and use a custom assertion with the Node.js assert library to compare the heading text to the expected value. If the comparison fails, the test will fail, and the specified error message will be displayed.