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

所以我只想测试log in过程和POST响应,状态200this 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,然后执行其余的代码.

推荐答案

在下面

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

插入以下内容:

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

Javascript相关问答推荐

以逗号分隔的列表来数组并填充收件箱列表

为什么子组件没有在reaction中渲染?

用相器进行向内碰撞检测

有Angular 的material .未应用收件箱中的价值变化

确定MutationRecord中removedNodes的索引

将json数组项转换为js中的扁平

单击更新页面的按钮后,页面刷新;测试/断言超时,有两个标题,但没有一个标题

点击按钮一次有文本出现和褪色,而不是点击两次?(html,CSS,JavaScript)

setcallback是什么时候放到macrotask队列上的?

无法读取未定义错误的属性路径名''

如何使用子字符串在数组中搜索重复项

变量的值在Reaction组件中的Try-Catch语句之外丢失

如何在coCos2d-x中更正此错误

提交链接到AJAX数据结果的表单

环境值在.js文件/Next.js中不起作用

400 bad request error posting through node-fetch

在使用REACT更改了CSS类之后,无法更改CSS样式

如何在FastAPI中为通过file:/URL加载的本地HTML文件启用CORS?

如何修复使用axios运行TSC index.ts时出现的错误?

使用Reaction窗体挂钩注册日历组件