-
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
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.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
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 |
playwright/test_agencycard_flow.py
Outdated
|
||
|
||
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("/")
?
playwright/run.sh
Outdated
|
||
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?
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.
922041b
to
811c691
Compare
further discussion is needed on how exactly we will pass environment-specific information to the tests.
811c691
to
694aeae
Compare
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. |
Closing this in favor of #2554 |
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)
Run the tests with:
You can also start a terminal session in the
playwright
service by running: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