使用构造函数的量角器页面对象

Protractor Page Object using constructor

我有这样的规范:

describe('test', function() {
function CreateApple(type,color, width){
    this.type= type
    this.color=color;
    this.width=width;
}

CreateApple.prototype.eat= function(){
    return console.log("eat mniam, mniam");
}

CreateApple.prototype.height = 55;      

CreateApple.prototype.xxx={
        module1:  1,
        hhh: 2,

        tablice:{
            tab1: function(num){return num},
            tab2: 44,
        }
}

it('test1', function() {


    var apple1 = new CreateApple("goodone", "red", 34);
    apple1.eat();
        console.log(apple1.type);
        console.log(apple1.height);
        var ttt= apple1.xxx.hhh;
        var uuu= apple1.xxx.tablice.tab1(4);
        console.log(ttt+" "+uuu);

    });
});

当我 运行 使用我的 conf.js 时,一切都很好。现在我想使用页面对象并只在我的 spec.js 中留下 'test1',这意味着构造函数 'CreateApple' 及其原型应该转到另一个文件。谁能告诉我新的 'page object' 文件应该是什么样子的?我得到了类似下面的东西,但我没有工作:

spec.js

require('../jgh/page4.js');

describe('test', function() {

it('test1', function() {

var apple1 = new CreateApple("goodone", "red", 34);
apple1.eat();
    console.log(apple1.type);
    console.log(apple1.height);
    var ttt= apple1.xxx.hhh;
    var uuu= apple1.xxx.tablice.tab1(4);
    console.log(ttt+" "+uuu);

});
});

和我的page4.js

modules.exports =function CreateApple(type,color, width){
    this.type= type
    this.color=color;
    this.width=width;
}

CreateApple.prototype.eat= function(){
    return console.log("eat mniam, mniam");
}

CreateApple.prototype.height = 55;      

CreateApple.prototype.xxx={
       module1:  1,
       hhh: 2,

       tablice:{
           tab1: function(num){return num},
           tab2: 44,
        }
}

我得到:

Error: ReferenceError: CreateApple is not defined
var CreateApple = require('../jgh/page4.js');

describe('test', function() {

    it('test1', function() {
        var apple1 = new CreateApple("goodone", "red", 34);
        apple1.eat();
        console.log(apple1.type);
        console.log(apple1.height);
        var ttt = apple1.xxx.hhh;
        var uuu = apple1.xxx.tablice.tab1(4);
        console.log(ttt + " " + uuu);

    });
});

//------------------------------------------

function CreateApple(type, color, width) {
    this.type = type
    this.color = color;
    this.width = width;
}

CreateApple.prototype.eat = function() {
    return console.log("eat mniam, mniam");
}

CreateApple.prototype.height = 55;

CreateApple.prototype.xxx = {
    module1: 1,
    hhh: 2,

    tablice: {
        tab1: function(num) { return num },
        tab2: 44,
    }
}
modules.exports = CreateApple;