This module provides TestCafe hooks executed once in a single browser even when you run tests in multiple browsers. This functionality is a workaround for the issue described in #1345.
The testcafe-once-hook module exports two functions:
oncePerFixtureruns in the first specified browser before and after all tests in a fixture. Unlike thefixture.beforeandfixture.afterhooks designed for server-side operations,oncePerFixtureallows you to execute test actions in the browser.oncePerTestruns in the first specified browser before and after each test in a fixture, while regularbeforeEachandafterEachhooks run in every browser.
This use case example does the following:
- Adds a record to a database with test actions (via the web interface);
- Runs tests in different browsers;
- Removes the record from the database with test actions (via the web interface).
This example uses express and lowdb.
/- shows the list of records from theJSONfile;/add- adds a new record to theJSONfile and redirects to the main page;/remove- removes a record from theJSONfile and redirects to the main page.
To start the project, execute the npm start command.
Go to the tests directory to see the examples.
Run the npm test command to start the project and run tests.