简体   繁体   English

Protractor - Angular 功能模块不同步

[英]Protractor - Angular Goes out of sync for feature modules

I am trying to run angular e2e tests using protractor.我正在尝试使用 protractor 运行 angular e2e 测试。

Here is my angular project looks like:这是我的 angular 项目的样子:

Angular Project Angular项目

  • Main module主模块

    • HR module (Feature module) HR模块(功能模块)
    • Register Module (Feature module)注册模块(功能模块)

For my e2e tests they are running fine if I try to execute tests on main module, but for the feature modules it goes out of sync.对于我的 e2e 测试,如果我尝试在主模块上执行测试,它们运行良好,但对于功能模块,它会不同步。

The error I am receiving is - Angular is not defined.我收到的错误是 - Angular is not defined. and some times element is not visible within specified timeout有时element is not visible within specified timeout

Spec code:规格代码:

describe('Page name', () => {

    it('should be able to load page', async () => {
      
        navigateToPage('hr/csvimport');
       
        browser.waitForAngular();
       
        const settingsName = generateRandomNumber();
       
        let btnAdd = element(by.id('btnAdd'));
        await btnAdd.click();
        //expect condition
   });
});

Navigate to page code:导航到页面代码:

export const navigateToPage = async (path) => {
    console.log('set location ' + path);
    if (path === '/' || path === '') {
        await browser.get('/');
    } else {
        await browser.waitForAngular().then(() => {
            browser.get('/' + path);
        });    
    }    
};

My best guess is that because of the feature module having different script loading it some how goes out of sync with angular.我最好的猜测是,由于功能模块加载了不同的脚本,因此它与 angular 不同步。 currently its frozen on click only and tests stops.目前它仅在点击时冻结并且测试停止。

Question: how to make it sync with the angular?问:如何使其与angular同步?

lets start 1 by 1让我们从 1 开始

navigateToPage and waitForAngular return promises. navigateToPagewaitForAngular返回承诺。 A promise needs to be resolved. promise 需要解决。 So when you call them use await所以当你打电话给他们时,请使用await

Let me know what you're seeing让我知道你在看什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM