-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: main
Are you sure you want to change the base?
Feat: Playwright setup #2500
Conversation
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.
I just realized / re-remembered that in the file structure, we have
so if it feels better to move everything in
I could do that. |
It would be nice if you could simply run:
And have that run the tests and output the results. In other words, overriding the |
|
||
|
||
def test_agency_card_flow(page: Page): | ||
page.goto("https://dev-benefits.calitp.org/") |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
This PR adds a service called
playwright
tocompose.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 ofpyproject.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)
First, create a
playwright/.env
file:Start the
playwright
service by running:and then open a terminal session in it by running:
docker exec -ti benefits-playwright-1 /bin/bash
where
benefits-playwright-1
is the name of the container you started with the first command.Set values you want the tests to use in
playwright/.env
, and then use the helper script to run the Playwright tests:(The tests will run as headless.)
The console output will hopefully tell you the tests passed, and you can view more output under
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