Open UncleGus opened 1 month ago
Interesting.. I've run your example and it shows correct location:
Possibly some Win vs OSX issue. Could you try to run pure Playwright test that throws such error?
Sure, I'll look into it further at my end.
When I open a different repo that does not use bddgen, just Playwright on its own, the error report points to the right place. So I don't think it's environmental/system, it's at the repo level. I'll carry on trying to isolate it.
I get the same result in both VSCode and IntelliJ IDEA.
Reinstalling node modules made no difference.
Setting up a new repo via npm init playwright@latest
and inserting an error reports it at the correct place.
Adding bdd-playwright to the same repo and generating a test spec file with it and adding the error points to the wrong place. Error occurs with both typescript and javascript.
I'm really at a loss now. Apart from sharing my actual system via a teams call or something, I'm not sure how to resolve this issue locally or reproduce this issue elsewhere.
Disabled WSL and Hyper-V, no change.
@UncleGus I've simplified playwright-bdd-example - kept only one step, removed cucumber reporter and added non-bdd project. Could you try to clone and run incorrect-fail-line
branch? Here is the PR to see the diff.
When I run npm t
I'm getting the following 2 errors:
Error: Fail in bdd test
at features/steps/index.ts:4
2 |
3 | Given("step", async ({}) => {
> 4 | throw new Error("Fail in bdd test");
| ^
5 | });
6 |
...
Error: Fail in non bdd test
2 |
3 | test("non bdd test", async ({}) => {
> 4 | throw new Error("Fail in non bdd test");
| ^
5 | });
6 |
npx playwright test --project non-bdd-project
.playwright.config.ts
and run npx playwright test --project non-bdd-project
again.Thank you for your investigation!
I'll have to get to that tomorrow, but I will say that I've added non-bdd tests to the actual project that I'm working in, and it reports errors at the correct line.
Okay, that didn't take as long as I though :P
Here's my output, and it's looking promising:
1) [bdd-project] › .features-gen\features\homepage.feature.spec.js:6:7 › Playwright Home Page › Check title › Given step
Error: Fail in bdd test
at features\steps\index.ts:4
2 |
3 | Given("step", async ({}) => {
> 4 | throw new Error("Fail in bdd test");
| ^
5 | });
6 |
at Object.<anonymous> (C:\dev\playwright-bdd-example\features\steps\index.ts:4:9)
at C:\dev\playwright-bdd-example\.features-gen\features\homepage.feature.spec.js:7:5
2) [non-bdd-project] › non-bdd\index.spec.ts:3:5 › non bdd test ──────────────────────────────────
Error: Fail in non bdd test
2 |
3 | test("non bdd test", async ({}) => {
> 4 | throw new Error("Fail in non bdd test");
| ^
5 | });
6 |
at C:\dev\playwright-bdd-example\non-bdd\index.spec.ts:4:9
2 failed
[bdd-project] › .features-gen\features\homepage.feature.spec.js:6:7 › Playwright Home Page › Check title
[non-bdd-project] › non-bdd\index.spec.ts:3:5 › non bdd test ───────────────────────────────────
Running the non-bdd project on its own got the same results for that test.
A colleague cloned the repo and had the exact same issue, so whatever the cause is, it's not specific to my laptop.
A colleague cloned the repo and had the exact same issue, so whatever the cause is, it's not specific to my laptop.
I will think how to debug that deeper. Is he also on win?
Given
Config:
Feature file:
Folders:
When
I added a line to throw an error in the steps definition file, and ran the test from the playwright test runner in VSCode, after running bddgen.
Then
The error was thrown and ended the test but the test-results reports the error in the wrong position:
But I expect
This is actually reasonably close, but in most non-artificially caused errors, it's out by 30-40 lines. Probably proportional to the line number. I expect it to point to where it actually failed. This offset also comes through in the playwright HTML report.
Isolated demo
https://github.com/vitalets/playwright-bdd-example/pull/21 In this case, the results point to a line past where it should, to a line that doesn't even exist: ![image](https://github.com/user-attachments/assets/c56b4ce4-8b7d-4787-9427-754c310b3c13) **Environment**