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

[Bug]: Using test.fail() does not actually fail the test #30846

Closed
adrianmaciuc opened this issue May 16, 2024 · 2 comments
Closed

[Bug]: Using test.fail() does not actually fail the test #30846

adrianmaciuc opened this issue May 16, 2024 · 2 comments

Comments

@adrianmaciuc
Copy link

Version

1.40

Steps to reproduce

Set at the beginning of the test test.fail()

  1. Navigate to blog.martioli.com
  2. Expect that an element is visible

Expected behavior

Test should fail

Actual behavior

Test will pass

Additional context

test("The fail", async ({ page }) => {
  test.fail();
  await page.goto('https://blog.martioli.com');
  await expect(getByRole('link', { name: 'About' })).toBeVisible()
});

If I replace the expect with a click action, then the test will actually fail.

Environment

CPU: (4) x64 Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz
    Memory: 8.81 GB / 15.91 GB
  Binaries:
    Node: 18.19.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.89.1 - C:\Microsoft VS Code\bin\code.CMD
  npmPackages:
    @playwright/test: ^1.40.0 => 1.42.1
@mxschmitt
Copy link
Member

test.fail() will look at the test once it is completed. If it failed, then it will be considered passing. If it passes, it will be considered failing, since we expect it to fail.

See here: https://playwright.dev/docs/api/class-test#test-fail

So this looks like its working as expected.

@adrianmaciuc
Copy link
Author

I guess I misunderstood how this actually works. Thank you

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