Last active
November 9, 2015 19:51
-
-
Save scottrippey/158e013d2a33a54482bf to your computer and use it in GitHub Desktop.
addElementCommands ideas
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
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" }, | |
}); |
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
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 }) | |
; | |
}); |
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 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