我正在运行 Protractor 测试,该测试应检查网格中是否存在具有特定许可证号的记录。但是,在遍历所有行后,它会丢失为 rowNumber
变量分配的值。不知道为什么要这样做。 rowNumber
应等于索引。
这是我的测试。
var rowNumber = null;
var rows = element.all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index'));
it('should find row the created Driver Licence lives on', function() {
rows.each(function(element, index) {
element.getText().then(function (text) {
if (text.includes(licenceNumber)) {
rowNumber = index; //rowNumber does equal the index at this point
return true;
}
});
expect(rowNumber).not.toEqual(null);
});
});
最佳答案
终于解决了。这就是我所做的
it('should find row the created Driver Licence lives on', function() {
rows.each(function(element, index) {
element.getText().then(function (text) {
if (text.includes(licenceNumber)) {
rowNumber = index;
return true;
}
}).then(function() {
expect(rowNumber).not.toEqual(null);
});
});
});
关于javascript - 变量在 Protractor 测试中丢失指定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853956/