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

Feat: Playwright setup #2500

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Feat: Playwright setup #2500

wants to merge 11 commits into from

Conversation

angela-tran
Copy link
Member

@angela-tran angela-tran commented Nov 4, 2024

This PR adds a service called playwright to compose.yml. Developers can use this container to run Playwright tests.

The base image of this service is a Microsoft-built image which includes Playwright and its dependencies already installed, thereby avoiding a long installation step for those.

This PR also includes a working test for running through the CST agency card flow on dev-benefits.calitp.org. You'll notice that we do install pytest-playwright into the devcontainer (line 41 of pyproject.toml) so that when viewing the test code in the devcontainer, we still have a nice developer experience.

Just to make this super clear: you should write Playwright tests in the devcontainer just as you would with writing application code and unit tests, but run Playwright tests from the playwright service container. The devcontainer does not have Playwright's dependencies and browsers installed in it.

Trying it out

(this is all outside of the devcontainer)

Run the tests with:

docker compose run --rm playwright

You can also start a terminal session in the playwright service by running:

docker compose run --rm playwright /bin/bash

and then you can run the tests and/or run other Playwright commands using that session.

(The tests will run as headless. This PR does not contain the setup for running in headed mode. That will come in a later PR.)

The console output will hopefully tell you the tests passed, and you can view more output under tests/playwright/test-results.

Small note about the test

I'm still learning the Playwright API, so note that there may be a better way to do what I'm doing with wait_for_timeout.

Helpful docs

use a base image that already has playwright and its browsers installed
add some test stubs, with one test that is a work-in-progress.

the devcontainer will have pytest-playwright installed so that when
we're writing tests, we can use auto-complete, reference code definition,
etc.

use the 'playwright' service container to run the tests. there is a sample
.env file and a helper script for running tests.
this makes it so they are used any time pytest is invoked from this
directory
this implements it in a simple way that works. there are probably
improvements that can be made, e.g. not waiting 10 seconds for the
enrollment to finish.

mark medicaregov flow test to be skipped.
since the tests-pytest workflow runs from the root level, it was also
collecting Playwright tests.
the tests-cypress workflow was failing because there is no .env file
for the playwright service, but we don't even need that service to
start.

this makes it so it is not started by default.
see https://docs.docker.com/compose/how-tos/profiles/ for more.
@angela-tran angela-tran self-assigned this Nov 4, 2024
@angela-tran angela-tran requested a review from a team as a code owner November 4, 2024 18:38
@github-actions github-actions bot added deployment-dev [auto] Changes that will trigger a deploy if merged to dev tests Related to automated testing (unit, UI, integration, etc.) docker Application container, devcontainer, Compose, etc. and removed deployment-dev [auto] Changes that will trigger a deploy if merged to dev labels Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits
  settings.py
  urls.py
  benefits/core
  context_processors.py
  models.py
Project Total  

This report was generated by python-coverage-comment-action

@angela-tran
Copy link
Member Author

I just realized / re-remembered that in the file structure, we have

tests/cypress
tests/pytest

so if it feels better to move everything in playwright in this PR to instead be under

tests/playwright

I could do that.

@thekaveman
Copy link
Member

It would be nice if you could simply run:

docker compose run playwright

And have that run the tests and output the results. In other words, overriding the entrypoint/cmd to call the run.sh script you created.



def test_agency_card_flow(page: Page):
page.goto("https://dev-benefits.calitp.org/")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you meant page.goto("/")?


set -e

base_url="https://dev-benefits.calitp.org"
Copy link
Member

Choose a reason for hiding this comment

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

Or maybe take this from the command line?

@angela-tran angela-tran marked this pull request as draft November 5, 2024 19:43
to ensure playwright service doesn't prevent other services from
starting if the `playwright/.env` file doesn't exist
keep the scope of this PR small. namely, this PR is for setting up the
environment in which we run and write tests.

figuring out if and how the tests get their values is a separate task
outside the scope of this PR.
@angela-tran angela-tran force-pushed the feat/playwright-setup branch 2 times, most recently from 922041b to 811c691 Compare November 21, 2024 19:22
@angela-tran
Copy link
Member Author

I've finished cleaning up this PR. I think it'd be good to go over this PR during our next dev workshop so will leave this in draft.

@angela-tran angela-tran linked an issue Nov 22, 2024 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Application container, devcontainer, Compose, etc. tests Related to automated testing (unit, UI, integration, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Figure out a way for developers to run Playwright easily
2 participants