|
|
||
|---|---|---|
| .. | ||
| requirements | ||
| resources | ||
| scripts | ||
| src | ||
| AGENTS.md | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.js | ||
Podman Desktop Playwright Tests
This document contains information on how to use the E2E testing framework of Podman Desktop on different scenarios. This is particularly useful if you want to execute the tests from a Podman Desktop extension or you want to develop your own.
Prerequisites:
- Have Node.js 22 installed (ideally using
nvm) - Uses pnpm v10, can be installed via
npm install -g pnpm@10or you can get it here - Have a clone of the Podman Desktop repo (you can get it here)
Core functionality how the E2E tests works
Podman Desktop E2E tests use the Playwright testing framework libraries to develop the tests and POM (page object model) for the Podman Desktop application. The test runner also relies on playwright code.
At this moment the electron support is marked as experimental.
In order to be able to reuse and share the core e2e tests libraries and definitions we created @podman-desktop/tests-playwright npm package.
The project uses devDependency to @playwright/test for access to playwright function, assertions, etc., and also to an electron package, which brings the ability to run Podman Desktop application (which is electron based) when running e2e tests.
Running E2E tests in development or production mode
We distinguish between two operational modes to run the tests with: development and production. In both cases, we need to have access to Electron binary which is used to launch the Podman Desktop application. Above functionality is handled by @podman-desktop/tests-playwright Runner class (podman-desktop-runner.ts). The runner is then shipped as a Playwright fixture and takes care of all the setup for E2E tests.
Multiple scenarios may occur:
- Running E2E tests from
podman-desktoprepository in DEVELOPMENT mode: We do not need to set any paths to electron binary,Runneruses default configuration and grabs electron from/node_modules/.bin/electronwhich is installed via electron dependency postinstall script duringpnpm install. - Running E2E tests from
podman-desktoprepository in PRODUCTION mode: We need to setPODMAN_DESKTOP_BINARYenvironment variable when running the tests frompodman-desktoprepository with the previously built or downloaded Podman Desktop electron app. Simply point to apodman-desktopbinary or executable. - Running E2E tests in external repository in DEVELOPMENT mode: Set
PODMAN_DESKTOP_ARGSand point to the previously builtpodman-desktoprepository. We are using electron binary frompodman-desktoprepository the same way as in point 1. - Running E2E tests in external repository in PRODUCTION mode: Set
PODMAN_DESKTOP_BINARYenvironment variable and point to a downloaded/built Podman Desktop application which is also main electron binary that is used.
This approach is beneficial in the way that we do not need to have the electron package set as a dependency in external repositories.
If you set PODMAN_DESKTOP_BINARY and PODMAN_DESKTOP_ARGS at the same time, the runner will throw an error since you cannot really run tests in both mode at the same time.
You can get testing-enabled Podman Desktop binaries and installation files from testing-prereleases repository.
Usage of @podman-desktop/tests-playwright to develop the podman-desktop tests in the Podman Desktop repository
This section explains how to develop your own E2E tests in the Podman Desktop repository.
Steps:
- Get into the Podman Desktop repo folder (should be named
podman-desktop) - Install its local dependencies by executing
pnpm install - Build the application's tests with
pnpm test:e2e:build - Now you can implement your E2E tests in the
tests/playwrightfolder - Execute
pnpm test:e2ein order to run them - When the tests finish you will find the test artifacts and logs available under
./tests/playwright/output(this directory can be modified in theplaywright.config.tsfile)
Usage of @podman-desktop/tests-playwright in an external repository in DEVELOPMENT mode
This section explains how to add the npm package to a repository external to podman-desktop.
Steps:
- Get into the Podman Desktop repo folder (should be named
podman-desktop) - Install its local dependencies by executing
pnpm install - Implement your changes to the E2E tests library (optional)
- Build the application and tests with
pnpm test:e2e:build - Set an environment variable by executing:
export PODMAN_DESKTOP_ARGS="/path/to/podman-desktop"(the current directory) [¹][⁶] - Get into YOUR repository and update the
package.jsonfile to have the following contents:
- Under
devDependencies:"@podman-desktop/tests-playwright": "next",[²]"@playwright/test": "^1.48.1"(or the current latest)
- Under
scripts:"test:e2e:setup": "xvfb-maybe --auto-servernum --server-args='-screen 0 1280x960x24' --"[³]"test:e2e": "cross-env npm run test:e2e:setup npx playwright test tests/src"
- Execute
pnpm install, which should extract the contents of the previously built Podman Desktop into thenode_modulesfolder in your repository - Write your E2E tests on your repository, which may use your changes to
@podman-desktop/tests-playwrightfrom step 3 (optional) - Run your E2E tests by executing
pnpm test:e2e[⁵]
Running in e2e tests in PRODUCTION mode
- You can either a) download a prerelease binary from the testing-prereleases repository or b) compile the binary yourself by getting into the podman-desktop folder and executing
pnpm compile:current, which will produce apodman-desktopexecutable under/dist/linux-unpacked - Set an environment variable by executing:
export PODMAN_DESKTOP_BINARY="/path/to/the/podman-desktop/executable"[⁶] - Follow steps 6 to 9 from the previous section [⁴]
[¹] Remember that environment variables defined this way only work on the terminal they were defined and only for as long as the terminal is active.
[²] Using the value next works for running tests locally, but for remote executions, specify the latest version of the @podman-desktop/tests-playwright package. Check the “Versions” tab here to find the latest version. This version will be written into the pnpm-lock.yaml file; to ensure you use the latest version in the future, force an update with pnpm add -D @podman-desktop/tests-playwright@next (use the -w flag in monorepos to install at the workspace root).
[³] If your project does not already have the xvfb-maybe dependency, you'll need to add it as well.
[⁴] To verify that the PD binary is correctly being passed to the extension tests, you can check at the beginning of the running tests trace if the path is correct here: executablePath: /expected/path/to/podman-desktop/binary
[⁵] Currently in linux, running the tests with pnpm test:e2e does not open Podman Desktop (PD starts minimized in the tray). To see the tests running, execute the binary once you've executed pnpm test:e2e
[⁶] Alternatively to exporting the envvar, you can add it directly to the execution of the tests like this:
PODMAN_DESKTOP_ARGS="/path/to/podman-desktop" pnpm test:e2ePODMAN_DESKTOP_BINARY="/path/to/the/podman-desktop/executable" pnpm test:e2e
How to develop and test @podman-desktop/tests-playwright locally
This section references how to use @podman-desktop/tests-playwright generated archive file for local development
- Get into the Podman Desktop repo folder (should be named
podman-desktop) - Get into the
tests/playwrightfolder and install its local dependencies by executingpnpm install - Implement your changes to the E2E tests library (it can be found under
tests/playwright) - Create the local package with
pnpm run packagewhich also builds the code. This will produce a.tgzarchive - Set the environment variable by executing:
export PODMAN_DESKTOP_ARGS="path/to/podman-desktop"(not the current directory, two folders up) - In YOUR repository, update the
package.jsonfile to have the following contents underdevDependencies:"@podman-desktop/tests-playwright": "file:../podman-desktop/tests/playwright/podman-desktop-1.20.0-next.tgz" - Execute
pnpm install, which should extract the contents of the previously built Podman Desktop package into thenode_modulesfolder in your repository - Now, the changes you made to
@podman-desktop/tests-playwrightshould be available in your project. If the process was successful, you should be able to find the classes you added in theindex.d.tsfile undernode_modules/@podman-desktop/tests-playwright/dist - You might need to remove
node_modulesto force new installation