我必须测试一个流程,在该流程中,angular 必须在恢复对返回页面的测试之前执行硬重定向到 bitly。
这会导致 UnknownError: javascript error: document unloaded while waiting for result
错误,该错误在网络上被广泛讨论。
但是,我找不到解决方法。问题出现在这两行之间:
element(by.id('signup-btn')).click();
expect(element(by.id('accept-btn')).isDisplayed()).toBeTruthy();
第一行提交一个导致硬重定向的表单(如 $window.location.href='/something'
)将网络应用程序返回到由第二行测试的页面线。但是重定向 borks projector.js。
有办法吗?
最佳答案
您可以使用等待功能代替 expect 断言
首先像这样声明一个定义全局最大时间的模块。
var Transitions = function(){};
//Sleep function to counter the custom animation that has been addes
Transitions.prototype.maxTimeToLook = 30000;
exports.Transitions = new Transitions();
这将是 Protractor 查找元素的最大超时时间。 然后你可以使用像这样的预期条件函数而不是 expect
browser.wait(protractor.ExpectedConditions.presenceOf(element(by.id('accept-btn'))), sync.maxTimeToLook);
您面临的问题是因为当您单击按钮时您正在使用 expect,expect 条件检查要在页面上呈现的元素。在我的测试中有效的一种解决方法是使用 presence of
根据 API 文档 https://angular.github.io/protractor/#/api?view=ExpectedConditions.prototype.stalenessOf
ExpectedConditions.prototype.presenceOf
An expectation for checking that an element is present
on the DOM of a page. This does not necessarily mean that
the element is visible.
如果存在不起作用。也许你可以使用这里提到的其他预期条件方法
https://angular.github.io/protractor/#/api?view=ExpectedConditions
关于javascript - Protractor.js 如何在硬页面重新加载之间等待结果而不会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29979812/