Created
February 15, 2019 03:41
-
-
Save TuHuynhVan/10fc2aaffd7bf7dec343273502595856 to your computer and use it in GitHub Desktop.
WebdriverIO custom command to input value in fields those need to be focused first
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
/** | |
* From David Ridgley | |
* https://github.com/Arximiro | |
*/ | |
// Define a custom command | |
browser.addCommand('fillInput', function (el, val) { | |
browser.waitUntil(function () { | |
el.click(); | |
return el.isFocused(); | |
}, 5000, 'Input Timed Out', 200) | |
el.setValue(val); | |
}); | |
// Usage example | |
browser.fillInput(this.nameField, formData.name); | |
browser.fillInput(this.descriptionField, formData.description); | |
browser.fillInput(this.maxUsesField, formData.max_uses); | |
browser.fillInput(this.targetField, formData.target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out this still doesn't fix the problem of inputs sometimes getting filled too quickly and causing text to get cut off or end up in the wrong input. I changed it to this for now. Will update if I find a better way.
edit: The above gist should still work if your issue is just that you need an input to be focused before using setValue for whatever reason. My issue was inputs getting filled too quickly and sometimes some text would end up in the next input.