Skip to content

Instantly share code, notes, and snippets.

@scottrippey
Last active November 9, 2015 19:51
Show Gist options
  • Save scottrippey/158e013d2a33a54482bf to your computer and use it in GitHub Desktop.
Save scottrippey/158e013d2a33a54482bf to your computer and use it in GitHub Desktop.
addElementCommands ideas
browser.addElementCommands({
// There are multiple ways to define an element.
// Just a selector:
"profile_Table_": "#table",
// The selector is a function:
"profile_Table_": function getSelector(rowAndColumn){
return "//a[" + rowAndColumn.row + "] span[" + rowAndColumn.column + "]";
},
"profile_Table_": function(rowAndColumn) {
// and uses ES6 template:
return template("//a[${row}] span[${column}]", rowAndColumn);
},
// Or use an object to specify other options, like `type`
"profile_Table_": { selector: "#table" || function(){...}, type: "text" },
});
it("should whatever", function() {
return browser
.profile_Table_shouldExist({ row: 1, column: 2 })
.profile_Table_click({ row: 1, column: 2 })
.profile_Table_moveToObject({ row: 1, column: 2 })
.profile_Table_setValue(txt, { row: 1, column: 2 })
;
});
function getSelector(commandOptions, extraInfo) {
var selector;
if (commandOptions is a string or a function) {
selector = commandOptions;
} else if (commandOptions is object) {
selector = commandOptions.selector;
}
if (selector is function) {
selector = selector(extraInfo);
}
return selector;
}
browser.addCommand(commandName + "click", function(extraInfo) {
var selector = getSelector(commandOptions, extraInfo);
return this
.click(selector);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment