是否可以在 Cypress 上进行涉及手动解决 recaptcha 的半自动测试?
Is it possible to do a semi-automated test on Cypress that involves solving recaptcha manually?
我知道根据 Cypress Best Practices 建议不要测试不受控制的第 3 方应用程序,但作为未来的测试人员,我这样做是在维护我的权威!
所以我只想测试 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 被手动(由我)解决,然后执行其余代码。
低于
Here comes the human tester that kills the reCaptcha manually IF
NEEDED
插入
cy.intercept('POST' , 'https://www.google.com/recaptcha/*').as('googleCaptcha')
cy.wait('@googleCaptcha').its('response.statusCode').should('eq', 200)
我知道根据 Cypress Best Practices 建议不要测试不受控制的第 3 方应用程序,但作为未来的测试人员,我这样做是在维护我的权威!
所以我只想测试 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 被手动(由我)解决,然后执行其余代码。
低于
Here comes the human tester that kills the reCaptcha manually IF NEEDED
插入
cy.intercept('POST' , 'https://www.google.com/recaptcha/*').as('googleCaptcha')
cy.wait('@googleCaptcha').its('response.statusCode').should('eq', 200)