获取RangeError:Protractor Typescript Automation Framework超出了最大调用堆栈大小

问题描述 投票:1回答:1

这是我的UI自动化框架的结构。它是针对量角器的Typescript编译。

3规格:

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

页面对象:从帮助程序导入函数。从应用程序助手导入函数。 //评论这可以创造奇迹并且不会抛出错误

Framework Helper功能:只是功能。

Application Helper函数:从helper导入函数。

我读到如果功能太多,就会发生这种情况。但是这对我的框架来说是必要的,以免陷入混乱的无法管理的代码。

怎么避免这个?什么是最佳做法?

错误:

× 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.js typescript protractor ui-automation
1个回答
0
投票

当我在不同的位置检出同一个项目时,错误自行解决。我不知道它是如何解决的。上一个位置的同一个项目仍在抛出错误。奇怪的。有时,只是复制粘贴或在不同的地方检查相同的项目只是帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.