How to check if element exists using Cypress.io

I’ll just add that if you decide to do if condition by checking the .length property of cy.find command, you need to respect the asynchronous nature of cypress. Example: Following condition evaluates as false despite appDrawerOpener button exists if (cy.find(“button[data-cy=appDrawerOpener]”).length > 0) //evaluates as false But this one evaluates as true because $body variable is … Read more

Logging into Azure Ad with Cypress

I managed to solve the Azure AD login by creating the following Cypress custom command: Cypress.Commands.add(‘login’, () => { return cy .request({ method: ‘POST’, url: `https://login.microsoftonline.com/${tenantId}/oauth2/token`, form: true, body: { grant_type: ‘password’, tenant: ‘tenantId’, client_id: ‘clientId’, client_secret: ‘clientSecret’, username: ‘username’, password: ‘password’, resource: ‘clientId’, }, }) .then((response) => { sessionStorage.setItem(‘access_token’, response.body.access_token); }); }); Then you … Read more