Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser testing framework #277

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/browser-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Browser Test

on:
pull_request:

jobs:
browser-test:
runs-on: 'ubuntu-22.04'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: pip install -r requirements/test.txt
- run: pip install -r requirements/docs.txt
- run: pip install jupyterlab pytest-playwright
- run: pip install -e .
- run: playwright install firefox --with-deps # Install a browser
- run: nohup jupyter lab --NotebookApp.token='' --NotebookApp.password='' --no-browser & # Start a JupyterLab server
- run: pytest tests/applications/playwright_testing.py --browser firefox
38 changes: 38 additions & 0 deletions tests/applications/playwright_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
# This file does not have the suffix "_test" in its name.
# It is because these tests are excluded from the other unit tests
# and are used for testing the Playwright testing framework.
# One of blocker issues is that the playwright fixture holds on an event loop
# but some of other tests require a clean event loop.
import pytest
from playwright.sync_api import Page, expect

_EXPECTED_JUPYTER_LAB_ADDRESS = "http://localhost:8888/lab"


@pytest.fixture()
def jupyter_lab_running(page: Page) -> bool:
"""Skip tests if jupyter lab is not running in the background."""
try:
# Try opening the Jupyter Lab page.
page.goto(_EXPECTED_JUPYTER_LAB_ADDRESS)
except Exception as e:
page.close()
# Playwright does not have different error objects for different errors.
# And error messages differ from browser to browser/OS.
# So we skip all tests on any error going to the Jupyter Lab page.
pytest.skip(
f"Jupyter Lab is not running at {_EXPECTED_JUPYTER_LAB_ADDRESS}."
"Check if jupyter lab is running without TOKEN or PASSWORD"
"and the address is correct.\n"
f"Raised error: {e}"
)
return True


def test_jupyter_lab_server_available(jupyter_lab_running: bool, page: Page) -> None:
# Expect a title "to contain" a substring.
assert jupyter_lab_running
page.goto(_EXPECTED_JUPYTER_LAB_ADDRESS)
expect(page).to_have_title("JupyterLab")