我已经开始使用赛普拉斯来测试我们的前端内部应用程序(使用Angular5构建),它使用Auth0作为登录身份验证。
我是一名具有 NO 任何编码经验的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并存储响应,这样我就不需要在为应用程序的其余部分运行的每个测试之前运行登录方案,但正如我所说的那样没有编码经验,我发现创建一个函数与创建如上所示的测试有很大不同。 如果有人能提供任何建议/提示/线索,他们都会受到赞赏。
答案 0 :(得分: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')