每次尝试运行测试时,我都会遇到 TypeError:对象不是函数。在我开始使用PageObject之前一切正常。
这是我的 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');
});
});
这是页面对象文件
'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();
答案 0 :(得分:4)
“导出”页面对象的方式存在问题,应该是:
module.exports = todoAppPage;