首页 文章

赛普拉斯测试场景登录Via Auth0

提问于
浏览
0

我已经开始使用赛普拉斯测试我们的前端内部应用程序(使用Angular5构建),它使用Auth0作为登录验证 .

我是一名具有任何编码经验的QA,所以当我设法让一些测试工作(并通过)时,我感到非常高兴 .

但是我遇到了绊脚石 . 即使我可以使用赛普拉斯来测试Auth0登录是否有效;当登录成功时,它不会在测试中打开应用程序,就像我手动测试一样 .

以下是我运行Auth0身份验证测试的测试 .

describe('My Login Test', function (){
    it('Visit Risk App Landing Page', function (){
        const typedText = 'user-email-address'
        cy.visit('http://localhost:3000/workflow')
        cy.get('button').click()
        cy.get('input.auth0-lock-input').first()
        .type(typedText)
        .should('have.value', typedText)
        cy.get('button').click()
        cy.url().should('eq','http://localhost:3000/workflow')
    })
})

我也在尝试创建一个函数,我可以调用Auth0并存储响应,这样我就不必在为应用程序的其余部分运行的每个测试之前运行登录方案,但正如我所说,我没有编码经验我发现创建一个函数与创建如上所示的测试有很大不同 . 如果有人可以提供任何建议/提示/线索,他们将不胜感激 .

1 回答

  • 0

    你的第一个问题无法帮到你 . 但至于提取重新使用的登录代码,您可以创建一个cypress命令https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax

    Cypress.Commands.add('login', (email, password) => {
            cy.visit('http://localhost:3000/workflow')
            cy.get('button').click()
            cy.get('input.auth0-lock-input').first()
            .type(email)
            cy.get('button').click()
            cy.url().should('eq','http://localhost:3000/workflow')
    })
    

    然后从测试中你可以称之为:

    cy.login('some-email', 'somepassword')
    

相关问题