目前我正在使用量角器并使用页面对象,因此有一个文件可以获取变量中元素的值,但我需要在另一个文件中调用此值。
vehiclePage.js
<div class="row">
现在我需要在另一个文件中使用上述变量的值
checkoutPage.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();
如何让它发挥作用?
答案 0 :(得分:1)
如果您正在关注页面对象设计模式,我会说测试不应该在页面对象上。我会写这样的东西。
<强> 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());
});
});
答案 1 :(得分:0)
执行此操作的一种方法是将状态对象传递给两个页面。
<div class="main_comp">
<div class="bigimg">image</div>
<div class="bigimg">image</div>
<div class="blog_art new">blog art</div>
<div class="blog_art new">blog art</div>
<div class="blog_art new">blog art</div>
</div>
.new:not(:nth-child(2)) {
grid-column: auto / span 2;
grid-row: 2;
background: orange;
}
然后你可以从两个新页面操纵和访问状态。