简体   繁体   中英

How to wait an arbitrary amount of time in nightwatch.js without web browser interaction

I'm migrating my tests from Intern.js to Nightwatch.js and I'm sure it's not the recommended way of writing tests, but my tests asynchronously make browser command calls (my tests use a class that has its own command queue). The Nightwatch command queue can be empty sometimes depending on what's executing, but will eventually be populated. I need a way to manually tell Nightwatch when it's done, and just wait until then, otherwise the browser will close too early.

I can do something like this:

 finished() { let done = false; //will run at the end of my class's internal command queue this.command.then(() => { done = true; }); //will cause nightwatch to wait until my command queue is done this.browser.perform(doneFn => { const check = () => { if (done) { return doneFn(); } setTimeout(check, 10); } check(); }); }

But in that case perform() will time out after waiting 10 seconds, and I don't seem to be able to configure that. I could otherwise run a sequence of ~9 second perform() calls but it just sounds too hacky. I could rewrite to depend on nightwatch command queue instead, but that'd also be a lot more work to rewrite everything.

In the end it was easier to just switch to depending on using nightwatch's command queue instead. Anything that was just a .then() with Intern.js got changed to a .perform() in its various forms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM