Skip to content

Commit

Permalink
Merge pull request #95 from lsst/tickets/PREOPS-5286
Browse files Browse the repository at this point in the history
PREOPS-5286: Add Playwright end-to-end tests
  • Loading branch information
alserene authored Jul 29, 2024
2 parents 757efb0 + c7ee2e6 commit 0faf5bc
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_and_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
shell: bash -l {0}
run: |
export RUBIN_SIM_DATA_DIR=~/rubin_sim_data
pytest -r a -v --cov=schedview --cov=tests --cov-report=xml --cov-report=term --cov-branch
python -m pytest -r a -v --cov=schedview --cov=tests --cov-report=xml --cov-report=term --cov-branch
- name: Upload coverage to codecov
uses: codecov/codecov-action@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ notebooks/MPCORB.DAT.gz
# Other temporary files
tmp/*
util/tmp/*
.vscode/settings.json
76 changes: 76 additions & 0 deletions docs/playwright_testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Playwright Testing
==================

Install playwright + browsers in environment
--------------------------------------------
`Install info <https://playwright.dev/python/docs/intro>`_

::

conda activate schedview
pip install playwright
playwright install # install browsers

Depending on your OS, you may also need to run:

::

playwright install-deps

Run (headless) tests
--------------------
Tests should be run from the root (where the tests are run during workflow).
The playwright tests are disabled by default, so, to run them, the environment variable ENABLE_PLAYWRIGHT_TESTS must be set.

::

ENABLE_PLAYWRIGHT_TESTS=1 pytest tests/test_scheduler_dashboard.py

Headed tests
------------
Tests will run in headless mode by default. If you would like to see the tests in action (headed), the tests must be run locally (where the LFA mode test will fail) or using NoMachine (or a supported equivalent).

`Instruction to set up NoMachine <https://s3df.slac.stanford.edu/public/doc/#/reference>`_

In the code, also comment/uncommment the following lines in each of the 3 classes' SetUpClass functions to swap to headed mode:

::

cls.browser = cls.playwright.chromium.launch(headless=True) # comment this out and uncomment the other lines
# cls.browser = cls.playwright.chromium.launch(
# headless=False,
# slow_mo=100
# )

Increase the 'slow_mo' parameter to slow the tests down (e.g. 500).

Debug tests
-----------
Visualise stepping through actions and assertions. Again, this needs to be run locally or using NoMachine.

`Docs <https://playwright.dev/python/docs/debug>`_

::

ENABLE_PLAYWRIGHT_TESTS=1 PWDEBUG=1 pytest -s tests/test_scheduler_dashboard.py

Note that when actions are taken that initiate the loading indicator + pop-up messages (e.g. load pickle, change date, reset dashboard), the assertions need to be stepped through very quickly or else the events will be missed and the test will fail. Be prepared for button mashing.

Test Generator
--------------
Generates testing code as you perform actions. Again, this needs to be run locally or using NoMachine.

`Docs <https://playwright.dev/python/docs/codegen>`_

Launch server from one terminal:

::

python schedview/app/scheduler_dashboard/scheduler_dashboard.py

Run test generator from another terminal:

::

playwright codegen http://localhost:8080/schedview-snapshot/dashboard

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ test = [
"isort",
"ruff",
"pytest-cov",
"geckodriver"
"geckodriver",
"playwright",
"pre-commit"
]
dev = [
"documenteer[guide]",
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ geckodriver
pre-commit
boto3
botocore
playwright
Loading

0 comments on commit 0faf5bc

Please sign in to comment.