this is a preview of a page object model that works independently of the browser driver.
page and component object define a hierarchy, and each of this objects expose a .s
property that has an absolute css selector to find the element (eg. using document.querySelector
),
the way that property is built is by space-concatenating the css selectors of it's ancestors.
var page = this.page('checkout');
// page.orderConfirmation.purchase.s === ['#main .order-confirmation', 'button.purchase-btn'].join(' ')
browserDriver.click(page.orderReview.purchase.s);
page and component objects receive a reference to the world
, so dom interaction code can be encapsulated in them.
var util = require('util');
var Component = require('./component');
function OrderReview(world){
Component.call(this, world);
this.at('#main .order-confirmation');
// children
this.purchaseButton = this.component().at('button.purchase-btn');
}
util.inherits(OrderReview, Component);
OrderReview.prototype.purchase = function(callback) {
var self = this;
this.browser
.waitForVisible(this.s)
// this.purchaseButton.s === '#main .order-confirmation button.purchase-btn"
.click(this.purchaseButton.s)
.call(callback);
};
the page:
var util = require('util');
var Page = require('./page');
function Checkout(world){
Page.call(this, world);
this.orderReview = this.component('order-review');
}
util.inherits(Checkout, Page);
module.exports = Checkout;
Now we can rewrite the first code block as:
this.page('checkout').orderReview.purchase();