So i’ve come across a situation which may require the usage of Promise.all
(Which I haven’t used a ton, so im not 100% on it’s use).
Essentially in my Page Objects I have a method called open
that goes to the specific URL. In some cases due to this being an older website I need to do a waitForResponse/waitForRequest
to ensure the page is “in a good state” before I start operating on it.
I tried to put that in the open
method by default, since it’ll ensure the page is in a “ready” state after going to the site. Which looks like this:
async open() {
const responsePromise = this.page.waitForResponse("api/users/someUsersEndpoint")
await super.open("/users")
await responsePromise
}
Unfortunately for me, apparently adding an await
to this method will cause the top most call (the waitForResponse
call) to await
. Which in this case I actually do NOT want (Since I want to send the call first, then go to the url, THEN await the promise).
Unless there is a better way I think i’ll need to use Promise.all
. In that case does the order within Promise.all
matter? I would think the .open
would go first, then the waitForResponse
but im not 100% how it should be arranged.
Also….im assuming you can not mix non-async and async code in an async method? Especially if one of the methods returns a promise by default? (I assume it’ll wait for everything even if it doesn’t have an await?)