我正在使用一个黄瓜量角器框架来运行特征文件。
在我的config.js中,我有:
specs: [
"../../features/XXX1.feature",
"../../features/XXX2.feature",
...
"../../features/XXXn.feature",
],
cucumberOpts: {
tags: "@mytag",
},
在我的功能文件XXX1.feature中,我将此标签设置为“ @mytag”:
@mytag
Scenario Outline: my Flow
Given I am running test case one
....
,但没有其他任何功能文件,例如XXX2.feature,XXX3.feature等。
我希望量角器仅运行XXX1.feature,而不运行XXX2.feature。确实如此,当涉及到XXX2.feature时,它启动浏览器,不执行任何操作,然后输出以下内容:
[14:35:53] I/testLogger - [chrome #01-2] PID: 14272
[chrome #01-2] Specs: D:\ptfbc\ui\features\XXX2.feature
[chrome #01-2]
[chrome #01-2] [14:35:44] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
[chrome #01-2]
[chrome #01-2]
[chrome #01-2] 0 scenarios
[chrome #01-2] 0 steps
[chrome #01-2] 0m00.000s
但是还不够好。由于XXX2.feature中没有标签“ @mytag”。它不应该跳过功能文件XXX2.feature并且根本不启动浏览器吗?
为每个不带有'@mytag'的不合格功能文件启动浏览器也很耗时。
有没有一种可以避免这种情况的配置方式?
功能和hook.ts
capabilities: {
browserName: "chrome",
shardTestFiles: true,
maxInstances: 1,
'chromeOptions': {
'args': [
'disable-infobars'//,'headless=true','disable-gpu=true',
],
'prefs': {
'credentials_enable_service': false,
'download': {
'prompt_for_download': false,
'directory_upgrade': true,
}
}
}
},
const { BeforeAll, After, Status } = require("cucumber");
import * as fs from "fs";
import { browser } from "protractor";
import { config } from "../config/config";
BeforeAll({timeout: 300 * 1000}, async () => {
await browser.get(config.baseUrl);
});
After(async function(scenario) {
// screenShot is a base-64 encoded PNG
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
});
答案 0 :(得分:1)
For the process of Protractor executing a feature file, it can be split into two stages.
Protractor open browser instance (create session) for each feature file as the first stage, then Protractor will hand over the running task to cucumber as the second stage.
In the second stage, cucumber will detect the feature file whether satisfy the tag. If not, cucumber won't run any scenario for the feature file and you will get 0 scenarios, 0 steps
in console.
Otherwise, cucumber will execute those scenarios satisfy the tag in feature file.
Because Protractor isn't responsible for detecting feature file satisfy the tag before it open browser, therefor as what you see a browser opened and closed without any operation
.
The only solution is to give the precise specs
in Protractor conf.js which satisfied the tag. In order to do that, you need to filter the feature files against tag then assign the filter result to specs
.
I made a spec filter at github
// general config.js
exports.config = {
specs:[
'./features/**/*.feature'
],
cucubmerOpts: {
tags: '@abc'
}
};
// conf.js use my filter
var config = {
specs:[
'./features/**/*.feature'
],
cucubmerOpts: {
tags: '@abc'
}
};
exports.config = require('./spec.filter.js').filter_by_tag(config);
答案 1 :(得分:0)
您正在做一个小错误,将其更改为Before而不是beforeAll。
并确保您拥有给定的小黄瓜,以便每种情况都可以导航到主页或URL。
Given I am navigating to homepage
这将有您的browser.navigate(url)
答案 2 :(得分:0)
我遇到了完全相同的问题,删除后问题解决了
shardTestFiles: true