vitalets / playwright-bdd

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

Question: NX mono repo (with several apps) playwright BDD implementation not working #215

Open markov1983 opened 3 weeks ago

markov1983 commented 3 weeks ago

Hi, I am working on one project using NX and playwright and am having trouble implementing the playwright BDD.

  1. The project has 5 apps and one nx.json/package.json/tsconfig.base.json in the project root
  2. The project is using playwright.config.base.ts which is then used by other playwright.config.ts inside the apps folder

One of those 5 apps is subject to implementation with playwright BDD I have followed the guidelines on your website and example repo to try to make it work, but I can't do that.

a) When I run: npx nx run my app-bdd:e2e (all other apps are executed like that) the .feature-gen dir is generated with test inside but I am getting an error that no tests are found image

Also, as you can see the command that is executed contains the SRC part which is I guess forced somehow through NX which is then trying to search the tests in that folder. If I try to run manually the command without src part through CLI the tests starts with execution.

As for the project.json, this is how it looks like: image As you can see I did try to force the output so that it generates the tests inside src folder but that doesn't work

Unfortunately, I am not able to share other parts of the repo/code

b) when I try to run: the npm run test I get an error (Can't find Playwright config file ) and the targeted folder is always the workspace root and not the desired app root (even dough I do try to pass the --config flag "npx bddgen --tags '@todo' && npx playwright test --config apps/myapp/playwright.config.ts" inside test script

c) If I try to use "executor": "@nx/playwright:playwright", then I am getting an error that no options are found: image

If you can help maybe with some advice or tips on how to make it work that would be great, thank you for great work and BDD implementation :)

Some of the libs used:

    "@mands/nx-playwright": "0.6.3",
    "@nx/devkit": "16.10.0",
    "@nx/eslint-plugin": "16.10.0",
    "@nx/jest": "16.10.0",
    "@nx/js": "16.10.0",
    "@nx/next": "16.10.0",
    "@nx/playwright": "16.10.0",
    "@nx/react": "16.10.0",
    "@nx/storybook": "19.0.4",
    "@nx/vite": "16.10.0",
    "@nx/web": "16.10.0",
    "@nx/workspace": "16.10.0",
    "@pact-foundation/pact": "12.5.0",
    "@playwright/test": "1.45.3"
    "nx": "16.10.0",
    "playwright": "1.45.1",
    "playwright-bdd": "7.2.2",
markov1983 commented 3 weeks ago

Hey @vitalets I made some progress with the test execution, I was able to run the tests with @nx/playwright:playwright executor just by using the "config" option but I can not use any options like devServerTarget as I am getting that error: unknown option. Why is that happening? If possible I would like to use other options so that I can build app prior to text execution, etc.

vitalets commented 3 weeks ago

Hi @markov1983 I've updated playwright-bdd-example nx branch, please check-out does it work for you.

Looking at provided files, I think the possible issue is here:

      "options": {
        "config": "playwright.config.ts"
      }

Each project searches for playwright.config.ts in workspace root, but should use Playwright config from project root. Try the following setup:

"targets": {
  "bddgen": {
      "command": "bddgen",
      "options": {
        "cwd": "{projectRoot}"
      }
    },
  "e2e": {
      "executor": "@nx/playwright:playwright",
      "dependsOn": ["bddgen"],
      "options": {
        "config": "{projectRoot}"
      }
    }
markov1983 commented 2 days ago

Thx, a lot @vitalets and I apologize for the late reply, I was on vacation. I have managed to sort it out. It was my bad setup/config. Thank you for the answer.