问题
I want to run feature files in a desired order or sequence, for example:
tags:"`@ProtractorScenario` or @CucumberScenario"
But cucumber scenario is getting executed first. Can someone guide me on this?
Note: Cucumber is executing scenario based on alphabetical order of feature file in folder
Also, in cases with more than 50+ feature files, what would be the best way to define sequencing of cucumber feature files?
回答1:
In order to have reliable tests, your tests should be independent and not rely on the order they are run in. The reason being that your test shouldn't depend on the system being in a certain state, as this will lead to flaky tests. Each of your tests should set up the expected state (and teardown!), so they can be run independently.
回答2:
Below is how protractor executes cucumber feature files:
- Protractor finds out all feature files specified in
specs
, save the absolute file path into an array, let's call itfeature_list
. - Protractor starts a session (start a browser instance)
Protractor generates a Cucumber CLI as below, and execute the CLI to hand over the running control cucumber:
./node_modules/bin/cucumber --require xxx --format xxx feature1,feature2,....featureN
feature1,feature2,....featureN calculated by
feature_list.join(',')
From above, we can learn the only opportunity to change the order
is given an order-done feature_list
to protractor specs
.
Note: every member of the
feature_list
should be absolute/relative path of single feature file.folder
andwildcard
are not recommended to appear in the path.
You can get a solution code from my github: spec.filter.js, which implements:
- filter feature file by cucumberOpts.tags
- order filter result of above step 1 by priority
Guide to use spec.filter.js
:
// protractor conf file
const specFilter = require('./spec.filter.js');
var config = {
seleniumAddress: 'xxxxx',
capabilities:'xxxx',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
ignoreUncaughtExceptions: true,
specs: [
'./aa/**/*.feature',
'./bb/**/*.feature'
],
cucumberOpts: {
require: [
'xxx'
],
priorities: {
// feature has tag @SPGC-21542 or @SPGC-21944 or @SPGC-21946
// will has priority 1
'1': ['@SPGC-21542 or @SPGC-21944', '@SPGC-21946'],
// feature has tag @SPGC-22055 will has priority 2,
// feature has heighest priority will put ahead at
// the `specs` list and get executed firstly.
'2': ['@SPGC-22055']
}
tags: ""
}
....
};
exports.config = specFilter(config);
来源:https://stackoverflow.com/questions/49237818/how-to-run-multiple-feature-files-in-sequence-using-cucumber-protractor