Testing¶
End-to-end testing.
Essential reading¶
Setting up a testing environment¶
Please follow the Kartoza coding standards.
Testing prerequisites¶
The primary framework used is playwright.
Setting up playwright¶
Note: Playwright is installed locally on your device and NOT in the container.
Navigate to the playwright
directory, there are two other directories present:
1. ci-tests
2. staging-tests
Navigate to ci-tests
.
To install playwright
ensure you have Node.js installed.
Once Node.js
is installed, use npm
JavaScript package manager to install playwright
.
To install dependencies defined in package.json
file:
To install playwright browsers and OS specific dependencies:
Note:
- By default, it uses TypeScript(
*.ts
).
This command will install all the required browsers and other dependencies. The directory structure will be as follows:
Running tests¶
Note: To run tests locally ensure the Django project is being served up locally. For tests on staging/production, ensure the website is up.
By default, tests will run on three browsers in headless mode.
To run all tests:
To run a specific test file:
To run it in UI mode, one can add --ui
tag at the end.
To run a specific file in UI mode:
Test reports¶
To generate test reports:
Continuous integration testing¶
Use of continuous integration and playwright.
The CI for this project is present in the directory .github/workflows
in the build-and-test.yml
file.
The action builds and tests for and push or a pull request is made into the main repository.
It uses the template.test.env
file to set up the environment. Which is copied into a new file .env
while setting up the containers.
Testing the Django endpoint:
Running coverage tests:
On setting up and testing using playwright.
- Updates dependencies: Installs various dependencies required
- Installs exact dependencies for
ci
, continuous integration. - Installs the playwright browsers and its packages.
- Runs the playwright tests
Reports: It will generate a report as HTML document and it will be retained for 30 days if it is present in that directory
Staging tests¶
Setting up environment¶
Navigate to staging-tests
.
NixOS
If you are a NixOS user, you can set up direnv and then cd into this directory in your shell.
When you do so the first time, you will be prompted to allow direnv which you can do using this command:
This may take a while the first time as NixOS builds you a sandbox environment.
Non-NixOS
For a non-NixOS user(Debian/Ubuntu) set up your environment by the following commands.
Recording a test¶
There is a bash helper script that will let you quickly create a new test:
Usage: ./record-test.sh TESTNAME
e.g. ./record-test.sh mytest
will write a new test to tests/mytest.spec.ts
Do not use spaces in your test name.
Test files MUST END in .spec.ts
After recording your test, close the test browser.
You can then run your test by doing:
./run-tests.sh
The first time you record a test, it will store your session credentials in a file ending in
auth.json
. This file should NEVER be committed to git / shared publicly. There is a gitignore rule to ensure this.
Running a test¶
The report can be downloaded and shared.