【发布时间】:2016-12-28 14:53:20
【问题描述】:
我正在使用量角器运行 e2e 测试用例。所有量角器调用都是异步调用。以下代码是量角器代码:
gridRow.then(function (rows) {
for (var index = 0; index < rows.length; index++) {
console.log(index); -------------------- 1
rows[index].all(by.className('ui-grid-cell-contents ng-scope')).get(1).getText().then(function (text) {
console.log(index); ----------------- 2
if (text.toUpperCase().replace(/ |-/g, '') === 'BRANCHONE') {
console.log(index); -------------- 3
}
});
}
});
在这种情况下 rows.length = 2。 1 处的 Console.log 按预期输出 0 和 1,但 2 和 3 处的 console.log 输出为 2,因为 then 调用是异步的。由于异步调用并行运行,同时index 的值更新为 2(index++)。
知道如何在我的异步调用中跟踪同步变量(索引)吗?
【问题讨论】:
标签: javascript asynchronous protractor