量角器:如何从其他文件访问函数?

时间:2017-12-05 09:35:47

标签: 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

这会抛出错误:'登录未定义'。 任何解决方案/想法? 感谢

1 个答案:

答案 0 :(得分:1)

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

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