【问题标题】:Execute asynchronous and synchronous code in the same describe in protractor在量角器中以相同的描述执行异步和同步代码
【发布时间】:2015-10-18 20:03:15
【问题描述】:

在量角器中,我正在尝试使用“for”循环执行测试次数,问题是循环停止值取决于异步“it”测试用例。

describe ("[Windows] My Account - History", function(){

//The Page Object I use
var grid    = new Grid();

//Initialize grid object in it test case
it("Initialize the grid object from the DOM",function(){
    grid.init();
});

//create number of test iteration
for(var counter = 0;counter < grid.windowInfo.length; counter++){
    it("Test 1",function() {

    });

    it("Test 2",function() {

    });
}
});

这里grid.windowInfo.length init 没有正确的值,因为init "it" 测试用例被发送到队列,并首先执行for 循环。

【问题讨论】:

  • 您看到您的Test 1Test 2 it 在控制台中执行了吗?在it 之外使用for 循环不会执行它。

标签: javascript angularjs asynchronous jasmine protractor


【解决方案1】:

这不是您可以测试此类功能的方式。先创建it,然后在里面创建for,然后检查所有结果是否匹配。因此,it 只有在所有循环都按预期执行时才会成功。

否则,您可以使用if("Test " + counter, ...,但这可能不是一个好主意,也是一个糟糕的测试,因为如果windowInfo 为空,那么您的测试就可以了,我认为这不是您想要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多