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

Use pytest-playwright #2185

Draft
wants to merge 2 commits into
base: 0.4.x
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:

- name: Run the tests
if: ${{ ! startsWith(runner.os, 'Linux') }}
run: BETTY_TEST_SKIP_SHELLCHECK=true BETTY_TEST_SKIP_RUFF=true BETTY_TEST_SKIP_MYPY=true BETTY_TEST_SKIP_STYLELINT=true BETTY_TEST_SKIP_ESLINT=true BETTY_TEST_SKIP_PLAYWRIGHT=true ./bin/test
run: BETTY_TEST_SKIP_SHELLCHECK=true BETTY_TEST_SKIP_RUFF=true BETTY_TEST_SKIP_MYPY=true BETTY_TEST_SKIP_STYLELINT=true BETTY_TEST_SKIP_ESLINT=true ./bin/test
shell: bash

- name: Upload code coverage
Expand Down
8 changes: 8 additions & 0 deletions betty/test_utils/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import TYPE_CHECKING

import pytest
from playwright.async_api import async_playwright, Playwright

from betty.app import App
from betty.cache.file import BinaryFileCache
Expand All @@ -40,3 +41,10 @@ async def new_temporary_app() -> AsyncIterator[App]:
"""
async with App.new_temporary() as app, app:
yield app


@pytest.fixture(scope="session")
async def playwright() -> AsyncIterator[Playwright]:
pw = await async_playwright().start()
yield pw
await pw.stop()
2 changes: 1 addition & 1 deletion betty/tests/project/extension/cotton_candy/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,4 @@ async def test_build_private_file(self, new_temporary_app: App) -> None:
DEFAULT_LOCALIZER,
).build()

assert actual == []
assert actual == []
35 changes: 35 additions & 0 deletions betty/tests/project/extension/cotton_candy/test_search_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from playwright.async_api import expect, Page

from betty import serve
from betty.ancestry.person import Person
from betty.ancestry.person_name import PersonName
from betty.project import Project
from betty.project.extension.cotton_candy import CottonCandy


class TestSearch:
@pytest.mark.asyncio(loop_scope="session")
async def test(self, page: Page) -> None:
# @todo Finish this
raise AssertionError
person_id = "I0001"
person = Person(id=person_id)
person_individual_name = "Janet"
PersonName(individual=person_individual_name, person=person)
async with Project.new_temporary(new_temporary_app) as project:
await project.configuration.extensions.enable(CottonCandy)
project.ancestry[Person].add(person)
async with (
project,
await serve.BuiltinProjectServer.new_for_project(project) as server,
):
page.goto(server.public_url)
search_query = page.locator("#search-query")
search_query.fill(person_individual_name)
search_query.press("ArrowDown")
expect(page.locator("#search-results")).to_be_visible()
page.keyboard.press("ArrowDown")
page.locator(":focus").press("Enter")
assert page.url == f"{server.public_url}/person/{person.id}/index.html"
page.close()
1 change: 0 additions & 1 deletion bin/build-ci
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pip install '.[ci]'
# Install JavaScript dependencies.
npm install
npm install --no-save "@types/node@$(node -e 'console.log(process.versions.node.split(".")[0])')"
npx playwright install --with-deps
3 changes: 0 additions & 3 deletions bin/build-dev-npm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ cd "$(dirname "$0")/.."
# Install JavaScript dependencies.
npm install
npm install --no-save "@types/node@$(node -e 'console.log(process.versions.node.split(".")[0])')"
# Install Playwright browser dependencies, but allow those
# to fail as Playwright runs on very few systems only.
npx playwright install --with-deps || true
3 changes: 3 additions & 0 deletions bin/build-dev-pip
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ cd "$(dirname "$0")/.."

# Install Python dependencies.
pip install -e '.[development]'
# Install Playwright browser dependencies, but allow those
# to fail as Playwright runs on very few systems only.
playwright install --with-deps || true
2 changes: 1 addition & 1 deletion bin/fix
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ruff format .
./node_modules/.bin/stylelint --fix "./betty/**/*.css" "./betty/**/*.scss"

# Fix JS code style violations.
./node_modules/.bin/eslint --fix -c ./eslint.config.js ./betty ./playwright
./node_modules/.bin/eslint --fix -c ./eslint.config.js ./betty
3 changes: 0 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,4 @@ if [ -z "${BETTY_TEST_SKIP_ESLINT-}" ]; then
./bin/test-eslint
fi
./bin/test-pytest
if [ -z "${BETTY_TEST_SKIP_PLAYWRIGHT-}" ]; then
./bin/test-playwright
fi
./bin/test-build-setuptools
2 changes: 1 addition & 1 deletion bin/test-eslint
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ cd "$(dirname "$0")/.."

echo 'Running ESLint...'

./node_modules/.bin/eslint -c ./eslint.config.js ./betty ./playwright "$@"
./node_modules/.bin/eslint -c ./eslint.config.js ./betty "$@"
9 changes: 0 additions & 9 deletions bin/test-playwright

This file was deleted.

2 changes: 0 additions & 2 deletions documentation/development/betty/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Helpful commands
Run `ESLint <https://eslint.org/>`_ tests.
``./bin/test-mypy``
Run `mypy <https://www.mypy-lang.org/>`_ tests.
``./bin/test-playwright``
Run `Playwright <https://playwright.dev>`_ tests.
``./bin/test-pytest``
Run `pytest <https://docs.pytest.org/en/stable/>`_ tests.
``./bin/test-ruff``
Expand Down
1 change: 0 additions & 1 deletion documentation/development/betty/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ These impact the ``./bin/test`` command:
* ``BETTY_TEST_SKIP_MYPY=true``: Skip mypy tests.
* ``BETTY_TEST_SKIP_STYLELINT=true``: Skip Stylelint tests.
* ``BETTY_TEST_SKIP_ESLINT=true``: Skip ESLint tests.
* ``BETTY_TEST_SKIP_PLAYWRIGHT=true``: Skip Playwright tests.

Fixing problems automatically
-----------------------------
Expand Down
10 changes: 0 additions & 10 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import eslint from '@eslint/js'
import stylistic from '@stylistic/eslint-plugin'
import globals from 'globals'
import playwright from 'eslint-plugin-playwright'
import tseslint from 'typescript-eslint'

const typescriptFiles = [
Expand Down Expand Up @@ -39,15 +38,6 @@ export default [
},
},

// Playwright tests.
{
files: [
'playwright/tests/**',
],
...playwright.configs['flat/recommended'],

},

// Generic EcmaScript.
{
plugins: {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"node": ">= 20"
},
"devDependencies": {
"@playwright/test": "^1.49.0",
"@stylistic/eslint-plugin": "^2.10.1",
"@types/node": "*",
"@types/webpack": "^5.28.5",
Expand All @@ -15,7 +14,6 @@
"eslint": "^9.15.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.13.2",
"eslint-plugin-playwright": "^2.1.0",
"eslint-plugin-promise": "^7.1.0",
"stylelint": "^16.10.0",
"stylelint-config-standard": "^36.0.1",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ test = [
'pytest-aioresponses ~= 0.2',
'pytest-asyncio ~= 0.24',
'pytest-mock ~= 3.14',
'pytest-playwright-asyncio ~= 9.9.9',
'requests ~= 2.32',
'ruff ~= 0.7',
'types-aiofiles ~= 24.1',
Expand Down
Loading