-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added playwright tests. #2444
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
base: main
Are you sure you want to change the base?
Added playwright tests. #2444
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,10 @@ COPY ./requirements ./requirements | |
| RUN apt-get update \ | ||
| && apt-get install --assume-yes --no-install-recommends ${BUILD_DEPENDENCIES} \ | ||
| && python3 -m pip install --no-cache-dir -r ${REQ_FILE} \ | ||
| && if [ "${REQ_FILE}" = "requirements/tests.txt" ]; then \ | ||
| echo "Installing Playwright browsers..."; \ | ||
| playwright install --with-deps; \ | ||
| fi \ | ||
| && apt-get purge --assume-yes --auto-remove ${BUILD_DEPENDENCIES} \ | ||
|
Comment on lines
33
to
38
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may choose to install and test on chromium if not all broswers are necessary:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will reduce the docker image size as well.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would test at least for chromium and firefox to at least cover the 2 more used open source browser engine. |
||
| && apt-get distclean | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| import os | ||
| from http import HTTPStatus | ||
| from io import StringIO | ||
|
|
||
| from django.conf import settings | ||
| from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
| from django.core.management import call_command | ||
| from django.test import TestCase | ||
| from django.urls import NoReverseMatch, get_resolver | ||
| from django.utils.translation import activate, gettext as _ | ||
| from django_hosts.resolvers import reverse | ||
| from playwright.sync_api import expect, sync_playwright | ||
|
|
||
| from docs.models import DocumentRelease, Release | ||
|
|
||
|
|
@@ -211,3 +214,53 @@ def test_single_h1_per_page(self): | |
| response = self.client.get(url) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertContains(response, "<h1", count=1) | ||
|
|
||
|
|
||
| class EndToEndTests(ReleaseMixin, StaticLiveServerTestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" | ||
| super().setUpClass() | ||
| cls.playwright = sync_playwright().start() | ||
| cls.browser = cls.playwright.chromium.launch() | ||
| cls.mac_user_agent = "Mozilla/5.0 (Macintosh) AppleWebKit" | ||
| cls.windows_user_agent = "Mozilla/5.0 (Windows NT 10.0)" | ||
| cls.mobile_linux_user_agent = "Mozilla/5.0 (Linux; Android 10; Mobile)" | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| super().tearDownClass() | ||
| cls.browser.close() | ||
| cls.playwright.stop() | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.setUpTestData() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah no, we need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, ok, for |
||
|
|
||
| def test_search_ctrl_k_hotkey(self): | ||
| page1 = self.browser.new_page(user_agent=self.windows_user_agent) | ||
| page2 = self.browser.new_page( | ||
| user_agent=self.mobile_linux_user_agent, | ||
| viewport={"width": 375, "height": 812}, | ||
| ) | ||
| for page in [page1, page2]: | ||
| with self.subTest(page=page): | ||
| page.goto(self.live_server_url) | ||
| search_bar = page.locator("#id_q") | ||
| expect(search_bar).to_have_attribute("placeholder", "Search (Ctrl+K)") | ||
| is_focused = page.evaluate("document.activeElement.id === 'id_q'") | ||
| self.assertFalse(is_focused) | ||
|
|
||
| page.keyboard.press("Control+KeyK") | ||
| is_focused = page.evaluate("document.activeElement.id === 'id_q'") | ||
| self.assertTrue(is_focused) | ||
| page.close() | ||
|
|
||
| def test_search_placeholder_mac_mode(self): | ||
| page = self.browser.new_page(user_agent=self.mac_user_agent) | ||
| page.goto(self.live_server_url) | ||
|
|
||
| desktop_search_bar = page.locator("#id_q") | ||
| expect(desktop_search_bar).to_have_attribute("placeholder", "Search (⌘\u200aK)") | ||
|
sarahboyce marked this conversation as resolved.
|
||
|
|
||
| page.close() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| -r dev.txt | ||
| coverage==7.13.1 | ||
| playwright==1.58.0 | ||
| requests-mock==1.12.1 | ||
| tblib>=3.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could someone that uses Docker review the change to this file?