End-to-End Testing with Cypress and Auth0

Cross-origin support is finally released which should resolve all remaining problems in this space:

Here’s an example implementation for an Auth0 site that uses identifier-first login & automatically redirects on load:

Cypress.Commands.add('loginAsUser', (email, password) => {
    const args = { email, password }
    cy.session(
        args,
        () => {
            // visit homepage
            cy.visit('/')
            // redirects to Auth0
            cy.origin('/**YOUR AUTH0 DOMAIN HERE**/', { args }, ({ email, password }) => {
                cy.get('#username').type(email)
                cy.get('button').contains(/^Continue$/).click();
                cy.get('#password').type(password)
                cy.get('button').contains('Continue').click();
            })
            // assert we've returned to the site
            cy.url().should('contain', '/home')
        }
    )
})

Very simple!

2 Likes