Validations in Cypress with Cypress-Xpath Module

Mohamed Yaseen
Nerd For Tech
Published in
3 min readMay 6, 2021

We need to validate that the Login button and the forgot password link are available on the page.

We need to validate that the Login button and the forgot password link are available with the text to init on the page.

Our assertions got passed. So now I’m going to make it that test fail by changing LOGIN to LOGINS in our test. As you can see, it got to the assertion, but it’s waiting 4 seconds just in case something changed. Cypress will wait on validations and look at how nicely the error is. It shows precisely what was wrong and how it failed in beautiful and brief English.

Now we’ll add one more validations to the test. This test will extent by login to the page and validate that Aravind is not checked by default in the Admin module. To do that we need to enable XPath validation to our codebase. Because there are data with the dynamic ids, we need to select a user using by their name but the Cypress doesn’t have the capability to use the XPath. So we need to install the cypress-xpath module to our code by the following command.

npm install -D cypress-xpath

Then include in your project’s cypress/support/index.js

require(‘cypress-xpath’);

So it worked and passed.

--

--

Mohamed Yaseen
Nerd For Tech

Experienced QA Automation Lead with expertise in test automation, frameworks, and tools. Ensures quality software with attention to detail and analytical skills