Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap app in Playwright end to end tests #320

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

adamjarling
Copy link
Contributor

@adamjarling adamjarling commented Mar 28, 2024

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.

  • Removes Cypress and its artifacts
  • Sets up comprehensive tests for
    • General layout
    • Search page
    • Work page
  • Sets up Github Actions workflow
  • Establishes a pattern for Playwright Test Fixtures

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"
# Start local server (automatically points NEXT_PUBLIC_DCAPI_ENDPOINT to the test data API)
npm run dev:test-env

# If in AWS Dev Environment, set a BASE_URL environment variable in a .env.local file
BASE_URL="[YOUR_DEV_ID].dev.rdc.library.northwestern.edu"

# Start Playwright tests in headless mode
npm run test:playwright

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:

# Run in an interactive test browser to visually see tests run
npm playwright test --ui

# Run all tests in headed mode
npm playwright test --headed

For more info, view the docs: Playwright.

Run in VSCode

Experiment with the preferred workflow of generating and running tests directly within VSCode.

Prerequisites

image

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:

.github/workflows/playwright.yml

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:

test("renders something", async ({
    page,
  }) => { ...tests here }

Fixtures are Typescript classes 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:

test("renders something", async ({
    page,
    openGraphPage
  }) => { ...tests here }

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

@adamjarling adamjarling self-assigned this Mar 28, 2024
@adamjarling adamjarling marked this pull request as draft March 28, 2024 17:49
@adamjarling adamjarling force-pushed the 4284-playwright-setup branch 4 times, most recently from 67c4bf2 to c09224f Compare March 29, 2024 19:16
@adamjarling adamjarling marked this pull request as ready for review April 9, 2024 13:38
Copy link
Member

@mathewjordan mathewjordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 This is really great and should really help us in testing some of our more interactive screens. Just the note on the timeout, but otherwise lets roll.

playwright.config.ts Show resolved Hide resolved
@adamjarling adamjarling force-pushed the 4284-playwright-setup branch 4 times, most recently from f961967 to c6312a1 Compare April 25, 2024 21:30
@adamjarling adamjarling force-pushed the 4284-playwright-setup branch 9 times, most recently from efc9255 to 21ef5ec Compare July 18, 2024 14:17
@adamjarling adamjarling merged commit 584f4cb into deploy/staging Jul 18, 2024
3 checks passed
@adamjarling adamjarling deleted the 4284-playwright-setup branch July 18, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants