Last active
November 9, 2015 21:57
-
-
Save giovanettid/2e5a6276c7c26cc3c5ec to your computer and use it in GitHub Desktop.
todo page object webdriverio
This file contains 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 TodoPage() { | |
'use strict'; | |
var idNew = '#new-todo'; | |
var title = 'title'; | |
var titleList = '#header > h1'; | |
var children = '#todo-list li'; | |
var childrenVisible = '#todo-list li:not(.hidden)'; | |
var nthChild = function(n) { | |
return children+':nth-child('+n+')'; | |
}; | |
var nthChildAndSelector = function(selector,n) { | |
return nthChild(n) + selector; | |
}; | |
var enterKey = function(selector) { | |
client = client.addValue(selector,'Enter'); | |
}; | |
var nthLabel = _.partial(nthChildAndSelector,' label'); | |
var nthInput = _.partial(nthChildAndSelector,' input.edit'); | |
var nthDestroyBtn = _.partial(nthChildAndSelector,' button.destroy'); | |
var nthCheckbox = _.partial(nthChildAndSelector,' input.toggle'); | |
var nthCompleted = _.partial(nthChildAndSelector,'.completed'); | |
var nthHidden = _.partial(nthChildAndSelector,'.hidden'); | |
var nthNotHidden = _.partial(nthChildAndSelector,':not(.hidden)'); | |
var options = { | |
desiredCapabilities: { | |
browserName: config.browser | |
} | |
}; | |
var client; | |
this.before = function() { | |
client = webdriverio.remote(options); | |
return client.init().url(config.url).execute('window.localStorage.clear();').refresh(); | |
}; | |
this.after = function() { | |
return client.end(); | |
}; | |
this.title = function() { | |
return client.getTitle(); | |
}; | |
this.titleList = function() { | |
return client.getText(titleList); | |
}; | |
this.typeNew = function(newTodo) { | |
client = client.setValue(idNew,newTodo); | |
return this; | |
}; | |
this.enterNew = function() { | |
enterKey(idNew); | |
}; | |
this.nbVisible = function() { | |
return client.isVisible(childrenVisible, function(err,res){ | |
return _.filter([].concat(res),function(isTrue) { | |
return isTrue; | |
}) | |
}); | |
}; | |
this.nthText = function(nth) { | |
return client.getText(nthLabel(nth)); | |
}; | |
this.mouseOverNth = function(nth) { | |
client = client.moveToObject(nthChild(nth)).moveToObject(nthDestroyBtn(nth)); | |
return this; | |
}; | |
this.deleteNth = function(nth) { | |
client = client.click(nthDestroyBtn(nth)); | |
}; | |
this.done = function(nth) { | |
client = client.click(nthCheckbox(nth)); | |
}; | |
this.nthCompleted = function(nth) { | |
return client.isVisible(nthCompleted(nth)); | |
}; | |
this.doubleClickNth = function(nth) { | |
client = client.moveToObject(nthLabel(nth)).doubleClick(nthLabel(nth)); | |
}; | |
this.editNth = function(nth,todo) { | |
client = client.addValue(nthInput(nth),todo); | |
return this; | |
}; | |
this.enterNth = function(nth) { | |
enterKey(nthInput(nth)); | |
}; | |
this.first = _.partial(this.nthText,1); | |
this.mouseOverFirst = _.partial(this.mouseOverNth,1); | |
this.deleteFirst = _.partial(this.deleteNth,1); | |
this.doubleClickFirst = _.partial(this.doubleClickNth,1); | |
this.editFirst = _.partial(this.editNth,1); | |
this.enterFirst = _.partial(this.enterNth,1); | |
} | |
module.exports = new TodoPage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment