gpt4 book ai didi

javascript - 使用构造函数的 Protractor 页面对象

转载 作者:行者123 更新时间:2023-11-30 15:29:10 25 4
gpt4 key购买 nike

我有这样的规范:

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”及其原型(prototype)应该转到另一个文件。谁能告诉我新的“页面对象”文件应该是什么样子?我得到了类似下面的东西,但我没有工作:

规范.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;

关于javascript - 使用构造函数的 Protractor 页面对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42494930/

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