gpt4 book ai didi

javascript - 使用另一个文件中变量的值

转载 作者:行者123 更新时间:2023-12-03 04:30:02 25 4
gpt4 key购买 nike

目前我正在使用 Protractor 并使用页面对象,因此有一个文件可以获取变量中元素的值,但我需要在另一个文件中调用该值。

vehiclePage.js

/*jshint esversion: 6 */

var basePage = require('./basePage.js');
var homePage = require('./homePage.js');

var VehiclePage = function() {

this.storeVehicleData = function() {

this.pessengersRuntValue = element(by.id('preview_ocupantes_runt')).getText();
};
};

VehiclePage.prototype = basePage; // extend basePage...

module.exports = new VehiclePage();

现在我需要在另一个文件中使用上述变量的值

checkoutPage.js

/*jshint esversion: 6 */

var basePage = require('./basePage.js');
var homePage = require('./homePage.js');

var CheckoutPage = function() {

this.getRuntValue = element(by.css('.mb10'));

this.compareValues = function() {

expect(this.getRuntValue.getText()).toContain(this.pessengersRuntValue);
};

};

CheckoutPage.prototype = basePage; // extend basePage...

module.exports = new CheckoutPage();

我怎样才能让它发挥作用?

最佳答案

如果您遵循页面对象设计模式,我会说测试不应该在页面对象上。我会写这样的东西。

VehiclePage.js

var VehiclePage = function(){
// if this is a browser testing something like this
browser.get('/vehicle');
};

VehiclePage.prototype = Object.create({}, {
runt: {
get: function(){
return element(by.id('preview_ocupantes_runt'));
}
}
});
module.export = VehiclePage;

CheckOutPage.js

var CheckOutPage = function(){
// if this is a browser testing something like this
browser.get('/checkout');
};

CheckOutPage.prototype = Object.create({}, {
runt: {
get: function(){
return element(by.css('.mb10'));
}
}
});
module.export = CheckOutPage;

TheTest.js

var VehiclePage = require('VehiclePage');
var CheckOutPage = require('CheckOutPage');


describe('testing something', () => {
var vehicle = new VehiclePage();
var checkout = new CheckOutPage();

it('should contain', () => {
expect(checkout.runt.getText()).toContains(vehicle.runt.getText());
});

});

关于javascript - 使用另一个文件中变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43529936/

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