Rayrun
← Back to Discord Forum

waitForResponse/Request

annessence
annessence

I was reading up on it in the docs, and found these 3 lines code:

// Start waiting for response before clicking. Note no await.
const responsePromise = page.waitForResponse('https://example.com/resource');
await page.getByText('trigger response').click();
const response = await responsePromise;```

I am fairly new and don't seem to understand this. Isn't in this case response being a unused variable?
image.png

This thread is trying to answer question "Isn't in this case response being a unused variable? Why is my test not always able to find the data inside a dropdown even after the waitForResponse is done?"

8 replies
annessence
annessence

Heres a screenshot incase the code above looks weird

welcome to async programming. setup a promise, invoke an action then wait for the completion.

annessence
annessence
@d3333333: I get that, but since I've called responsePromise inside response variable, it is not triggering right? Or am I misunderstanding it there?

I get that, but since I've called responsePromise inside response variable, it is not triggering right? Or am I misunderstanding it there?

annessence
annessence

do I not have to actually call it somewhere

timdeschryver
timdeschryver
@annessence: you can't see it in the example, but the `click()` invokes the HTTP request,

you can't see it in the example, but the click() invokes the HTTP request,

annessence
annessence
@timdeschryver: Okay, makes a bit more sense then

Okay, makes a bit more sense then

annessence
annessence

Though I'm still wondering why my test is still not able to find the data inside a dropdown even after the waitForResponse is done

annessence
annessence

Or atleast, not always, but quite some times

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.