有条件地 运行 it() 块或嵌套 it() 块在 Webdriver.io

Conditionally run it() block or nest it() block in Webdriver.io

我正在尝试在 Webdriver.io 中进行测试,当第一个 it() 块断言失败时停止。是否可以嵌套 it() 块或有条件地执行它们?

对于您的第一个问题 "I am trying to have a test in Webdriver.io stop when the first it() block fails its assertion",答案如下:-

您可以按照此处所述使用 mocha 'bail' 选项 Mocha Bail

命令行用法:-

 --bail, -b                 Abort ("bail") after first test failure   [boolean]

并且,在这样的任何配置文件中

"bail" : true 

Any "boolean" flag (which doesn't require a parameter, such as --bail), can be specified using a boolean value, e.g.: "bail": true.

关于条件执行 it 语句的第二个问题,请看下面的代码

describe("Some module", function() {
if(false) {
    it ("should NOT run this test case", function() { });
}

it("should run this test case", function() { });  });

如果您需要更多帮助,请告诉我。