如何仅在特定情况下跳过规范文件中的整个测试集? 示例代码:

context("Conditional run", () => {
    before(() => {
        cy.get("div").then($div => {
            if (!Cypress.$("div[title='OK']", $comp).length) {
                // continue with the tests
            } else {
                // skip ALL the tests
            }
        });
    });
  });

推荐答案

beforeEach()可以跳过.

尝尝这个

  context("Conditional run", () => {
    let skip = false;
    before(() => {
        cy.get("div").then(($div) => {
            if (!Cypress.$("div[title='OK']", $comp).length) {
                skip = false
            } else {
                skip = true
            }
        });
    });

    beforeEach(function() {    // use regular function here
      if (skip) this.skip();
    })
  });

因为您想跳过所有测试,所以只需将跳过调用放在前面可能也行得通.

  context("Conditional run", () => {

    before(function() {    // use regular function here

        cy.get("div").then(function($div) {    // not sure if function is needed here
            if (Cypress.$("div[title='OK']", $comp).length) {
                this.skip();
            }
        });
    });
  });

Javascript相关问答推荐

错误:找不到react-redux上下文值;请确保该组件包装在React原生Expo应用程序中的提供者中

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

如何通过继承contentitable属性的元素捕捉keydown事件?

获取表格的左滚动位置

. NET中Unix时间转换为日期时间的奇怪行为

角色 map 集/spritebook动画,用户输入不停止在键上相位器3

我应该绑定不影响状态的函数吗?'

判断表格单元格中是否存在文本框

Spring boot JSON解析错误:意外字符错误

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

用JS从平面文件构建树形 struct 的JSON

如何将数据块添加到d3力有向图中?

扩展类型的联合被解析为基类型

变量在导入到Vite中的另一个js文件时成为常量.

将异步回调转换为异步生成器模式

如何确保预订系统跨不同时区的日期时间处理一致?

处理app.param()中的多个参数

ReferenceError:无法在初始化之前访问setData

将Singleton实例设置为未定义后的Angular 变量引用持久性行为

在Puppeteer中使用promise进行日志(log)记录时出现TargetCloseError