'Object is not a function' 尝试将页面对象与量角器一起使用时出错
'Object is not a function' error when trying to use Page Object with Protractor
每次我尝试 运行 我的测试时,我都会遇到 TypeError: object is not a function。在我开始使用 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();
您 "export" 页面对象的方式有问题,应该是:
module.exports = todoAppPage;
每次我尝试 运行 我的测试时,我都会遇到 TypeError: object is not a function。在我开始使用 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();
您 "export" 页面对象的方式有问题,应该是:
module.exports = todoAppPage;