量角器执行在验证 DOM 中不存在的元素时挂起



这很奇怪,当我们验证测试用例在 dom 中不存在时,量角器执行无限挂起。 下面是我们尝试的代码,但它挂起不知道为什么。 它一直在等待这个.columnNamesInTableSingle 元素,即使它在 DOM 中不存在,我们只需要验证它

var el = this.columnNamesInTableSingle;
browser.wait(protractor.ExpectedConditions.not(protractor.ExpectedConditions.presenceOf(el)),5000);

expect(this.columnNamesInTableSingle.isPresent()).toBe(false);
this.columnNamesInTableSingle.then(a=>{
//         console.log(a.length+"==============================")
//     },abc=>{
//         console.log(abc)
//     })

我知道这篇文章很旧,但我实现了一个函数,可用于测试元素是否存在(或不存在)在没有任何wait的情况下在 DOM 中:

3个参数:

  • 字段:目标ElementFinder | ElementFinder[];
  • 字段名称:string目标的名称(仅用于记录它);
  • 演示:boolean切换控件(测试是否存在);

函数:

export async function checkField(field: any, fieldName: string, present?: any) {
let text: string;
if (present === false) {
if (field.length > 0) {
field.forEach(async el => {
try {
text = await el.getText();
expect('should not be present (' + fieldName + ')').toEqual('but it is');
} catch (e) {
expect(el.isPresent()).toBe(present);
}
});
} else {
try {
text = await field.getText();
expect('should not be present (' + fieldName + ')').toEqual('but it is');
} catch (e) {
expect(field.isPresent()).toBe(present);
}
}
} else {
if (field.length > 0) {
field.forEach(async el => {
try {
text = await el.getText();
expect(el.isPresent()).toBe(true);
} catch (e) {
expect('is present (' + fieldName + ')').toEqual('but i can't find it');
throw e;
}
});
} else {
try {
text = await field.getText();
expect(field.isPresent()).toBe(true);
} catch (e) {
expect('is present (' + fieldName + ')').toEqual('but i can't find it');
throw e;
}
}
}
}

希望这仍然有用(我知道,可以写得更好)

如果这有效并满足您的问题,请考虑关闭它!

最新更新