:::: MENU ::::

Software testing enthusiast.

This article is a part of the Cypress Test series. To read another story in this series, please follow the links below:

Cypress Test Series:





In this article, I will show you how to create a constant that contains an HTML path in Cypress.
How to Save an HTML Path Into a Constant

Sometimes, when creating tests for the front end, we need to access elements under the long HTML path. It will be troublesome if we need to assert elements under the same long path. The workaround I suggest is to save the path into a constant then we call the constant to assert the element.

To achieve the result, we can implement the script below:
describe('Login with Cypress.$ Function', ()=>{
before(function() {
cy.visit('http://zero.webappsecurity.com/login.html');
})

it('should execute login procedure', () => {

const userLogin = cy.get('#user_login')
const userPassword = cy.get('#user_password')
const userRememberMe = cy.get('#user_remember_me')
const signInButton = cy.contains('Sign in')

userLogin.type("username")
userPassword.type("password")
userRememberMe.click()
signInButton.click()
});
})

That script will save the user_login, user_password, user_remember_me, and Sign in button to a constant, then we can call the constant to create an assertion.

0 comments:

Post a Comment

Find this blog interesting? Follow us