Setup
Importing the PageObject object
You can import the PageObject object using the import
construct as follows:
import PageObject from '../page-object';
The previous example assumes that your test file is one level deep under tests/
folder. e.g. tests/acceptance/login-test.js
.
The .create method
To create a new PageObject definition use the .create
method.
var page = PageObject.create({
// page attributes
});
You can define attributes using any JavaScript construct.
var page = PageObject.create({
title: function() {
return $('.title').text();
},
text: 'A text'
});
assert.equal(page.title(), 'My title');
assert.equal(page.text, 'A text');
There are many special attributes defined under the PageObject namespace that implement common patterns, for example, retrieving the text of an element.
var page = PageObject.create({
title: PageObject.text('.title')
});
The advantage of using this attribute for example is that it normalizes white spaces and trims the white spaces at both ends of the string. Like this attributes, there are many more that can help you write better page objects.