Wrap app in Playwright end to end tests #320
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this do?
This swaps out DC's integration test framework from Cypress to Playwright, as part of a larger idea to adopt Playwright across our team's apps and platforms. These consolidated tests could be stored in the [RDC Test Runner][https://github.com/nulib/rdc-test-runner] repository.
Integration tests and fixtures are located in the root
/test
directory.How to run the tests for the first time
Delete your
package-lock.json
file and the/node_modules
folder (to avoid any lingering Cypress artifacts)# Install new dependencies npm install
Test fixtures can be accessed by pointing the app to a Test Environment API.
NEXT_PUBLIC_DCAPI_ENDPOINT="https://dc-test-api.rdc-staging.library.northwestern.edu/api/v2"
Note the first time you run Playwright tests it may prompt you to download test browsers. Go ahead and accept when prompted.
To run more visual tests, try experimenting with:
For more info, view the docs: Playwright.
Run in VSCode
Experiment with the preferred workflow of generating and running tests directly within VSCode.
Prerequisites
Environments
This PR allows integration tests to be ran in different environments (local laptop dev, AWS dev, and within Github Actions). Default environment is local laptop dev, but you can easily adjust this by updating the
BASE_URL
in a local.env.local
file as noted above.Github Actions
Tests are configured to work with Github Actions and the workflow code lives here:
Test Fixtures
Test fixtures are a Playwright concept allowing Tests to be set up and customized in a flexible way, to test exactly what you want. In default tests, you're given the
page
object to assert upon:Fixtures are Typescript
class
es which contain some pre-configured UI or state within the page. You can make as many as you want, and pass them into your tests like:The idea is to not have to create kitchen-sink
beforeEach()
setup for a large suite of assertions. Check out some initial patterns in the following files./tests/fixtures/open-graph.ts
/tests/fixtures/search-page.ts