在量角器测试期间,离开页面然后返回中断等待角度启用()



在对 angular 8 应用程序运行 e2e 测试时,如果我离开应用程序并在测试中返回它,测试驱动程序将失败。

更具体地说:

在我的 Angular 8 应用程序中,我有一组量角器 e2e 测试,这些测试需要对外部页面上的服务器进行身份验证。

在量角器的 onPrepare 函数中,我通过等待应用程序检测到需要身份验证并重定向到登录页面来开始测试运行,该页面本身不是一个角度应用程序。

然后,我调用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 元素的任何操作都会无限期超时。 堆栈跟踪显示waitForAngular处失败。

如果我通过跳过对waitForAngularEnabled(true)的最后一次调用来等待角度切换,测试大多正常运行,但许多操作突然需要额外的手动wait调用才能正常工作。

有没有办法在返回页面后恢复原始waitForAngular行为?

您错过了waitForAngularEnabled方法的await

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);
}

最新更新