@ensono-stacks/playwright
Using the @ensono-stacks/playwright
plugin can help you get started with testing using playwright, with it's comprehensive feature set this plugin helps you capitalise on those features by accelerating your setup process and providing examples to get you started.
Additionally, if infrastructure has been generated through the @ensono-stacks/next:infrastructure
then Playwright E2E tests will be added to your pipelines!
tip
Visit the Frontend Testing in an Nx monorepo and Testing with Playwright user guides for more information!
Setting up @ensono-stacks/playwright
Install the @ensono-stacks/playwright
plugin with the following command:
- npm
- yarn
npm install --save-dev @ensono-stacks/playwright@latest
yarn add --dev @ensono-stacks/playwright@latest
Executors and Generators
To see a list of the plugin capabilities run the following command:
nx list @ensono-stacks/playwright
View additional information about a plugin capability through the following command:
nx g @ensono-stacks/playwright:[generator-executor-name] --help
Generators
@ensono-stacks/playwright:init
Create a playwright test project for your chosen application
The init generator creates a playwright project for the application you choose. Additionally it initialises your playwright project with additional stacks configuration and adds playwright tests to your pipeline if present.
Usage
nx g @ensono-stacks/playwright:init
Upon calling the init generator you will be presented with the following question:
- What app would you like to generate a test project for?
- The name of the existing application to generate a test project for (named <app-name>-e2e)
Command line arguments
The following command line arguments are available:
Option | Description | Type |
---|---|---|
--project | The name of the application to generate a test project for | string |
Generator Output
Default Output
The init generator will create a new test project for your chosen application containing an example test and predefined configuration for the monorepo and the individual test projects. By default the init generator will configure both a baseline playwright configuration and an individual project base playwright configuration.
.
โโโ apps
โ โโโ <app-name>-e2e
โ โ โโโ src
โ โ โ โโโ example.spec.ts #Example tests using playwright
โ โ โโโ playwright.config.ts #Example playwright configuration catering for multiple browsers and devices
โ โ โโโ project.json #Configuration for the project, including various NX targets
โ โ โโโ tsconfig.e2e.json #E2E typscript config file
โ โ โโโ tsconfig.json #typscript config file
โ โ โโโ .eslintrc.json #Linting configuration for the e2e project
โโโ playwright.config.base.ts
note
Visit the Testing with Playwright
documentation for further details!
@ensono-stacks/playwright:accessibility
Adds axe accessibility tests to your test project
The accessibility generator installs @axe-core/playwright
and configures an example accessibility test
Usage
nx g @ensono-stacks/playwright:accessibility
Command line arguments
The following command line arguments are available:
Option | Description | Type |
---|---|---|
--project -p | The name of the test project to add accessibility tests to | string |
Generator Output
Scaffolding accessibility testing will add two dependencies to the package.json
:
@axe-core/playwright
- The accessibility test engineaxe-result-pretty-print
- Result formatter
Additionally, an example accessibility test will be generated, showcasing how to utilise both axe and axe-result-pretty-print to scan your application for accessibility violations:
.
โโโ apps
โ โโโ <app-name>-e2e
โ โ โโโ src
โ โ โ โโโ axe-accessibility.spec.ts #Example accessibility test using playwright
โโโโโโโโโโโ
note
Visit the Accessibility Testing
documentation for further details!
@ensono-stacks/playwright:visualRegression
Adds native or cloud based visual regression to your test suite
The visualRegression generator provides you with the option to scaffold visual regression tests and configuration through a cloud based provider or Playwrights native visual comparison API.
Usage
nx g @ensono-stacks/playwright:visualRegression
Upon calling the visualRegression generator you will be presented with a number of options:
- What type of visual regression tests would you like to use?
- native: Generate visual regression tests using Playwrights native visual comparison api
- applitools: Generate visual regression tests using the
@applitools/eyes-playwright
plugin and scaffold an example visual regression test batch
Command line arguments
The following command line arguments are available:
Option | Description | Type | Accepted Values | Default |
---|---|---|---|---|
--project | The name of the existing playwright test app to enhance | string | ||
--visualRegression, -v | Method used to conduct visual testing | string | [choices: "native", "applitools"] | none |
Generator Output
Playwright with native visual comparisons
Opting to scaffold native visual testing will make a number of amendments to your test projects configuration:
- playwright.config.ts snapshot configuration: Configuration for your visual tests
- playwright-visual-regression.spec.ts: Sample test showcasing how to perform visual testing using playwrights native visual comparison api.
- project.json: Additional task set up to enable you to run your visual regression tests using the playwright:jammy container
.
โโโ apps
โ โโโ <app-name>-e2e
โ โ โโโ src
โ โ โ โโโ playwright-visual-regression.spec.ts #Example visual test using playwright
โโโ build
โ โโโ azDevOps
โ โ โโโ azuredevops-updatesnapshots.yaml #Pipeline to capture and update baseline images within the CI
โโโโโโโโโโโ
note
Visit the Playwright with visual comparisons
documentation for further details!
Playwright with Applitools Eyes
Opting to scaffold visual testing with applitools will make a number of amendments to your test projects configuration:
- @applitools/eyes-playwright: Dependency added to
package.json
- playwright.config.ts project configuration: Standalone project configuration to isolate visual tests with Applitools Eyes
- applitools-eyes-grid.spec.ts: Sample test showcasing how to perform visual testing using the Applitools Eyes Grid.
.
โโโ apps
โ โโโ <app-name>-e2e
โ โ โโโ src
โ โ โ โโโ applitools-eyes-grid.spec.ts #Example visual test using playwright
โโโโโโโโโโโ
note
Visit the Playwright with Applitools Eyes
documentation for further details!
Executors
@mands/nx-playwright:playwright-executor
Enables you to execute your playwright tests
The playwright-executor executor is a third party executor provided by @mands and enables you to run your e2e tests.
Usage
The following command will run all of the playwright tests within your e2e test folder, as part of the executor it will automatically spin up a web server on local host for the corresponding application.
nx e2e <app-name>-e2e
Command line arguments
See the @mands/nx-playwright plugin page for a list of up to date command line arguments