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
When you want to run protractor scripts by opening a browser instance for each test, you should add two capabilities shardTestFiles and maxInstances in the Capabilities block of the conf. js file. This will help to execute your scripts on same browser with multiple instances.
To do this is quite simple in protractor. Adding the shardTestFiles and maxInstences to your capabilities config should allow you to (in this case) run at most two test in parrallel. Increase the maxInstences to increase the number of tests run. Note : be careful not to set the number too high.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With