无法检查量角器中的状态指示器
Unable to check for status indicator in protractor
我正在为端到端测试开发量角器,需要检查状态指示器是否在单击按钮之前消失。现在我做不到。
我曾尝试使用 invisibilityOf()
和 stalenessOf()
但它不起作用。它显示错误'在点 (540,823) 不可点击,其他元素将收到点击:<#api-status-indicator>'
这是我在 PageObject 中的代码:
public isNotPresent(elem) {
return browser.wait(protractor.ExpectedConditions.stalenessOf(elem), 5000).then(function () {
console.log("Status indicator is not present in DOM");
return true; //success
},function () {
console.log("Status indicator is present in DOM");
return false; //Failure
});
}
public waitForStatusIndicator(){
console.log('in method wait for status indicator');
return this.isNotPresent(element(by.css('#api-status-indicator'))).then((isNotPresent)=>{
return isNotPresent;
});
}
这是我尝试检查状态指示器的位置:
PageObject.waitForStatusIndicator().then(function (isNotPresent) {
if(isNotPresent == true) {
someButton.click();
return expect(browser.getCurrentUrl()).not.toBe(browser.baseUrl + "/login");
}
})
我哪里错了?
如果该元素刚出现,不在 DOM 中,您首先需要等到它出现并可见,然后再检查它是否又消失了。
总的来说是这样的:
public isNoLongerPresent(elem) {
//NOTE: If any of the expected conditions don't happen, your code times out.
//No need for false-check or similar
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(elem), 5000);
browser.wait(EC.visibilityOf(elem), 5000); //Note, that visibilityOf requires presence
return browser.wait(EC.stalenessOf(elem), 5000);
}
public waitForStatusIndicator(){
console.log('in method wait for status indicator');
return this.isNoLongerPresent(element(by.css('#api-status-indicator')));
}
你的规格:
再次不需要任何 then()
。量角器同步执行它,如果途中有任何 false
,您的代码将超时。
PageObject.waitForStatusIndicator();
someButton.click();
return expect(browser.getCurrentUrl()).not.toBe(browser.baseUrl + "/login");
我正在为端到端测试开发量角器,需要检查状态指示器是否在单击按钮之前消失。现在我做不到。
我曾尝试使用 invisibilityOf()
和 stalenessOf()
但它不起作用。它显示错误'在点 (540,823) 不可点击,其他元素将收到点击:<#api-status-indicator>'
这是我在 PageObject 中的代码:
public isNotPresent(elem) {
return browser.wait(protractor.ExpectedConditions.stalenessOf(elem), 5000).then(function () {
console.log("Status indicator is not present in DOM");
return true; //success
},function () {
console.log("Status indicator is present in DOM");
return false; //Failure
});
}
public waitForStatusIndicator(){
console.log('in method wait for status indicator');
return this.isNotPresent(element(by.css('#api-status-indicator'))).then((isNotPresent)=>{
return isNotPresent;
});
}
这是我尝试检查状态指示器的位置:
PageObject.waitForStatusIndicator().then(function (isNotPresent) {
if(isNotPresent == true) {
someButton.click();
return expect(browser.getCurrentUrl()).not.toBe(browser.baseUrl + "/login");
}
})
我哪里错了?
如果该元素刚出现,不在 DOM 中,您首先需要等到它出现并可见,然后再检查它是否又消失了。
总的来说是这样的:
public isNoLongerPresent(elem) {
//NOTE: If any of the expected conditions don't happen, your code times out.
//No need for false-check or similar
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(elem), 5000);
browser.wait(EC.visibilityOf(elem), 5000); //Note, that visibilityOf requires presence
return browser.wait(EC.stalenessOf(elem), 5000);
}
public waitForStatusIndicator(){
console.log('in method wait for status indicator');
return this.isNoLongerPresent(element(by.css('#api-status-indicator')));
}
你的规格:
再次不需要任何 then()
。量角器同步执行它,如果途中有任何 false
,您的代码将超时。
PageObject.waitForStatusIndicator();
someButton.click();
return expect(browser.getCurrentUrl()).not.toBe(browser.baseUrl + "/login");