首页 > 解决方案 > call a function in another JS file -i have an error: gotoapp is undifined Please advise

问题描述

I'm having an error when calling goToApp function. The first page is the creation off the class and functions the second one is the other JS file

please advice

    //PO.js- a class I have created



   `class Kibana extends Page {
        constructor() {
            super();
            this._navigator = new KibanaNavigator();
        }

        async goToApp() {
            await this.openApp('DevOps Portal');
            await this.openApp('Kibana');
            // TODO replace with browser.wait();
            await browser.sleep(10000);
            const winHandles = await browser.getAllWindowHandles();
            await browser.switchTo().window(winHandles.pop());
        }

        async openDashboardPage() {
            await this._navigator.navigateTo('Dashboard');
            return new DashboardPage();
        }
    }

    //myFile.js -calling the gotoapp function 

    const Kibana = require('@vos/gallery/ui_page_objects/kibana.po.js');
    const kibana = new Kibana();`enter code here`

    await ui.kibana.goToApp();

标签: javascriptnode.jsfunction

解决方案


您必须导出您的课程才能从另一个文件中使用。

例子:

class Kibana extends Page { ... }

module.exports.Kibana = Kibana;

推荐阅读