gpt4 book ai didi

javascript - 尝试将页面对象与 Protractor 一起使用时出现“对象不是函数”错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:45:26 25 4
gpt4 key购买 nike

每次尝试运行测试时,我都会遇到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();

最佳答案

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

module.exports = todoAppPage;

关于javascript - 尝试将页面对象与 Protractor 一起使用时出现“对象不是函数”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28708406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com