【发布时间】:2014-05-12 18:56:20
【问题描述】:
上下文:使用 Protractor 在 Angular JS 中进行端到端测试
目标:我想针对许多不同的值运行相同的测试。理想情况下,循环遍历一组值并为每个值运行相同的 it 块。
问题:由于 Protractor 将异步运行测试,for 循环内的任何测试都将在循环结束后执行。
例如,
var values = ['...','...'];
for (var i = 0; i < values.length; i++) {
it('should do something good', function() {
// some test using this particular value in the values array
});
}
但是(假设数组中有 10 个项目),结果是测试运行了 10 次,其中 i 的值每次都是 9,而不是预期的 0,1,2,3...。这与测试的异步特性有关。
我的尝试:根据this stack overflow question的回答使用done()回调。
for (var i = 0; i < values.length; i++) {
it('should do something good', function (done) {
// some test using this particular value in the values array
setTimeout(done, 1000);
});
}
为什么这不起作用:我收到以下错误:
/node_modules/protractor/jasminewd/index.js:44
throw new Error('Do not use a done callback with WebDriverJS tests
^
Error: Do not use a done callback with WebDriverJS tests. The tests are patched to be asynchronous and will terminate when the webdriver control flow is empty.
at null._onTimeout (/Users/drew/apps/hotrod/node_modules/protractor/jasminewd/index.js:44:19)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
关于如何遍历一组值并对每个值运行相同的测试有什么想法吗?谢谢
【问题讨论】:
标签: angularjs asynchronous selenium-webdriver jasmine protractor