I'm trying to enforce independence between protractor tests within a spec.
To detect whether or not tests are depending on a state introduced by an previous test, I would like to run those tests in random order.
Is there a way to tell protractor the order of tests can be randomized?
I found a feature request for Jasmine at pivotaltracker
As of 10/10/17, it's possible to set a setting in the protractor.conf.js JasmineNodeOpts to run specs in semi-random order when using Jasmine, no code needed.
In your protract.conf.js file add the following json block:
jasmineNodeOpts?: {
...
/**
* If true, run specs in semi-random order
*/
random?: boolean,
...
};
Source
You could execute the specs in a random order by shuffling them at the end of the suite:
var shuffle = function (items) {
var item, ii;
for(var i = 0; i < items.length; i++){
ii = (Math.random() * items.length) | 0;
item = items[i];
items[i] = items[ii];
items[ii] = item;
}
}
describe('Suite', function() {
it("should a", function () {
console.log("execute a");
});
it("should b", function () {
console.log("execute b");
});
it("should c", function () {
console.log("execute c");
});
shuffle(this.children); // shuffle the specs
});