Last active
February 17, 2018 11:04
-
-
Save Calamari/dbf647bb752ef630c91e810c4fa0f61d to your computer and use it in GitHub Desktop.
page helpers for async waiting
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 sleep = time => new Promise(resolve => { | |
setTimeout(() => resolve(), time) | |
}) | |
const waitUntilHidden = async (selector, timeout = 5000) => { | |
const endTime = Date.now() + timeout | |
while (document.querySelectorAll(selector).length && Date.now() < endTime) { | |
await sleep(100) | |
} | |
} | |
const waitUntil = async (selector, timeout = 5000) => { | |
const endTime = Date.now() + timeout | |
while (!document.querySelectorAll(selector).length && Date.now() < endTime) { | |
await sleep(100) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment