Skip to content

Instantly share code, notes, and snippets.

@giovanettid
Last active November 9, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovanettid/2e5a6276c7c26cc3c5ec to your computer and use it in GitHub Desktop.
Save giovanettid/2e5a6276c7c26cc3c5ec to your computer and use it in GitHub Desktop.
todo page object webdriverio
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