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: failed test output points to wrong line in code #227

Open
UncleGus opened this issue Oct 4, 2024 · 15 comments
Open

Bug: failed test output points to wrong line in code #227

UncleGus opened this issue Oct 4, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@UncleGus
Copy link

UncleGus commented Oct 4, 2024

Given

Config:

import "dotenv/config";
import environments from "./config/environments.json";
import { defineConfig, expect } from "@playwright/test";
import { defineBddConfig } from "playwright-bdd";

const validEnvironments = Object.getOwnPropertyNames(environments);
const environmentErrorMessage = `Environment name not found. Edit .env in the root directory to set GALAXY=<environment name>, using one of the following options:
${validEnvironments}`;
expect(validEnvironments, environmentErrorMessage).toContain(
  process.env.GALAXY
);
console.log(`Using environment ${process.env.GALAXY}`);

const testDir = defineBddConfig({
  features: "tests/features/**/*.feature",
  steps: "tests/**/*.ts",
});

export default defineConfig({
  testDir,
  reporter: "html",
  use: { browserName: "chromium", viewport: { width: 1280, height: 880 } },
});

Feature file:

Feature: Automatic renewal of policy

Background:
  Given I am logged in to PolicyCenter as Super user
  And I am using an existing completed account
  And I have a policy
  And the policy type is Renewing
  And the term type is Annual
  And the policy expiration date is 10 days in the future
  And the policy has a coverage of type Milk

@PC_DF_014
Scenario: Policy renewal for Buildings and Contents
  Given the policy defined in the background
  When I start the batch renew process and return to the account summary

Folders:
image

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.
image

Then

The error was thrown and ended the test but the test-results reports the error in the wrong position:
image

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

Environment

Playwright-bdd environment info:

platform: win32
node: v20.12.1 
playwright-bdd: v7.4.2
@playwright/test: v1.47.2
@cucumber/cucumber: none
Playwright config file: playwright.config.ts
@UncleGus UncleGus added the bug Something isn't working label Oct 4, 2024
@vitalets
Copy link
Owner

vitalets commented Oct 4, 2024

Interesting..
I've run your example and it shows correct location:
image

Possibly some Win vs OSX issue. Could you try to run pure Playwright test that throws such error?

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

Sure, I'll look into it further at my end.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

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.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

I get the same result in both VSCode and IntelliJ IDEA.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

Reinstalling node modules made no difference.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

Setting up a new repo via npm init playwright@latest and inserting an error reports it at the correct place.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

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.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

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.

@UncleGus
Copy link
Author

UncleGus commented Oct 7, 2024

Disabled WSL and Hyper-V, no change.

@vitalets
Copy link
Owner

vitalets commented Oct 8, 2024

@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 |
  1. Also could you run only non-bdd-project npx playwright test --project non-bdd-project.
  2. And if it still produce incorrect line, comment all BDD-related stuff in playwright.config.ts and run npx playwright test --project non-bdd-project again.

Thank you for your investigation!

@UncleGus
Copy link
Author

UncleGus commented Oct 8, 2024

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.

@UncleGus
Copy link
Author

UncleGus commented Oct 8, 2024

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 ───────────────────────────────────

@UncleGus
Copy link
Author

UncleGus commented Oct 8, 2024

Running the non-bdd project on its own got the same results for that test.

@UncleGus
Copy link
Author

UncleGus commented Nov 7, 2024

A colleague cloned the repo and had the exact same issue, so whatever the cause is, it's not specific to my laptop.

@vitalets
Copy link
Owner

vitalets commented Nov 8, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants