【问题标题】:Protractor - Angular Goes out of sync for feature modules量角器 - Angular 与功能模块不同步
【发布时间】:2021-06-20 04:31:10
【问题描述】:

我正在尝试使用量角器运行角度 e2e 测试。

这是我的 Angular 项目的样子:

角度项目

  • 主模块

    • HR 模块(功能模块)
    • 注册模块(功能模块)

对于我的 e2e 测试,如果我尝试在主模块上执行测试,它们运行良好,但对于功能模块,它会不同步。

我收到的错误是 - Angular is not defined. 有时是element is not visible within specified timeout

规格代码:

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

导航到页面代码:

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

我最好的猜测是,由于功能模块加载了不同的脚本,因此它与 angular.js 不同步。目前它仅在点击时冻结并且测试停止。

问题:如何使它与角度同步?

【问题讨论】:

    标签: angular protractor angular8 angular-e2e


    【解决方案1】:

    让我们从 1 个 1 个开始

    navigateToPagewaitForAngular 返回承诺。一个承诺需要被解决。所以当你打电话给他们时,请使用await

    告诉我你看到了什么

    【讨论】:

    • 还是一样:Async callback was not invoked within timeout specified。我认为与导致问题的功能模块有关? defaultTimeoutInterval: 30000,
    • 您确定没有将任何参数传递给it 块的第二个参数,例如本例中的done `it('应该能够加载页面',async (done ) => {`
    • 没有谢尔盖,即使我对这种行为感到惊讶
    • 好的,下一步我要做的是确定您的页面是否与量角器兼容。 stackoverflow.com/questions/20927652/…
    • 如果我尝试检查 angular 是否启用,它返回 false 并且它是一个 angularR 应用程序。加载延迟加载的路线后,页面变得无角度。如果我尝试导航到其他页面,它会按预期工作。
    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    相关资源
    最近更新 更多