Skip to content
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

[Feature]: Native way to hard wait without page context #34073

Closed
KociPApplifting opened this issue Dec 18, 2024 · 1 comment
Closed

[Feature]: Native way to hard wait without page context #34073

KociPApplifting opened this issue Dec 18, 2024 · 1 comment

Comments

@KociPApplifting
Copy link

🚀 Feature Request

At the moment it is only possible to hard wait using page.waitForTimeout(); (to my knowledge).

I have tests that consist of several requests, where i need to wait few seconds for BE to catch up, before being able to send the next one. If i dont wait some of the requests will fail, since BE wasnt given enough time to process them.
Normally i would do something like:

  1. Request one is sent, effects of which take several seconds to change server state
  2. Wait 3 seconds, using await page.waitForTimeout();
  3. Request two is sent, passing because there was enough time between step 1 and 3
    However, since im only sending requests, there is no "page", therefore Playwright will fail on TypeError: Cannot read properties of undefined (reading 'waitForTimeout')

I would like to have the option to have hard coded wait no matter the context (like cy.wait() for Cypress)
Ofcourse if there is better way to handle my case than hard waiting i welcome it.

Example

Im using playwright-bdd package to be able to use Cucumber gherkin syntax for scenarios and Playwright for step definition, however that should not influence the essence of the example

Then('step definition name', async ({ page, request }) => {
    await wait(5000); <- This makes sure the request will pass even with slow backend

    const response = await request.post(`${process.env.API_URL}/requestURL`, {
        headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${global.globalData.authToken}`,
        }
    });
    expect(response.status()).toBe(200);
    const responseBody = await response.json();
    expect(responseBody.response).toHaveProperty('code', 200);
    expect(responseBody.response).toHaveProperty('status', 'Approved');
});

Motivation

I think there is lot of QAs that have no way to influence how quickly server state will change and simply need to use hard wait to make sure a request will be sent at the right time.

@pavelfeldman
Copy link
Member

You can always wait using setTimeout and promises (google it), but your test will be 100% flaky. The only way for you to work around it is to poll your server's health endpoint until you know it is live.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants