From 97e7165f8e9b3212228008a302b208af9e86b4e3 Mon Sep 17 00:00:00 2001 From: Christian Vogt Date: Tue, 23 Jul 2024 13:37:52 -0400 Subject: [PATCH] document commands for cypress e2e tests --- docs/testing.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index aa92a62f71..240552e346 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -122,9 +122,41 @@ Hook specific assertions: ## Cypress Tests -Cypress is used to run tests against the frontend while mocking all network requests. +Cypress is used to run tests against the frontend by either mocking all network requests or directly interacting with a live cluster. -Single command to run all Cypress tests or a specific test (build frontend, start HTTP server, run Cypress): +### E2E Tests + +Cypress e2e tests run against a live cluster. + +Before running the Cypress e2e tests, you must populate the test variables by first creating a copy of the `test-variables.yml.example` file and setting the `CY_TEST_CONFIG` env variable value to be the path to this file. Update the variables according to your testing environment. + +```bash +CY_TEST_CONFIG=./test-variables.yml +``` + +Cypress e2e tests can make use of the `oc` command line tool. This is useful for test setup and tear down. When run in CI, the default user will be a cluster admin. +```ts +cy.exec(`oc new-project test-project`); +``` + +Prior to running the Cypress e2e tests, run `oc login` to login as a cluster admin to ensure the test env matches that of our CI and provides a default user for all `oc` commands executed in tests. + +To run all Cypress e2e tests, a specific test, or open the Cypress GUI: +```bash +npm run cypress:run + +npm run cypress:run -- --spec "**/testfile.cy.ts" + +npm run cypress:open +``` + +Use the custom command `cy.visitWithLogin` to visit a page and perform the login procedure steps if the user is not already logged in. The default user is not an ODH admin. `cy.visitWithLogin` can be used to login with different users by supplying the user auth configuration as a parameter. + +### Mocked Tests + +Cypress mocked tests run against a standalone frontend while mocking all network requests. + +Single command to run all Cypress mock tests or a specific test (build frontend, start HTTP server, run Cypress): ```bash npm run test:cypress-ci