Skip to content

Instantly share code, notes, and snippets.

@just-boris
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save just-boris/6de3603b64ec60c9978a to your computer and use it in GitHub Desktop.

Select an option

Save just-boris/6de3603b64ec60c9978a to your computer and use it in GitHub Desktop.
Page object proposal
function PageFactory(config) {
function Page(element) {
this.element = element;
this.config = config;
this.get = function(key) {
var item = config[key];
if(!item) {
throw new Error('No item named "'+key+'" provided')
}
if(typeof item === 'string') {
return this.element + item
}
if(item instance of Page) {
return item
}
}
};
return Page
}
var AvatarBlock = new PageFactory({
'picture': '.userpic',
'name': '.username',
});
var UserPage = new PageFactory({
'input': '.user_input_somewhere',
'avatar': new Repeater(new AvatarBlock('.user_ava')),
'avatarSelected': new AvatarBlock('.user_ava_selected'),
'button': '.user_button_type_submit'
});
var page = new UserPage(driver.findElement('.page_selector'))
page.input.sendKeys('hello');
page.button.click();
expect(page.avatar[3].name.getText()).toBe('a man');
expect(page.avatarSelected.name.getText()).toBe('a man');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment