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

Javascript 使用构造函数的量角器页对象,javascript,constructor,protractor,pageobjects,Javascript,Constructor,Protractor,Pageobjects,我有这样的规格: 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.proto

我有这样的规格:

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运行它时,一切都非常好。现在我想使用Page对象,并在spec.js中只保留“test1”,这意味着构造函数“CreateApple”及其原型应该转到另一个文件。有人能告诉我我的新“页面对象”文件应该是什么样子吗??我得到了下面这样的东西,但我不工作:

规格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;