rafalf
rafalf

Reputation: 435

run spec multiple times

    suites: {
    dev: ['./test/show-file.spec.js'],
    smoke: [
        // './test/template.spec.js',
        './test/form-validation.spec.js',
        './test/upload.spec.js',
        './test/empty-folder.spec.js',
        './test/versions.spec.js',
        './test/search.spec.js',
        './test/archive.spec.js',
        './test/move.spec.js',
        './test/copy.spec.js',
        './test/tags.spec.js',
        './test/share.spec.js',
        // './test/signup.spec.js',
        // './test/show-file.spec.js',
    ],
    recovery: [
        './test/show-file.spec.js',
        './test/show-file.spec.js',
        './test/show-file.spec.js',
        './test/show-file.spec.js',
        './test/show-file.spec.js',
        './test/show-file.spec.js',
    ]
},

the above is my config file and Id like to run recovery suite to make sure that the system recovers. so basically the same test X times. for some unknown to me reason it only runs it once. is there any setting to avoid it and have it run multiple times

test.conf.js --suite=recovery 

Found a work around

for (var i = 0; i < 10; ++i){
    describe('Suite: show', function () {
        it('may be fine', function () {
            expect(Math.random() < 0.5).toBeTruthy();
        });
    });
}

Upvotes: 0

Views: 1338

Answers (1)

yong
yong

Reputation: 13722

Protractor will do the repeatability check on suite to remove same file pattern/file name, but don't do that on specs.

The simply solution is to use specs rather than suite. No extra script needed.

The compalicate solution need extra script's assistance.

// protractor conf.js

var params = {};   
process.argv.slice(3).forEach(function(arg, index) {
    var flag = arg.split('=')[0];
    var value = arg.split('=')[1];
    var name = flag.replace('--', '');   
    params[name] = value;   
});

console.dir(params);

var config = {   
    capabilities: {
        browserName: 'chrome'
    },   
    suites: {
        dev: ['./test/show-file.spec.js'],
        smoke: [
            './test/template.spec.js',
            // ...
        ],
        recovery: [
            './test/show-file.spec.js'
        ]
    },   
    onPrepare: function() {}, 
    // ...
};

if (params['repeat.suites'] && config.suites &&
    Object.keys(config.suites).length > 0) {

    var repeat = (params['repeat.times'] || 1) * 1;
    var specs = [];   
    params['repeat.suites'].split(',').forEach(function(suiteName) {
        suiteName = suiteName.trim();
        if (config.suites[suiteName]) {
            specs = specs.concat(config.suites[suiteName]);
        }
    });

    var allSpecs = [];   
    while (repeat > 0) {
        allSpecs = allSpecs.concat(specs);
        repeat--;
    }  
    config.specs = allSpecs;
}

console.dir(config);   
exports.config = config;

// protractor cmd line:
protractor conf.js --repeat.suites="smoke,recovery" --repeat.times=2

Note you can continue use other protractor supported cli options. Only when you want to repeat execute some suite, you should not use --suite, but use --repeat.suite instead.

Upvotes: 1

Related Questions