Created
March 27, 2022 15:56
-
-
Save sbolel/59561060b1fe3dcf45d52b1bd39493e9 to your computer and use it in GitHub Desktop.
Autofill forms for testing
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
| const setNativeValue = (element, value) => { | |
| const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set; | |
| const prototype = Object.getPrototypeOf(element); | |
| const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; | |
| if (valueSetter && valueSetter !== prototypeValueSetter) prototypeValueSetter.call(element, value); | |
| else valueSetter.call(element, value); | |
| element.dispatchEvent(new Event('input', {bubbles: true})); | |
| }; | |
| const setValue = (name, value) => setNativeValue(document.querySelector(`input[name="${name}"]`), `${value}`) | |
| const id = () => { | |
| const d = new Date(); | |
| return `${d.getMonth()}${d.getDay()}.${d.getHours()}${d.getMinutes()}${d.getSeconds()}`; | |
| } | |
| const example = () => { | |
| [ | |
| ['url', `${id}.website.com`] | |
| ['email', `${id}@email.com`] | |
| ['password', 'TestThis!l33t'] | |
| ].map(i => setValue.apply(null, i)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment