【发布时间】:2017-07-18 14:35:51
【问题描述】:
我有这样的规格:
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”及其原型应该转到另一个文件。谁能告诉我我的新“页面对象”文件应该是什么样子?我得到了类似下面的东西,但我不工作:
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
【问题讨论】:
-
你应该看看这个 - stackoverflow.com/questions/20534702/…
标签: javascript constructor protractor pageobjects