Solving the Problem of BDD Gen Manual Script Execution with Nodemon (NPM)
Mahesh Joshi
FMG Insurance | Guidewire Cloud | Passionate Automation Test Analyst | Driving Quality & Efficiency in Technology
Solving the Problem of Manual Script Execution with Nodemon
Title: Automatically Update Test Scripts with Nodemon
As a QA Engineer I want to automatically run a script whenever I update my test files So that I can ensure my tests are always up-to-date without having to run the script manually
Background:
When you are using BDD playwright in VS code( testing framework) , every time we update or add a BDD feature file, we need to manually run the bddgen script before running any tests. This manual step is time-consuming and prone to human error, as it can be easily forgotten, leading to outdated test scripts and potential test failures.
The Problem:
I tried various extensions to automate this process, but none of them worked as expected. The challenge was to find a reliable solution that could detect changes in our BDD feature files and automatically execute the bddgen script without any manual intervention.
The Solution:
After much research and experimentation, I finally found Nodemon, a tool that perfectly fits our needs. Nodemon automatically restarts applications when file changes are detected, making it an ideal solution for our problem.
What is Nodemon?
Nodemon is a tool that helps developers by automatically restarting their application when file changes are detected. It's particularly useful during development because it saves time and effort by eliminating the need to manually restart the application after every change.
In our case, we use Nodemon to watch for changes in our BDD feature files and automatically run a script (bddgen) to update our test scripts whenever a change is detected.
Acceptance Criteria:
Tasks:
领英推荐
Example Documentation Section:
Automating BDD Feature File Updates with Nodemon
To automate the execution of the bddgen file whenever a BDD feature file is updated or added, follow these steps:
Install Nodemon: Run the following command to install Nodemon as a development dependency:
npm install --save-dev nodemon
{
"watch": ["tests/features/**/*.feature"],
"ext": "feature",
"exec": "npm run bddgen",
"legacyWatch": true,
"env": {
"CHOKIDAR_USEPOLLING": "true"
}
}
Update Package Scripts: Add the following script to package.json:
"scripts": {
"bddgen": "npx bddgen",
"test": "npx bddgen && npx playwright test",
"watch-bdd": "nodemon"
}
Run Nodemon: Start Nodemon by running:
npm run watch-bdd
Verify Automation: Make changes to a BDD feature file and verify that Nodemon automatically executes the bddgen file. Check the logs for the following output:
[nodemon] clean exit - waiting for changes before restart
[nodemon] restarting due to changes...
[nodemon] starting `npm run bddgen`
?[nodemon] restarting due to changes...
[nodemon] starting `npm run bddgen`
> [email protected] bddgen
> npx bddgen
Troubleshooting: If Nodemon is not restarting, ensure that the watch path in nodemon.json is correct. If there are issues with file watching, try setting "legacyWatch": true and "CHOKIDAR_USEPOLLING": "true" in the env section of nodemon.json.
Web Developer
3 个月I'm interested
Passionate Automation Engineer , helping customers to accelerate their digital transformation journeys.Mentoring engineers,Helping engineers to get job through my networks ??
3 个月thanks for sharing