Webdriver.IO:如何使用 WDIO 在 Jasmine 中运行特定的 'it' 语句



我正试图从使用Jasmine框架(wdio-jasmine-framework)编写的回归套件中提取一个烟雾套件。

是否可以在Jasmine中为特定的测试用例添加一个标签?

如果我没有记错Jasmine/Mocha的日子,有几种方法可以实现这一点。我会详细介绍一些,但我相信可能还有其他一些。使用最适合你的。

1。条件运算符表达式中使用it.skip()语句来定义测试用例的状态(例如:在smokeRun的情况下,使用:(smokeRun ? it.skip : it)('not a smoke test', () => { // > do smth here < });跳过非烟雾测试)。

下面是一个扩展示例:

// Reading the smokeRun state from a system variable:
const smokeRun = (process.env.SMOKE ? true : false);
describe('checkboxes testsuite', function () {
// > this IS a smoke test! < //
it('#smoketest: checkboxes page should open successfully', () => {
CheckboxPage.open();
// I am a mock test... 
// I do absolutely nothing!
});
// > this IS NOT a smoke test! < //
(smokeRun ? it.skip : it)('checkbox 2 should be enabled', () => {
CheckboxPage.open();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
expect(CheckboxPage.lastCheckbox.isSelected()).toEqual(true);
});
// > this IS NOT a smoke test! < //
(smokeRun ? it.skip : it)('checkbox 1 should be enabled after clicking on it', () => {
CheckboxPage.open();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
CheckboxPage.firstCheckbox.click();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(true);
});
});

2.使用it.only()来实现主要相同的效果,不同之处在于测试用例重构工作负载。我将这些想法总结为:

  • 如果您的烟雾测试多于非烟雾测试,请使用it.skip()方法
  • 如果非烟雾测试多于烟雾测试,请使用it.only()方法

您可以在此处阅读有关pending-tests的更多信息。


3。运行时跳过(.skip())与一些嵌套的describe语句结合使用。

它应该看起来像这样:

// Reading the smokeRun state from a system variable:
const smokeRun = (process.env.SMOKE ? true : false);
describe('checkboxes testsuite', function () {
// > this IS a smoke test! < //
it('#smoketest: checkboxes page should open successfully', function () {
CheckboxPage.open();
// I am a mock test... 
// I do absolutely nothing!
});
describe('non-smoke tests go here', function () {
before(function() {
if (smokeRun) {
this.skip();
}
});
// > this IS NOT a smoke test! < //
it('checkbox 2 should be enabled', function () {
CheckboxPage.open();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
expect(CheckboxPage.lastCheckbox.isSelected()).toEqual(true);
});
// > this IS NOT a smoke test! < //
it('checkbox 1 should be enabled after clicking on it', function () {
CheckboxPage.open();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
CheckboxPage.firstCheckbox.click();
expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(true);
});
});
});

!注意:这些都是工作示例!我使用WebdriverIO推荐的Jasmine Boilerplace项目对它们进行了测试。

!Obs:有多种方法可以过滤Jasmine测试,不幸的是,只有在测试文件(testsuite)级别(例如:使用grep管道语句,或内置WDIOspecs&exclude属性

除了iamdanchiv的答案外,还有WebdriverIO~7+&Jasmine~3.7+(可能也有旧版本)您可以将任何文本标签添加到您的its和描述中,并过滤规范以由其运行。

工作包.json脚本使用Jasmine的grep:

"smoketest": "wdio run wdio.local.conf.js --suite=temp --jasmineOpts.grep=_smoke"

其中:

--suite=temp在wdio.local.conf.js套件中定义,并且只运行那些规范文件

--jasmineOpts.grep=_smoke在上述规范文件中的测试(it)标题和describe标题中找到"_smoke"部分,并仅运行它们。

这将运行完整描述的

describe(`Suite 1 _smoke any other text`, () => {
it('Test 1-1', async () => {});
it('Test 1-2', async () => {});
});

以及来自另一个描述的测试,如:

it('Test 2-1 _smoke is for smoke runs', async () => {});

将跳过不匹配的测试。

_smoke可以是您添加到标题中的任何其他文本标记。

附言:我不能让多个标签一起工作,但这足以只选择烟雾测试。

相关内容

最新更新