Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can protractor tests be run in a random order?

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

like image 250
TomVW Avatar asked Jun 08 '16 07:06

TomVW


People also ask

How do you run multiple protractor tests?

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.

How do you speed up a protractor test?

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.


1 Answers

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

});
like image 76
Florent B. Avatar answered Sep 17 '22 17:09

Florent B.