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.

Can waitForResponse take a promise instead of function or url?

See original GitHub issue

Tell us about your environment:

  • Puppeteer version: 1.14
  • Platform / OS version: Windows
  • Node.js version: 10

What steps will reproduce the problem? try to pass a promise to await page.waitForResponse(response => condition) instead of urlOrPredicate.

What is the expected result? expect async function to work

What happens instead? no waiting as promise gets eval to truthy.

response object has text method which is a promise to use that i need callback to be promise as well… but if i make callback to be promise it breaks the waitForResponse function

Issue Analytics

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

github_iconTop GitHub Comments

25reactions
sourabhmozarkcommented, Jul 4, 2020

Hello Everyone, If you are an Appium tester and want to showcase your skills, here is an amazing opportunity for you! MOZARK’s online global app testing contest- QAppathon is now live! The contest is free to register, all you need to do is: • Sign up to MOZARK QAppAssure • Write an Appium script to measure the Home page load time of your app. • Run the script on at least 10 devices across the QAppAssure device cloud. • Ensure a minimum of 50 test runs. • Send in the logs and a brief description of your test methodology to aquamark-support@mozark.ai The first 10 testers to successfully complete the challenge will get an Amazon gift voucher worth INR 5k and MOZARK cloud vouchers worth INR 10k!

Register Now and be a MOZARK certified Appium tester

7reactions
techsincommented, Apr 24, 2019

i wanted to do response.text() which returns a promise. I wanted to return true or false based on what’s inside text(). can’t wait for promise to be resolved if original function isn’t promise based.

eventually had to go with page.on(‘response’…

        await (new Promise(function (resolve, reject) {
            let listener = async (response) => {
                let url = 'https://www.example.com/';
                if (url == response.url()) {
                    try {
                        let json = JSON.parse(await response.text());
                        if (json.data.abc) {
                            ...
                            page.removeListener('response', listener);
                            resolve();
                        }
                    } catch (error) {
                        console.log(error);
                    }
                }
            };
            page.on('response', listener);
        }));

Read more comments on GitHub >

github_iconTop Results From Across the Web

page.click function does not wait till page.waitForResponse ...
I would try the page.waitForNavigation() in your Promise.all() as mentioned in the docs for page.click() .
Read more >
Async and Await in JavaScript, the extension to a promise.
An async function simply implies that a promise will be returned and if a promise is not ... You cannot use the await...
Read more >
Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >
How to make JavaScript wait for a API request to return?
If no value is returned, it wraps the promise and resumes the normal execution. Await: It is used to wait for a promise...
Read more >
How to wait for and intercept a particular HTTP request in ...
Use a promise to wait for the correct HTTP response (remove the await ... don't wait for waitForResponse, but continue by omitting await...
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