selenium-pageobject
A lightweight pageobject library for use with webdriverjs.
Read about pageobjects at Martin Fowler's bliki and Selenium's wiki.
Installation
npm install selenium-pageobject
Getting started
The primary classes are:
PageNavigator
- everything in the elements directory
The PageNavigator
provides methods to visit pages etc. The Element
and its derived classes are wrappers to elements on the web page.
You can directly use the elements to access things on the page like this:
var wd = elements = elements; var driver = pageNavigator = driver: driver ; pageNavigator;var cb = driver Byid'checkboxId';cb;
PageObjects (WIP)
There's no actual class that represents a PageObject, since these are the things you write to drive your site. So let's run through a quick example of what one might look like.
Start with modelling your UI, so mypagemodel.js
:
var By = By po = extend = poextend Element = poelementsElement; moduleexports = { ; { _super; thisusername = thisef; thispassword = thisef; thisloginButton = thisef; } return MyPageModel;}Element;
Now create your PageObject in mypage.js
:
var By = By MyPageModel = ; { this_ui = driver BytagName'html';} MyPageprototype { this_uiusername; this_uipassword; return this_uiloginButton;}; moduleexports = MyPage;
Now write your test in mypageTests.js
:
var chai = expect = chaiexpect wd = By = wdBy PageNavigator = PageNavigator MyPage = ; ;
Workflows
This is an experimental feature at the moment and may not make it into the final version
A Workflow
allows you to define a set of steps which it will then run through, you can define callbacks that occur on specific steps of the workflow.