代码之家  ›  专栏  ›  技术社区  ›  NoahVerner

是否可以在Cypress上进行半自动测试,包括手动解决recaptcha?

  •  2
  • NoahVerner  · 技术社区  · 4 年前

    据我所知 Cypress Best Practices 建议不要测试不受个人控制的第三方应用程序,但作为未来的测试人员,我无论如何都在维护自己的权威!

    所以我只是想测试一下 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,然后执行其余的代码。

    1 回复  |  直到 4 年前
        1
  •  1
  •   EugenSunic    4 年前

    在下面

    下面是人工测试人员,如果 需要

    插入以下内容:

    cy.intercept('POST' , 'https://www.google.com/recaptcha/*').as('googleCaptcha') 
    cy.wait('@googleCaptcha').its('response.statusCode').should('eq', 200)'