Protractor cucumber框架:如何只运行一个测试



仅供参考,其他Stackoverflow问题/答案都没有为我解决这个问题。

Angular项目中,我们使用Protractor Cucumber Framework进行E2E测试。

我不知道如何通过tags只运行一个测试。您应该能够在protractor.conf.js文件的cucumberOpts属性中编辑tags。但是,当我在那里添加一个标记@testOnlyThis,然后将该标记添加到.feature文件中的测试中,然后运行npm run e2e:ci(根据package.json,它运行"protractor ./e2e/protractor.conf.js")时,Protractor仍然运行我们套件中的每个E2E测试。在protractor.conf.js文件中所做的其他更改将生效,但编辑tags似乎没有任何效果。

什么东西?

量角器.conf.js

// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const path = require('path');
const fs = require('fs');
const cucumberJunit = require('protractor-cucumber-junit/lib/cucumber_junit');
const downloadsPath = path.resolve(__dirname, 'downloads');
const reportingPath = path.resolve(__dirname, 'reporting/protractor-cucumber-framework');
let startDate;
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 20000,
specs: ['./src/features/**/**/**/**/**/*.feature'],
resultJsonOutputFile: 'reporting/results.json',
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1,
chromeOptions: {
prefs: {
'plugins.always_open_pdf_externally': true,
download: {
directory_upgrade: true,
prompt_for_download: false,
default_directory: downloadsPath,
},
},
args: [
'--no-sandbox',
'--test-type=browser',
'--disable-gpu',
'--log-level=1',
'--disable-dev-shm-usage',
// '--disk-cache-dir=null',
],
},
},
directConnect: true,
SELENIUM_PROMISE_MANAGER: false,
noGlobals: true,
baseUrl: 'https://mybaseurl.com',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: ['./src/step-definitions/*steps.ts'],
tags: ['@testOnlyThis', '~@ignore'],
format: ['json:./reporting/protractor-cucumber-framework/results.json'],
retry: 2,
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json'),
});
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
},
beforeLaunch() {
startDate = new Date().getTime();
if (!fs.existsSync(downloadsPath)) {
fs.mkdirSync(downloadsPath);
}
if (!fs.existsSync(reportingPath)) {
fs.mkdirSync(reportingPath, { recursive: true });
}
console.log(`process.env.E2E_LANGUAGE is set to: '${process.env.E2E_LANGUAGE}'`);
},
afterLaunch() {
const endDate = new Date().getTime();
const duration = (endDate - startDate) / (60 * 1000);
console.log(
`ALL TESTS EXECUTION TIME: ${Math.floor(duration)}m${Math.round((duration % 1) * 60)}s`,
);
const file = fs.readFileSync('reporting/results.json', 'utf-8');
// @ts-ignore
const xml = cucumberJunit(file);
fs.writeFileSync('e2e/reporting/results.xml', xml);
fs.rmdirSync(reportingPath, { recursive: true });
},
};

嗨,试着这样声明你的标签,如果这有助于的话

cucumberOpts: {
tags: '@Smoke,@Intgr'
}

最新更新