diff --git a/src/session.js b/src/session.js index 1363185753..126112d7c7 100644 --- a/src/session.js +++ b/src/session.js @@ -201,4 +201,17 @@ module.exports = class RiotSession { close() { return this.browser.close(); } + + async poll(callback, timeout) { + const INTERVAL = 100; + let waited = 0; + while(waited < timeout) { + await this.delay(INTERVAL); + waited += INTERVAL; + if (callback()) { + return true; + } + } + return false; + } } diff --git a/src/usecases/signup.js b/src/usecases/signup.js index 2522346970..1f9605c30e 100644 --- a/src/usecases/signup.js +++ b/src/usecases/signup.js @@ -64,9 +64,11 @@ module.exports = async function signup(session, username, password, homeserver) //wait for registration to finish so the hash gets set //onhashchange better? - await session.delay(2000); - const url = session.page.url(); - assert.strictEqual(url, session.url('/#/home')); + const foundHomeUrl = await session.poll(() => { + const url = session.page.url(); + return url === session.url('/#/home'); + }, 5000); + assert(foundHomeUrl); session.log.done(); }