Skip to content

Commit 87c7de2

Browse files
authored
Use playwright for functional tests (#537)
* Use playwright for functional tests * Wait for image to fully load * Wait specifically for image load * Upload traces if test run fails * Misc fixes * Upgrade pytest-env version for pyproject.toml support * Remove duplicate ENV already declared in pyproject.toml * Add test instructions and remove extra Dockerfile logic
1 parent 95c107f commit 87c7de2

12 files changed

+766
-1002
lines changed

.github/workflows/pull_request.yml

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ jobs:
2727
just build
2828
just up
2929
just test
30+
- uses: actions/upload-artifact@v4
31+
if: ${{ !cancelled() }}
32+
with:
33+
name: playwright-traces
34+
path: build/test-results/

Dockerfile

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ ENV PYTHONUNBUFFERED=1
99
WORKDIR /usr/src/app
1010

1111
# Install packages depending on ENV arg from docker-compose
12-
ARG BASE_PACKAGES="gcc libpq-dev libjpeg62-turbo-dev libsqlite3-0 zlib1g-dev"
13-
ARG DEV_PACKAGES="firefox-esr"
14-
RUN if [ "$IS_PROD" = "true" ]; then \
15-
PACKAGES_TO_INSTALL="$BASE_PACKAGES"; \
16-
else \
17-
PACKAGES_TO_INSTALL="$BASE_PACKAGES $DEV_PACKAGES"; \
18-
fi && \
19-
apt-get update && \
12+
ARG PACKAGES_TO_INSTALL="gcc libpq-dev libjpeg62-turbo-dev libsqlite3-0 zlib1g-dev"
13+
RUN apt-get update && \
2014
apt-get install -y -qq --no-install-recommends $PACKAGES_TO_INSTALL && \
2115
apt-get clean && \
2216
rm -rf /var/lib/apt/lists/*
@@ -28,6 +22,7 @@ RUN if [ "$IS_PROD" = "true" ]; then \
2822
poetry install --only main --no-root; \
2923
else \
3024
poetry install --no-root; \
25+
playwright install --with-deps chromium; \
3126
fi
3227

3328
# Setup application

OpenOversight/app/static/js/find_officer.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $(document).ready(function() {
3434
$('#current-uii').text(deptUiidLabel);
3535
$('#uii-question').show();
3636
} else {
37+
$('#unique_internal_identifier').text('');
3738
$('#uii-question').hide();
3839
}
3940
});

OpenOversight/app/templates/submit_image.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h3 class="mt-4">High security submissions?</h3>
8787
dept_id = $("#department").val();
8888
});
8989

90-
const getURL = (file) => "/upload/department/" + dept_id;
90+
const getURL = (file) => "/upload/departments/" + dept_id;
9191
init_dropzone("#my-cop-dropzone", getURL, csrf_token);
9292
</script>
9393
</div>

OpenOversight/pytest.ini

-6
This file was deleted.

OpenOversight/tests/conftest.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
from faker import Faker
1616
from flask import current_app
1717
from PIL import Image as Pimage
18-
from selenium.webdriver.firefox.options import Options as FirefoxOptions
19-
from selenium.webdriver.firefox.service import Service as FirefoxService
20-
from selenium.webdriver.firefox.webdriver import WebDriver as Firefox
18+
from playwright.sync_api import Page
2119
from sqlalchemy.orm import scoped_session, sessionmaker
22-
from webdriver_manager.firefox import GeckoDriverManager
2320

2421
from OpenOversight.app import create_app
2522
from OpenOversight.app.models.database import (
@@ -900,19 +897,6 @@ def server(app, server_port):
900897
).start()
901898

902899

903-
@pytest.fixture(scope="session")
904-
def browser(app, server):
905-
options = FirefoxOptions()
906-
options.add_argument("--headless")
907-
options.add_argument("--width=1024")
908-
options.add_argument("--height=768")
909-
910-
service = FirefoxService(
911-
executable_path=GeckoDriverManager().install(), log_path="/tmp/geckodriver.log"
912-
)
913-
driver = Firefox(options=options, service=service)
914-
915-
yield driver
916-
917-
# shutdown headless webdriver
918-
driver.quit()
900+
@pytest.fixture
901+
def page(app, server, page: Page):
902+
yield page

0 commit comments

Comments
 (0)