量角器等待超时
Protractor wait timing out
我在编写 angularjs e2e 测试时 运行 遇到 Protractor 的问题。
对于以下代码,它抛出的错误是 Failed: Wait timed out after 1025ms
。此测试专门针对 Ionic Modal,因此它的过渡持续时间少于 1000 毫秒。
it('should close the modal on button click', function () {
expect(modal.isPresent()).toBeTruthy();
element(by.css(merchantInfoClose)).click();
// wait for close animation to complete
browser.driver.wait(function() {
return !browser.isElementPresent(modal);
}, 1000).then(function() {
expect(modal.isPresent).toBeFalsy();
});
});
我对如何解决这个问题非常困惑,并且通读了许多关于量角器超时问题的 SO 帖子,其中 none 对我有所帮助。关于我在这里做错了什么有什么想法吗?
由于我们无法重现问题,只能假设并提出可能的解决方案。我会尝试使用 stalenessOf
expected condition:
An expectation for checking that an element is not attached to the DOM of a page.
var EC = protractor.ExpectedConditions;
browser.wait(EC.stalenessOf(modal), 1000);
莫非模态一直存在,但它的可见性被切换了?
然后,我怀疑你应该检查元素 visible 而不是 present:
expect(modal.isDisplayed()).toBeTruthy();
另见 How to use protractor to check if an element is visible?。
然后您可能还可以使用@alecxe 建议的预期条件,使用 ExpectedConditions.visibilityOf。
我还发现 click()
承诺后没有 then
有点可疑。以下是否有效?
element(by.css(merchantInfoClose)).click().then(function() {
expect(modal.isDisplayed()).toBeFalsy();
}
这假设模态通知 Angular 准备好动画,并且量角器能够自行判断应该等待它。
我在编写 angularjs e2e 测试时 运行 遇到 Protractor 的问题。
对于以下代码,它抛出的错误是 Failed: Wait timed out after 1025ms
。此测试专门针对 Ionic Modal,因此它的过渡持续时间少于 1000 毫秒。
it('should close the modal on button click', function () {
expect(modal.isPresent()).toBeTruthy();
element(by.css(merchantInfoClose)).click();
// wait for close animation to complete
browser.driver.wait(function() {
return !browser.isElementPresent(modal);
}, 1000).then(function() {
expect(modal.isPresent).toBeFalsy();
});
});
我对如何解决这个问题非常困惑,并且通读了许多关于量角器超时问题的 SO 帖子,其中 none 对我有所帮助。关于我在这里做错了什么有什么想法吗?
由于我们无法重现问题,只能假设并提出可能的解决方案。我会尝试使用 stalenessOf
expected condition:
An expectation for checking that an element is not attached to the DOM of a page.
var EC = protractor.ExpectedConditions;
browser.wait(EC.stalenessOf(modal), 1000);
莫非模态一直存在,但它的可见性被切换了? 然后,我怀疑你应该检查元素 visible 而不是 present:
expect(modal.isDisplayed()).toBeTruthy();
另见 How to use protractor to check if an element is visible?。
然后您可能还可以使用@alecxe 建议的预期条件,使用 ExpectedConditions.visibilityOf。
我还发现 click()
承诺后没有 then
有点可疑。以下是否有效?
element(by.css(merchantInfoClose)).click().then(function() {
expect(modal.isDisplayed()).toBeFalsy();
}
这假设模态通知 Angular 准备好动画,并且量角器能够自行判断应该等待它。