question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to wait for several responses that differs only with body?

See original GitHub issue

After clicking button multiple requests to GraphQL are made. URL is the same, only body is different. I tried the following:

async uploadFile() {
    const [fileChooser] = await Promise.all([
        this.page.waitForEvent('filechooser'),
        this.page.click(this.elements.csvInput)
    ]);
    await fileChooser.setFiles('./resources/upload_findings.csv');
    await this.page.click(this.elements.uploadButton);
}

async function waitForFindingUpload(page, findingName) {
    return await page.waitForResponse(async (response) => {
        let body = await response.text();
        return body.includes(findingName)
    }, {
        timeout: 10000
    });
}
const [response1, response2] = await Promise.all([
    waitForFindingUpload(page, "Name of Finding 1"),
    waitForFindingUpload(page, "Name of Finding 2"),
    uploadFindingsPage.uploadFile()
])

These response1, response2 are both either “Name of Finding 1” or “Name of Finding 2”. I can not get both responses. How can I do this ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
GetafixITcommented, Aug 12, 2021

Would rather use async/await but this seems to work on a graphql query for the time being:

await this.page.waitForResponse((resp) => {
      return resp.text().then((body) => {
        return body.indexOf("someTextFromTheResponseBody") > -1;
      });
    });
4reactions
dgozmancommented, Apr 14, 2021

I think the issue here is that waitForResponse does not support an async predicate. So it treats the returned promise as truthy, and always returns the response that comes first, for both waitForResponse calls. We should fix that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress: Stub response for same route with three different ...
When the dashboard page is loaded, we trigger 3 concurrent AJAX POST requests with different actions. Even if we write response as a...
Read more >
Create approval flows with custom responses - Power Automate
Select Custom Responses - Wait for one response. Approval type. Next, you will create the custom responses that your approvers will use when ......
Read more >
What Are Frontotemporal Disorders? Causes, Symptoms, and ...
Speak slowly and clearly, use simple sentences, wait for responses, and ask for clarification if needed. Work with a speech-language pathologist ...
Read more >
Federal Employees' Compensation Act — Frequently Asked ...
The following "Frequently Asked Questions" (FAQs) are a supplement to ... There are several of these detailing the different sorts of documentation to...
Read more >
Ask the Experts: Administering Vaccines
If I need to give more than 1 injection in a muscle, are certain vaccines best given at different anatomic sites? Since DTaP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found