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]: timeout option for test.step #33475

Open
HardworkingSlacker opened this issue Nov 6, 2024 · 0 comments · May be fixed by #33560
Open

[Feature]: timeout option for test.step #33475

HardworkingSlacker opened this issue Nov 6, 2024 · 0 comments · May be fixed by #33560
Assignees
Labels
feature-test-runner Playwright test specific issues open-to-a-pull-request The feature request looks good, we are open to reviewing a PR v1.50

Comments

@HardworkingSlacker
Copy link

🚀 Feature Request

A new timeout option for test.step.
Optionally, step timeouts can be configured to be independant from the test timeout (like fixture timeouts).

Example

const timeoutFirstStep = 60_000;
const timeoutSecondStep = 30_000;
const timeoutExtra = 10_000;
test.setTimeout(timeoutExtra, {separateStepTimeouts: true})
test(`Steps with individual time limits`, async () => {
  await test.step(`abort test if this step takes longer than ${timeoutFirstStep} milliseconds`, async () => {
  // Do something that should not take more than 60 seconds to complete
  }, {timeout: timeoutFirstStep})
  await test.step(`abort test if this step takes longer than ${timeoutSecondStep} milliseconds`, async () => {
  // Do something else that should not take more than 30 seconds to complete
  }, {timeout: timeoutSecondStep})
})
// Even though it has a timeout of 10 seconds, test runs for up to 90 seconds because of separateStepTimeouts: true

Motivation

We have test cases where different steps aren't supposed to take more than x seconds to complete.
They belong to the same test case, so splitting them up into individual tests is very cumbersome.
expect.toPass is the goto workaround but then you need to dynamically adjust the test.setTimeout value when using dynamic timeout values and it looks kind of ugly.

const timeoutFirstStep = 60_000;
const timeoutSecondStep = 30_000;
const timeoutExtra = 10_000;
test.setTimeout((timeoutFirstStep+timeoutSecondStep+timeoutExtra));
test(`Steps with individual time limits`, async () => {
  await test.step(`abort test if this step takes longer than ${timeoutFirstStep} milliseconds`, async () => {
    await expect(/*Operation limited to 60 seconds*/).toPass({timeout: timeoutFirstStep, intervals: []})
  })
  await test.step('abort test if this step takes longer than ${timeoutSecondStep} milliseconds', async () => {
    await expect(/*Operation limited to 30 seconds*/).toPass({timeout: timeoutSecondStep, intervals: []})
  })
})

A timeout option for test.step would be prettier and simpler to use.

@yury-s yury-s added open-to-a-pull-request The feature request looks good, we are open to reviewing a PR feature-test-runner Playwright test specific issues v1.50 labels Nov 6, 2024
yury-s added a commit to yury-s/playwright that referenced this issue Nov 12, 2024
@yury-s yury-s linked a pull request Nov 12, 2024 that will close this issue
@yury-s yury-s self-assigned this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-test-runner Playwright test specific issues open-to-a-pull-request The feature request looks good, we are open to reviewing a PR v1.50
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants