vitalets / playwright-bdd

BDD testing with Playwright runner
https://vitalets.github.io/playwright-bdd/
MIT License
300 stars 35 forks source link

Error: Pickle step not found for step: I am login in my app (Since v6.0.1 ) #104

Closed jzaratei closed 7 months ago

jzaratei commented 7 months ago

Given export default defineConfig({

  ...
  project : {
      name: "login-chrome",
      testDir: defineBddConfig({
        outputDir: ".features-gen/login",
        importTestFrom: "page-objects/basePage.ts",
        paths: ["./features/login.feature"],
        require: ["page-objects/*.ts"],
        featuresRoot: "./features",
        verbose: true,
      }),
    },
    {
      name: "Regresion - Chrome",
      testDir: defineBddConfig({
        outputDir: ".features-gen/regression",
        importTestFrom: "page-objects/basePage.ts",
        paths: ["./features/todo.feature"],
        require: ["page-objects/*.ts"],
        featuresRoot: "./features",
        verbose: true,
      }),
      dependencies: ["login-chrome"],
   }
`
  @Given("I am login in myapp")
  async gotoApp() {
    await this.goto();
    await expect(this.loadingIcon).not.toBeVisible();
    await this.login.click();
  }`

When

I execute npx bddgen

Then

I get an error

Error: Pickle step not found for step: I am login in myapp
    at TestFile.findPickleStep (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:406:11)   
    at TestFile.getStep (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:316:29)
    at C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:279:16
    at Array.map (<anonymous>)
    at TestFile.getSteps (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:271:34)
    at TestFile.getBeforeEach (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:200:38)
    at TestFile.getSuiteChild (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:184:39)
    at C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:178:60
    at Array.forEach (<anonymous>)
    at TestFile.getSuite (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:178:22)
    at TestFile.getRootSuite (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:168:17)
    at TestFile.build (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\testFile.ts:116:15)
    at C:\myProjectUrl\node_modules\playwright-bdd\src\gen\index.ts:111:12
    at Array.map (<anonymous>)
    at TestFilesGenerator.buildFiles (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\index.ts:102:8)
    at C:\myProjectUrl\node_modules\playwright-bdd\src\gen\index.ts:44:12
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at withExitHandler (C:\myProjectUrl\node_modules\playwright-bdd\src\utils\exit.ts:30:12)
    at TestFilesGenerator.generate (C:\myProjectUrl\node_modules\playwright-bdd\src\gen\index.ts:41:5)
    at main (C:\myProjectUrl\node_modules\playwright-bdd\src\cli\worker.ts:12:3)

But I expect

test cases generated successfully.

Isolated demo

Environment

platform: win32
node: v20.11.1
playwright-bdd: v6.0.1
@playwright/test: v1.42.1
@cucumber/cucumber: v10.3.1
Playwright config file: playwright.config.ts
adamwood-novafori commented 7 months ago

Same here, I'm using Windows 11 Pro Node: v18.18.1 pnpm: 8.15.4 "@playwright/test": "^1.42.1" "playwright-bdd": "^6.0.1",

vitalets commented 7 months ago

Could you try to use windows backslashes "\" in paths in defineBddConfig?

adamwood-novafori commented 7 months ago

I just tried with my defineBddConfig like: const testDir = defineBddConfig({ importTestFrom: 'support\\fixtures.ts', paths: ['.\\features'], require: ['steps\\*.ts'], quotes: 'backtick', featuresRoot: '.\\features' });

Still got the same error and I ran bddgen successfully on version 5.8.0 with the above too so we know it's correct

vitalets commented 7 months ago

Got it! Could you also paste an output of 'npx bddgen --verbose'

adamwood-novafori commented 7 months ago

Sure here you go (I did swap back the slashes but can put back to windows style if needs be):

npx bddgen --verbose
Loading features from: ./features
Loading steps from: steps/*.ts
Loaded steps: 166
Loaded features: 20
C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\dist\gen\testFile.js:312
        throw new Error(`Pickle step not found for step: ${step.text}`);
              ^

Error: Pickle step not found for step: an authenticated Marketplace Operator
    at TestFile.findPickleStep (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:406:11)
    at TestFile.getStep (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:316:29)
    at C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:279:16
    at Array.map (<anonymous>)
    at TestFile.getSteps (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:271:34)
    at TestFile.getBeforeEach (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:200:38)
    at TestFile.getSuiteChild (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:184:39)
    at C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:178:60
    at Array.forEach (<anonymous>)
    at TestFile.getSuite (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:178:22)
    at TestFile.getRootSuite (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:168:17)
    at TestFile.build (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\testFile.ts:116:15)
    at C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\index.ts:111:12
    at Array.map (<anonymous>)
    at TestFilesGenerator.buildFiles (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\index.ts:102:8)
    at C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\index.ts:44:12
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at withExitHandler (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\utils\exit.ts:30:12)
    at TestFilesGenerator.generate (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\gen\index.ts:41:5)
    at async Promise.all (index 0)
    at Command.<anonymous> (C:\Users\Adam.Wood\Documents\Code\NextGenDemo.UI\test\node_modules\.pnpm\playwright-bdd@6.0.1_@cucumber+cucumber@10.3.1_@playwright+test@1.42.1\node_modules\playwright-bdd\src\cli\commands\test.ts:29:5)

Node.js v18.18.1
vitalets commented 7 months ago

Thank you @adamwood-novafori Looks like it's reproduced only on win. Lets do one more thing: could you clone and run playwright-bdd-example: https://github.com/vitalets/playwright-bdd-example And if it runs fine, try to run your project without decorator steps (if possible).

adamwood-novafori commented 7 months ago

Yeah might be windows being difficult as usual!

I've just tried it with the example project with npm and pnpm and it works fine.

Couldn't see much difference between the setup of that one and mine I even tried matching the same defineBddConfig and adding the tsconfig you had but still the same issue. Even tried changing the project structure to match the typical workplace with src and test directories but couldn't replicate it.

Edit: I just tried installing cucumber explicitly and not just as a peer but still no luck

My project uses playwright style with fixtures so no decorators.

hmmm 🤔

vitalets commented 7 months ago

@adamwood-novafori maybe start from another side: could you comment parts of your project to get it look like playwright-bdd-example?

jzaratei commented 7 months ago

hello, the problem seems to be the number of features to generate. I found out the maximum is 9 features to make it work, if I try with 10 I got the pickle error. Actually my project has 12 features in total.

jzaratei commented 7 months ago

hello, the problem seems to be the number of features to generate. I found out the maximum is 9 features to make it work, if I try with 10 I got the pickle error. Actually my project has 12 features in total.

Hello I though the problem was the number of features in total but actually, in my case, the problem is an specific feature with no scenarios (commented as TODO). If I delete that, then I am able to generate all the features. @adamwood-novafori try to delete 1 by 1 your feature until you get your project works.

adamwood-novafori commented 7 months ago

@jzaratei Nice find! I located my problem feature file and it's because I had a background step but my actual tests were commented out because of waiting for bug fixes.

So maybe that's what caused the problem, generating a playwright test when there's a background but no tests

jzaratei commented 7 months ago

@vitalets here you a branch where you could replicate the issue. https://github.com/jzaratei/playwright-bdd-example/tree/emptyFeature

vitalets commented 7 months ago

Reproduced it, preparing the fix.

vitalets commented 7 months ago

Fixed in 6.0.2. For feature without scenarios spec file will not be generated. @jzaratei @adamwood-novafori please re-check on your side and feel free to reopen in case of any issues. Thank you for your feedback!