首页 > 解决方案 > 获取 RangeError:Protractor Typescript 自动化框架超过了最大调用堆栈大小

问题描述

这是我的 UI 自动化框架的结构。它是 Typescript 编译到 Protractor。

3 规格:

每个从页面对象、应用程序助手和框架助手导入

页面对象: 从助手导入函数。从应用程序助手导入函数。//评论这会产生奇迹并且不会引发错误

框架助手函数: 只是函数。

应用程序助手函数: 从助手导入函数。

我读到如果功能太多,就会发生这种情况。但这对于我的框架不会膨胀成混乱无法管理的代码是必要的。

如何避免这种情况?最佳实践是什么?

错误:

× encountered a declaration exception
      - RangeError: Maximum call stack size exceeded

再加上这么复杂的框架,

debugger;

只是行不通。

示例代码:

describe('My app', () => {
    debugger;
    let login = new LoginPage(),//Has a few functions
        dashboard = new DashboardPage(); //Has a few functions
    // myApp: myAppHelper = new myAppHelper();//Has a few functions. Called in all the page object files. If commented everywhere except 1 then works fine.

    //There are just 3 spec files and 3 page objects. No infinite loops anywhere and everything is quite straightforward.

    beforeEach(async () => {
        browser.ignoreSynchronization = true;
    });
    afterEach(async () => {
        await console.log("Step completed.")
    });


    it('open all admin pages', async () => {
        try {
            browser.pause();
            // await myApp.login();
            await login.loginToMyApp('UserID', 'Password');
            await browser.sleep(5000);
            // await dashboard.openAdminPurposes();
            await browser.sleep(5000);
            // await dashboard.openAdminmyAppProcesses();
            await browser.sleep(5000);
        }
        catch (error) {
            console.log("Open admin pages failed." + error);
        }
    });

应用程序助手

/**
 * A library of reusable functions that can be used across the abc.
 * Do NOT add any functions that are related to the automation framework.
 */
import { browser, by, WebElement, element } from 'protractor';
import { Helper } from './helper';
import { DashboardPage } from './page-objects/abc/dashboard-page';


export class myAppHelper {
    helper: Helper = new Helper();
    dashboardPage: DashboardPage = new DashboardPage();
    currentEnvironment: string = "beta";
    serverURL: string = this.setServerURL(this.currentEnvironment);
    subSt: string = "/v3/abc/view/";
    adminSt: string = "/v3/abc/admin/";
    URL: string = this.serverURL;

    setServerURL(env: string): string {
        if (env.toLowerCase() == "beta") {
            return this.serverURL = "https://beta-abcde.abc.com";
        }
        else {
            return this.serverURL = "https://abcde.abc.com";
        }
    }

    async login(): Promise<void> {
        await browser.get(this.URL);
    }

    async gotoDashboard(): Promise<void> {
        await browser.get(this.URL + this.subSt + "dashboard");
        await this.helper.compareText(this.dashboardPage.dashboardHeader, "Dashboard");
    }

    async gotoProjectsList(): Promise<void> {
        await browser.get(this.URL + this.subSt + "projects");
    }

    //Admin Pages
    async gotoAdminPurposes(): Promise<void> {
        await browser.get(this.URL + this.adminSt + "purposes");
    }

    }

    //The rest of the functions are application specific but you get the idea.
}

帮手

/**
 * A library of reusable functions that can be used across the framework.
 * Do NOT add any functions that are project/module specific.
 */
import { browser, WebElement } from 'protractor';


export class Helper {
    async enterText(aelement: WebElement, textToEnter: string): Promise<void> {
        await browser.sleep(1000);
        await aelement.sendKeys(textToEnter);
    }

    async click(aelement: WebElement): Promise<void> {

        try {
            await browser.sleep(1500);
            await aelement.click();
        }
        catch (error) {
            console.log("Error in click: " + error);
        }
    }

    async readText(element: WebElement): Promise<string> {

        var elementText = await element.getText().then(function(text) {
            console.log("ReadText is : " + text);
            return text;
        });
        return elementText;
    });
    }
}

标签: node.jstypescriptprotractorui-automation

解决方案


当我在不同位置签出同一个项目时,该错误自行解决。我不知道它是如何解决的。上一个位置的同一个项目仍然抛出错误。诡异的。有时,只是复制粘贴或在不同的地方签出同一个项目会有所帮助:)


推荐阅读