How to run multiple feature files in sequence using Cucumber + protractor

流过昼夜 提交于 2019-12-11 16:24:49

问题


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:

  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);


来源:https://stackoverflow.com/questions/49237818/how-to-run-multiple-feature-files-in-sequence-using-cucumber-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!