在对angular 8应用程序运行e2e测试时,如果我离开应用程序并在测试中返回,测试驱动程序会失败。
更具体地说:
在我的Angular 8应用程序中,我有一组量角器e2e测试,这些测试需要对外部页面的服务器进行身份验证。
在量角器的on准备功能中,我通过等待应用程序检测到需要身份验证并重定向到登录页面来开始测试运行,该页面本身不是一个角度应用程序。
然后我调用waitForAngularEnabled(false),执行必要的登录步骤,并重新启用waitForAngular。
代码如下所示:
const onPrepare = async () => {
browser.waitForAngularEnabled(false);
await browser.get('/');
await $('#username').clear();
await $('#username').sendKeys('username');
await $('#password').clear();
await $('#password').sendKeys('password');
await $('button[value=login]').click();
browser.waitForAngularEnabled(true);
}
恢复测试后,任何等待UI元素的操作都会无限期超时。堆栈跟踪显示< code>waitForAngular处出现故障。
如果我通过跳过最后一次调用waitForAngularEnford(true)
来关闭等待角度,测试大多正常运行,但很多操作突然需要额外的手动等待
调用才能正常工作。
有没有办法在我返回页面后恢复原始的 waitForAngular
行为?
您错过了等待角度启用
方法的等待
。
const onPrepare = async () => {
await browser.waitForAngularEnabled(false);
await browser.get('/');
await $('#username').clear();
await $('#username').sendKeys('username');
await $('#password').clear();
await $('#password').sendKeys('password');
await $('button[value=login]').click();
await browser.waitForAngularEnabled(true);
}