Add new playwright test for project creation flow#5687
Draft
Conversation
ea0f0b0 to
e4392a6
Compare
1 task
c7ea49a to
c0cf66e
Compare
Our project creation E2E test requires a user who can access the Staff Area Projects page, click on the 'Create a project' button, then navigate to the `ProjectCreate` and `ProjectCreated` views. This requires a logged-in user with the `StaffAreaAdministrator` and `ServiceAdministrator` roles. This commit adds a factory fixture, `login_context_for_user`, which creates a Playwright browser context that is already authenticated as a test user. This is based on the example in opencodelists (https://github.com/opensafely-core/opencodelists/blob/7de7c1a79d4695826e634fc3ae96b7b7a6960d4d/opencodelists/tests/functional/conftest.py#L37), but with some modifications for our current needs (we require users to have roles, and we don't need a user to be associated with an org). This allows a test to start in an authenticated state without going through the login UI, keeping the test focused on the project creation workflow.
c0cf66e to
94dbab4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #5621
Summary
This PR introduces a basic 'happy path' Playwright test for the project creation flow.
Context: Slack thread with discussion about how to structure the test and what to include.
WIP notes about the factory fixture to create a login context for the user:
I originally built the factory fixture
yield _login_context_for_userwith a variable in the outer function to keep track of multiple contexts in case we wanted this functionality in future, and used.close()to close the browser contexts we created at the end of a test. We don't use.close()in these opencodelists or airlock examples, but the example test in the Playwright documentation shows closing a new context that we have created once it's no longer needed, so I used it. Playwright also advises that we use.close()for any new contexts that we create ourselves (not the Playwright default).But then I changed my mind and paired the approach back:
.close(): I'm semi-confident (i.e. still somewhat unsure) the Playwright documentation on test isolation means that each test gets it's own browser, and therefore any browser contexts created will not be shared between tests; thus we can be reasonably confident that even if we don't implementcontext.close(), the contexts will not impact other tests in our test suiteQuestions:
context = browser.new_context(locale="en-GB")) in the factory fixture? Could we use the default context that Playwright gives us per test? We currently don't need multiple users, or multiple browser contexts.AOB
just test-functional --headed --slowmo 1000 tests/functional/test_project_creation.pyto see what's happening in the test;1000is the number of milliseconds to slow each Playwright operation down by