Protractor Page objects - TypeError: Object #<Object> has no method 'methodName'

我怕爱的太早我们不能终老 提交于 2019-12-06 16:12:52

Try this:

Ensure you have the following in your LoginPage.js file

module.exports = LoginPage;

Add the missing new keyword

var LoginPage = require('./LoginPage.js');
var loginPage = new LoginPage();

After trying the above syntax (no success) I rewrote the page object using the Astrolable. Now it works! My test looks like this:

//pageobject
'use strict';
var env = require('./environment.js')

var LoginPage = function () {
  browser.driver.get('http://example.com');
};

LoginPage.prototype = Object.create({}, {

userInput:         {    get: function()    { return browser.driver.findElement(by.id('username'));}},
pwdInput:          {    get: function() { return browser.driver.findElement(by.id('password'));}},
btnEnter:          {    get: function()    { return browser.driver.findElement(by.id('btnLogin'));}},

setUser:           {     value: function (loginName) {
    this.userInput.sendKeys(loginName);        
}},

setPasswd: { value: function (loginPass) {
    this.pwdInput.sendKeys(loginPass);
}},

clickBtnEnter:    {    get: function()    { return this.btnEnter.click();}}    
});

module.exports = LoginPage;

Spec file:

'use strict';
var loginPage = require('./LoginPage.js');

describe('myApp', function() {
    var poLogin = new loginPage();

    it('should save contract config', function (){        
        poLogin.setUser('userid');
        poLogin.setPasswd('passwd');
        poLogin.clickBtnEnter;
    });
});

Now it is working fine. Thanks for answering.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!