Last active
August 29, 2015 14:10
-
-
Save just-boris/6de3603b64ec60c9978a to your computer and use it in GitHub Desktop.
Page object proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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