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
我在数据透视跟踪找到了一个对Jasmine的功能请求
2 个解决方案
#1
3
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.
从10/10/17开始,可以在protractor.conf中设置一个设置。js jasminenodets以半随机的顺序运行spec,使用Jasmine时不需要任何代码。
In your protract.conf.js file add the following json block:
在你protract.conf。js文件添加以下json块:
jasmineNodeOpts?: {
...
/**
* If true, run specs in semi-random order
*/
random?: boolean,
...
};
源
#2
8
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
});
#1
3
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.
从10/10/17开始,可以在protractor.conf中设置一个设置。js jasminenodets以半随机的顺序运行spec,使用Jasmine时不需要任何代码。
In your protract.conf.js file add the following json block:
在你protract.conf。js文件添加以下json块:
jasmineNodeOpts?: {
...
/**
* If true, run specs in semi-random order
*/
random?: boolean,
...
};
源
#2
8
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
});