Skip to content

Add new playwright test for project creation flow#5687

Draft
KatieB5 wants to merge 5 commits intomainfrom
KatieB5/add-basic-playwright-test-for-project-creation
Draft

Add new playwright test for project creation flow#5687
KatieB5 wants to merge 5 commits intomainfrom
KatieB5/add-basic-playwright-test-for-project-creation

Conversation

@KatieB5
Copy link
Copy Markdown
Contributor

@KatieB5 KatieB5 commented Mar 13, 2026

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_user with 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).

new_context
Added before v1.9
Creates a new browser context. It won't share cookies/cache with other browser contexts.

note
If directly using this method to create BrowserContexts, it is best practice to explicitly close the returned context via browser_context.close() when your code is done with the BrowserContext, and before calling browser.close(). This will ensure the context is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.

But then I changed my mind and paired the approach back:

  • The brief in Create project form - test project creation flow #5621 is to write a basic Playwright test. The definition of basic is subjective, but I interpret this to mean keep the test as simple as possible, whilst providing sufficient coverage of the workflow under test
  • Multiple browser contexts: YAGNI - currently, the basic playwright test for the project creation workflow is a 'happy path' test requiring one user and one new context for that user; we aren't creating multiple contexts in one test that we need to track
  • .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 implement context.close(), the contexts will not impact other tests in our test suite

Questions:

  • Do we need to create a new context (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.
  • There is a (very small, I think) chance that we have a flaky assertion where we check Created at date. Should we implement control over the time/date in the test, or is the risk small enough that we don't need to do this?
  • Do we want to test that the correct breadcrumbs (title and link) are showing on each page the user sees or is this unecassary)?

AOB

  • Run just test-functional --headed --slowmo 1000 tests/functional/test_project_creation.py to see what's happening in the test; 1000 is the number of milliseconds to slow each Playwright operation down by
  • There are some other useful CLI options you can pass in listed here.

@KatieB5 KatieB5 force-pushed the KatieB5/add-basic-playwright-test-for-project-creation branch 2 times, most recently from ea0f0b0 to e4392a6 Compare March 16, 2026 16:36
@KatieB5 KatieB5 force-pushed the KatieB5/add-basic-playwright-test-for-project-creation branch 2 times, most recently from c7ea49a to c0cf66e Compare March 20, 2026 14:40
KatieB5 added 5 commits March 23, 2026 15:15
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.
@KatieB5 KatieB5 force-pushed the KatieB5/add-basic-playwright-test-for-project-creation branch from c0cf66e to 94dbab4 Compare March 23, 2026 15:16
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.

Create project form - test project creation flow

1 participant