我知道,根据Cypress Best Practices,建议不要测试不受个人控制的第三方应用程序,但作为future 的测试人员,我无论如何都在维护自己的权威!
所以我只想测试log in
过程和POST
响应,状态200
为this particular page,所以我在这里编写了以下测试用例:
describe('Log in and Log out Tests', () => {
it('Log in Test', () => {
/// Go to 'https://bandcamp.com/'
cy.visit('https://bandcamp.com/')
/// Get the 'log in' element and click it
cy.get("[class='log-in-link']").click()
/// Assert the log in page is 'https://bandcamp.com/login'
cy.url().should('include', '/login')
/// Set up the API variable, in this case the url was '**/login_cb'
cy.intercept('POST', '**/login_cb').as('POSTresponse')
/// Get the 'Username/email' textbox and type the email then verifies such textbox contains the previous
cy.get('[name="username-field"]').type('xxxx@outlook.com')
.should('have.value', 'xxxx@outlook.com')
/// Get the 'Password' textbox and type the password
cy.get('[name="password-field"]').type('xyz')
.should('have.value', 'xyz')
/// Click the 'Log in' button
cy.get('#loginform > div.buttons > button').click()
/// Here comes the human tester that kills the reCaptcha manually IF NEEDED ///
/// Now wait for the POSTresponse variable
cy.wait('@POSTresponse')
/// Print the value of POSTresponse variable as a JQuery object
cy.get('@POSTresponse').then( XHR => {
console.log(XHR)
// Check that the status code is equal to 200 (success)
expect(XHR.response.statusCode).to.equal(200)
})
})
})
问题是,当执行上面的自动测试时,这样的页面有时会抛出一个reCaptcha来解决它,有时不会,所以我想知道是否有方法为这样的事件添加一个if/else异常,测试只是直接等待,直到手动(由我)解决该reCaptcha,然后执行其余的代码.