Search code examples
automationcucumberpackage.jsonplaywright

Need to run a specific feature file using the file's name (cucumber js integrated with playwright)


After successful integration of playwright with cucumber and typescript, I am able to run feature files all in one go by using command "npx cucumber-js". But I want to run a specific feature file.

Here is my package.json

{
  "name": "test-playwright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "cucumber-js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@cucumber/cucumber": "^9.5.0",
    "@playwright/test": "^1.37.1"
  },
  "dependencies": {
    "ts-node": "^10.9.1"
  }
}

And here is my cucumber.json

{
  "default": {
    "paths": ["src/features/**/*.feature"],
    "require": ["src/step-definations/*.ts", "src/support/hooks.ts"],
    "requireModule": ["ts-node/register"],
    "format": ["html:cucumber-report.html"],
    "publish-quite": true
  }
}

I have tried multiple commands but nothing works they all run all feature files present in src, some commands I tried are

  1. /node_modules/.bin/cucumber-js ./features/admin.feature. (give some sort of error)
  2. npx cucumber-js src/features/content-creator.feature. (runs all feature files)
  3. npm run test src\features\content-creators.feature. (runs all feature files)

Seems like I am missing some thing but can't sort it out

Here is my folder structure enter image description here


Solution

  • The method I found is to specify the unique file I want to run under paths

    {
      "default": {
        "paths": ["src/features/YourFeatureName.feature"],
        "require": ["src/step-definations/*.ts", "src/support/hooks.ts"],
        "requireModule": ["ts-node/register"],
        "format": ["html:cucumber-report.html"],
        "publish-quite": true
      }
    }