Created
July 21, 2017 16:38
-
-
Save alanshaw/61fb4432a91722eeee4d357d6643c268 to your computer and use it in GitHub Desktop.
Nightwatch commands for getting state of multiple elements
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
// Get state for multiple elements | |
// getState is passed an element and should return a promise that gets some state | |
// e.g. http://nightwatchjs.org/api#elementIdText | |
// Callback will be called with an array of the state values once they're all resolved | |
exports.command = function getElementsState (selector, getState, callback) { | |
this.elements('css selector', selector, function (elements) { | |
const values = elements.value.map(getState) | |
Promise.all(values).then(callback) | |
}) | |
return this | |
} |
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
// Get text for multiple elements | |
// Callback is called with an array of texts for the matching elements | |
exports.command = function getElementsText (selector, callback) { | |
const getState = (element) => { | |
return new Promise((resolve) => { | |
this.elementIdText(element.ELEMENT, (text) => resolve(text.value)) | |
}) | |
} | |
return this.getElementsState(selector, getState, callback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you also post sample test for these commands ?.