javascript - 如何访问其他文件中的函数?

标签 javascript protractor pageobjects

这会引发错误:“登录未定义”。

//<Common.js>
var Common = function(){
this.login = function(uname,password){
    //All your code that you want to call from the test spec
    element(by.id('txtUserName')).sendKeys(login);
    element(by.id('txtPassword')).sendKeys(password);
    element(by.xpath('//input[@id="btnLogin"]')).click();

};
};

module.exports = new Common();

//<Test.js>
var newPage = require('./Common.js');

describe('The application', function() {

  it('should let you log into the application', function() {
         newPage.login('abcd', '1234');
 });
});


Failures:
1) The application should let you log into the application
  Message:
    Failed: login is not defined
  Stack:
    ReferenceError: login is not defined

最佳答案

将以下行中的“login”更新为“uname”

element(by.id('txtUserName')).sendKeys(uname);

关于javascript - 如何访问其他文件中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47650251/

相关文章:

javascript - 如何从 Protractor 中的表中收集和返回聚合数据作为数组?

java - 在使用页面工厂和 selenium webdriver 实现页面对象建模时,这两种方法中哪一种是更好的方法?

javascript - 我想让 arr[0][0] 显示从最大到最小,但在运行时显示类型错误 arr[i].sort();不是一个函数

javascript - 如何用 Protractor 捕获 ngToast?

angularjs - 当我有 Cucumber 和 Selenium 时,为什么还需要 Protractor?

ruby - 动态页面网址

java - Selenium 页面工厂 : initelements once per class?

javascript - 未捕获(在 Promise 中)DOMException : play() can only be initiated by a user gesture

javascript - 动态构造javascript对象

javascript - 来自 python dataframe 的 Google 图表无法绘制