How to run multiple feature files in sequence usin

2019-08-17 17:32发布

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?

2条回答
不美不萌又怎样
2楼-- · 2019-08-17 17:58

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-17 18:07

Below is how protractor executes cucumber feature files:

  1. Protractor finds out all feature files specified in specs, save the absolute file path into an array, let's call it feature_list.
  2. Protractor starts a session (start a browser instance)
  3. 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 and wildcard are not recommended to appear in the path.

You can get a solution code from my github: spec.filter.js, which implements:

  1. filter feature file by cucumberOpts.tags
  2. 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);
查看更多
登录 后发表回答