【发布时间】:2016-11-24 05:18:09
【问题描述】:
我使用量角器编写了一个导出模块。它内部定义了多个功能。 现在,我想在同一个模块的另一个函数中调用其中一个导出函数。 我的模块如下所示。
module.exports = {
read_page_number_data: function {
// code here
},
read_page_data: function {
this.read_page_number_data().then(function () {
// Code here.
});
},
check_link_present: function {
// code here
},
click_link: function {
this.check_link_present().then(function () {
// Code here.
});
},
}
现在,当我在测试脚本中调用 read_page_data 函数时,出现以下错误。
失败:this.read_page_number_data 不是函数。
我已经尝试了以下问题中给出的所有选项。还是没有成功。
protractor calling an exported function within the same module
注意:在调用 read_page_data 函数之前,我正在调用 click_link 函数,该函数在内部调用 check_link_present 函数。但是这个调用工作正常,并且 check_link_present 函数可以从 click_link 函数正确调用。在此之后,控件导航到链接中给出的页面。
【问题讨论】:
-
您应该在前缀“this”。导出模块中的所有方法“read_page_number_data”。它应该像'this.read_page_number_data'
-
感谢@SureshSalloju 的回复。但是,当我给“这个”加上前缀时。在所有功能中,我得到以下错误 [21:33:56] I/launcher - 运行 1 个 WebDriver 实例 [21:34:01] E/launcher - 错误:C:\uiauto\lib\search_lib.js:4 this.enter_search_key_home_page: function (key) { ^ SyntaxError: Unexpected token .
-
你可以试试下面我的回答吗
标签: javascript protractor