我有三个要检查的代码是否存在。当我运行我的代码时,我收到一条消息,提示“ Expected false to true”。我在做什么错
var Ecode1 = element(by.xpath('.//*[contains(text(),\'201\')]'));
var Ecode2 = element(by.xpath('.//*[contains(text(),\'202\')]'));
var Ecode3 = element(by.xpath('.//*[contains(text(),\'501\')]'));
if (expect(Ecode1.isPresent()).toBe(true)) {
//ecode1 rules
}
else if (expect(Ecode2.isPresent()).toBe(true)) {
//ecode2 rules
}
else if (expect(Ecode3.isPresent()).toBe(true)) {
//ecode3 rules
}
else {
browser.close();
}
答案 0 :(得分:0)
只要像解决方案一样承诺isPresent
,就可以:
async/await
方法:
if (await Ecode1.isPresent()) {
} else if (await Ecode2.isPresent()) {
} else if (await Ecode3.isPresent()) {
} else {
browser.close();
}
Web驱动程序Control Flow
的方法很丑陋,并且需要额外的复杂性:
Promise.all([
Ecode1.isPresent(),
Ecode2.isPresent(),
Ecode3.isPresent()
]).then((result)=>{
// Ecode1 present
if(result[0]) {
}
// Ecode2 present
else if(result[1]) {
}
// Ecode3 present
else if(result[2]) {
}
else {
browser.close();
}
});
此外,expect
下的if
语句是多余的