在赛普拉斯中,有没有一种方法可以根据每日消息来避免故障? [英] In Cypress, is there a way to avoid a failure depending on a daily message?

查看:57
本文介绍了在赛普拉斯中,有没有一种方法可以根据每日消息来避免故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用赛普拉斯开发一种测试工具,用于当前处于活动状态的网页。问题是有时我会得到一个模态,显示新功能,事件等。

I'm developing a testing tool using Cypress for a webpage that is currently live. The problem is that sometimes I get a modal showing the new features, events, etc.; and this breaks the remaining tests.

我已经尝试在登录后立即关闭模式(这是以前的测试之一),但这导致登录测试失败。我想知道是否有一种方法可以使测试忽略下面的代码中的最后2条指令,无论它们是否可见。

I already tried to close the modal as soon as I login (which is one of the previous tests), but this leads the login test to fail. I was wondering if there is a way to make the test ignore the last 2 instructions from the code below, wether or not they are visible.

   it('Visits habitica and logins correctly', function () {
        cy.visit('https://habitica.com/login')
        cy.get('form').find('input[id="usernameInput"]').click().type("username")
        cy.get('form').find('input[id="passwordInput"]').click().type("password")
        cy.get('.btn-info').click() 
        cy.get('.modal-dialog').find('button[class="btn btn-warning"]').click()
        cy.get('.start-day').find('button').click({force:true})
    })


推荐答案

是浏览器模式还是模式由您的团队开发?在第一种情况下,赛普拉斯应自动接受模态。在第二种情况下,您可以通过仅在可见时接受它来解决它。您可以通过将其添加到脚本中来完成此操作:

Is it a browser modal or a modal developed by your team? In the first case Cypress should automatically accept the modal. In the second case you can work around it by only accepting it when it is visible. You can do that by adding this to your script:

cy.get('body').then($body => {
  if ($body.find('IDENTIFIER_FOR_THE_MODAL').length === 1) {
    cy.get('IDENTIFIER_TO_CLOSE_THE_MODAL')
      .click()
  }
})

它在体内搜索模态(当然,您必须将 IDENTIFIER_FOR_THE_MODAL 更改为正确的标识符)。如果确实找到模态,则脚本会搜索IDENTIFIER_TO_CLOSE_THE_MODAL来关闭模态并单击它。

It searches within the body for the modal (ofcourse you have to change IDENTIFIER_FOR_THE_MODAL to the correct identifier). If it does find the modal the script searches for the IDENTIFIER_TO_CLOSE_THE_MODAL to close the modal and clicks it.

在您的情况下,可能需要关闭模态的动作略有不同。 ,但语法可以使用。

Possible the action to close the modal has to be slightly different in your case, but the syntax will work.

这篇关于在赛普拉斯中,有没有一种方法可以根据每日消息来避免故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆