简体   繁体   中英

'Object is not a function' error when trying to use Page Object with Protractor

I've got a TypeError: object is not a function every time I try to run my tests. Before I started to use PageObject everything was ok.

Here is my spec.js

'use strict';

var todoAppPage = require('../pages/angular.page');

describe('angularjs todo list', function () {

    var page;

    beforeEach(function () {
        page = new todoAppPage();
        page.get();
    });

    it('should add a todo task', function () {
        page.addNewTask('my first task');

        expect(page.todoList.count()).toEqual(1);
        expect(page.todoList.get(0).getText()).toEqual('my first task'); 
    });
});

Here is Page Object file

'use strict';

var todoAppPage = function() {

    this.newTodo = element(by.model('newTodo'));
    this.todoList = element.all(by.repeater('todo in todos'));

    this.get = function() {
        browser.get('/');
    };

    this.addNewTask = function (taskName) {
        this.newTodo.sendKeys(taskName);
        this.newTodo.sendKeys(protractor.Key.ENTER);
    };
};

module.exports = new todoAppPage();

您“导出”页面对象的方式存在问题,应该是:

module.exports = todoAppPage;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM