Skip to content

Commit 59d454c

Browse files
author
SilviaAmAm
committed
📝 [#172] docs: Document running E2E tests
1 parent 3ea6816 commit 59d454c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

docs/developers/setup-local-environment.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,52 @@ Next Steps
138138
----------
139139

140140
- Refer to :doc:`environment-variables` for a complete breakdown of required configuration.
141+
142+
Running end-to-end tests
143+
========================
144+
145+
The E2E tests use pytest instead of the Django test framework (based on unittest). They make use of the libraries
146+
``pytest-django`` and ``pytest-playwright``.
147+
148+
We currently use the ``sync`` interface of Playwright, which is a wrapper around the ``async`` API that abstracts
149+
``asyncio`` usage. Since under the hood Playwright remains asynchronous, it needs to be run with the environment variable
150+
``DJANGO_ALLOW_ASYNC_UNSAFE=yes`` (see `this issue`_ for more details).
151+
152+
.. _this issue: https://github.com/microsoft/playwright-pytest/issues/29
153+
154+
To run the tests locally, you first need to build the frontend. This can be done
155+
with the script ``backend/bin/setup_e2e.sh``. This will build the frontend with the environment
156+
variable ``MYKN_API_URL=""`` and then symlink the ``index.html`` and the javascript/css assets into the templates
157+
and the static folders of the backend respectively. You can skip the building step with the environment variable ``SKIP_BUILD=yes``.
158+
159+
Then, set the environment variable ``E2E_TESTS=yes``. This will tell the backend to use the ``index.html`` as
160+
the template on the root page instead of the ``master.html``.
161+
162+
Finally, run the e2e tests from the ``backend/`` folder with (possible browsers are ``firefox|chromium|webkit``):
163+
164+
.. code:: bash
165+
166+
pytest -k e2e --headed --browser=firefox src/
167+
168+
TL;DR
169+
-----
170+
171+
#. From ``backend/``, run ``./bin/setup_e2e.sh``.
172+
#. Set environment variables ``E2E_TESTS=yes`` and ``DJANGO_ALLOW_ASYNC_UNSAFE=yes``.
173+
#. Run tests from ``backend/`` with ``pytest -k e2e --headed --browser=firefox src/``.
174+
175+
Adding tests
176+
------------
177+
178+
Make sure that the tests are decorated with ``@pytest.mark.e2e``:
179+
180+
.. code:: python
181+
182+
import pytest
183+
184+
@pytest.mark.e2e
185+
def test_some_feature(page, runner):
186+
...
187+
188+
189+
This marker is used to discover all the E2E tests.

0 commit comments

Comments
 (0)