I know that according to Cypress Best Practices it's recommended to not test 3rd party apps which are not under one's control, but as a a future tester, I'm asserting my authority by doing so anyway!
So I just wanted to test the log in
procedure and POST
response with status 200
for this particular page, so I wrote the following test case here:
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('[email protected]')
.should('have.value', '[email protected]')
/// 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)
})
})
})
The thing is, when executing the automated test above, such page sometimes throws a reCaptcha to solve it, sometimes it doesn't, so I would like to know if there's a way to add an if/else exception for such event where the test just literally waits until that reCaptcha gets solved manually (by me), for then executing the rest of code.
CodePudding user response:
Below
Here comes the human tester that kills the reCaptcha manually IF NEEDED
insert the following:
cy.intercept('POST' , 'https://www.google.com/recaptcha/*').as('googleCaptcha')
cy.wait('@googleCaptcha').its('response.statusCode').should('eq', 200)'