Skip to content

Commit 690b1df

Browse files
committed
create add images for files
1 parent 9fee871 commit 690b1df

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Playwright Tests
2+
# https://devblogs.microsoft.com/python/announcing-playwright-for-python-reliable-end-to-end-testing-for-the-web/
3+
# https://github.com/marketplace/actions/run-playwright-tests
4+
5+
on:
6+
pull_request:
7+
types: [labeled]
8+
branches:
9+
- gh-pages
10+
11+
workflow_dispatch:
12+
13+
jobs:
14+
test:
15+
if: ${{ github.event.label.name == 'design_change' }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.12"
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements-dev.txt
27+
python -m playwright install --with-deps chromium
28+
- name: Set up Ruby
29+
uses: ruby/setup-ruby@v1
30+
with:
31+
bundler-cache: true
32+
# Run tests
33+
- name: Run Tests
34+
run: |
35+
python -m pytest -m design
36+
- name: upload images
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: page_screenshots
40+
path: test_images/

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[pytest]
22
python_files = tests/*.py
3-
addopts = -v
3+
addopts = -v -m "not design"
4+
markers =
5+
design: get visuals for test paths

tests/test_design.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pathlib
2+
import pytest
3+
from playwright.sync_api import Page, sync_playwright
4+
5+
6+
@pytest.fixture(scope="module")
7+
def per_device_page_url(xprocess, loaded_profile, url_port):
8+
"""Returns the url of the live server"""
9+
10+
url, port = url_port
11+
12+
class Starter(xprocess.ProcessStarter):
13+
# Start the process
14+
args = [
15+
"bundle",
16+
"exec",
17+
"jekyll",
18+
"serve",
19+
"--source",
20+
pathlib.Path().cwd().absolute(),
21+
"--port",
22+
port,
23+
]
24+
terminate_on_interrupt = True
25+
pattern = "Server running... press ctrl-c to stop."
26+
27+
xprocess.ensure("per_device_page_url", Starter)
28+
29+
with sync_playwright() as p:
30+
device = p.devices[loaded_profile]
31+
browser = p.chromium.launch()
32+
context = browser.new_context(**device)
33+
page = context.new_page()
34+
35+
# Return the URL of the live server
36+
yield page, url
37+
38+
# Clean up the process
39+
xprocess.getinfo("per_device_page_url").terminate()
40+
41+
42+
@pytest.fixture(scope="session")
43+
def create_test_image():
44+
image_path = pathlib.Path("./").joinpath("test_images")
45+
46+
if not image_path.is_dir():
47+
image_path.mkdir()
48+
return image_path
49+
50+
51+
@pytest.mark.design
52+
def test_route_designs(
53+
loaded_route: str,
54+
per_device_page_url: tuple[Page, str],
55+
create_test_image,
56+
request,
57+
) -> None:
58+
"""Test that the destinations page loads with seeded data"""
59+
# Create a destination
60+
page, live_server_url = per_device_page_url
61+
response = page.goto(f"{live_server_url}/{loaded_route}")
62+
page.screenshot(path=create_test_image.joinpath(request.node.name), full_page=True)
63+
assert response.status == 200

0 commit comments

Comments
 (0)