本文介绍了量角器waitForAngularEnabled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

waitForAngularEnabled似乎不起作用.

waitForAngularEnabled doesn't seem to work.

用例:-将waitForAngularEnabled设置为false以获取sso页并填充用户/密码字段-返回角度应用程序并将waitForAngularEnabled设置为true会导致错误

Use case :- waitForAngularEnabled to false to get sso page and fill user/password fields- return to angular app and waitForAngularEnabled to true causes error

我已经创建了一个简单的有角度的应用程序projet来再现它,并运行e2e

i've create a simple angular app projet to reproduce it, simple run ng e2e

https://github.com/lilletech/protractor-issue

推荐答案

为了调试和减轻量角器控制流程的问题,您应该进一步分解测试.将测试更改为以下工作:

You should break your tests up more, both for your sake with debugging and to mitigate issues with the protractor control flow. Changing your tests to the following works:

import { browser, element, by } from 'protractor';

describe('protractor-test-project App', () => {

    it('goes to google', () => {
        browser.waitForAngularEnabled(false);
        browser.get('https://www.google.com');
        expect(browser.getCurrentUrl()).toEqual('https://www.google.com/');
    });

    it('enters a search', () => {
        const inputEl = element(by.id('lst-ib'));
        browser.wait(() => inputEl.isPresent(), 10000, 'too long');
        inputEl.sendKeys("protractor issue waitForAngularEnabled");
        expect(inputEl.getAttribute('value')).toEqual('protractor issue waitForAngularEnabled');
    });

    it('returns to angular page', () => {
        browser.get('/');
        browser.waitForAngularEnabled(true);
        const titleElement = element(by.id("title"));
        expect(titleElement.isPresent());
    });
});

不能肯定地说为什么控制流不能正确处理这个问题,但这似乎是由于在同一规范中有两个waitForAngularEnabled引起的(也可能是因为导航了两次).如果禁用第二个(重新启用它的位置),则测试有效.

Can't say for sure why the control flow wouldn't be handling this properly, but this seems to be caused by having two waitForAngularEnabled in the same spec (also might be because of navigating twice). If you disable your second one (where you re-enable it), your test works.

因此,您可以使用上面的解决方案将其分解为多个步骤,也可以将调用嵌套在browser.get下,这似乎也可以工作

So you can either use my solution above which breaks them out into multiple steps, or you can nest the call under browser.get which also seems to work i.e.

   browser.get('/').then(() => {
        browser.waitForAngularEnabled(true);
    });

同样,不确定为什么会那样.控制流应该同步这些步骤,因此不必使用c2,但是显然如此.将测试分为多个it块也可以帮助量角器以正确的顺序同步事物

Again, not sure why exactly that would happen. The control flow should be synchronizing these steps so using .then() shouldnt be necessary... but apparently it is. Breaking tests out into multiple it blocks also helps protractor synchronize things in the proper order

这篇关于量角器waitForAngularEnabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 13:49