-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Wait for XHR triggered by action #3976
Comments
Hi @sedenardi – did you try waiting for the network call before await page.click('h1');
await page.waitForResponse('https://example.com/resource'); API reference |
@arjun27 We did, and that does indeed work. However, we were trying to avoid making our tests dependent on the underlying routes that are being called to save the data. This isn't a complete show-stopper since our tests do depend on the URLs of pages. For What are the timing implications of using await Promise.all([
page.waitForResponse((resp: Response) => resp.url().includes(XHR_URL)),
page.click('h1')
]); |
Thanks @sedenardi. Yes, you're right about The promise.all pattern is better since the click triggers the action. |
I have had same requerments, that to wait for XHR request to resolve before proceeding further checks. I think |
|
I'm attempting to use playwright for e2e testing of our web application. One of the pages is a form input that automatically saves user input, using the
onBlur
event on the form<input>
s.The workflow we're testing is:
Playwright code:
The issue we're seeing is that after the page is reloaded with the original value. This is because
page.reload()
happens immediately, not waiting for the XHR request to initiate or resolve.We've tried to use
page.waitForLoadState
to detect and wait for network connections, but that hasn't worked.We realize that it may be because the XHR request isn't initiated by the time
page.waitForLoadState
is executed, so we're wondering if we're either not usingpage.waitForLoadState
properly, not using the appropriate API to wait for XHR requests, or what we're trying to do isn't possible (at least not out of the box) with playwright.Thanks for your help in advance.
The text was updated successfully, but these errors were encountered: