javascript - 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();
解决方案
您必须导出您的课程才能从另一个文件中使用。
例子:
class Kibana extends Page { ... }
module.exports.Kibana = Kibana;
推荐阅读
- angular - 运行 npm run start 打开一个文件而不是指定的脚本
- java - AsynchronousJiraRestClientFactory 无法转换为 JiraRestClientFactory
- python - 如何在使用 Flask 和 WTForms 保留表单数据的同时进行重定向?
- c# - 将抽象类型对象转换为派生类型
- bixby - bixby:音频在选择页面上播放消息两次(模拟器)
- c++ - C++:指针元素向量是否会在销毁时自动释放每个指针指向的动态内存?
- java - 部署后的语言更改 - Android
- python - 如何将 python 库安装到拉取的 docker 映像中?
- c - 正则表达式在 C 语言中失败,在线测试通过
- python - 如何在不改变其结构的情况下更改 HTML 的文本