Skip to content

Commit 7f6fe5d

Browse files
committed
Basic UI testing via playwright, requires Python3
- Includes a dev server test - Includes a few download button tests
1 parent 4e1ddb9 commit 7f6fe5d

6 files changed

Lines changed: 107 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,29 @@ You can contribute to content translation of www.thunderbird.net pages using [Po
9696

9797
# Donation FAQ
9898

99-
The actual questions and answers part of the FAQ can be found in `./faq.py`. Make sure to include the `gettext` call, otherwise we won't be able to extract the strings for localization.
99+
The actual questions and answers part of the FAQ can be found in `./faq.py`. Make sure to include the `gettext` call, otherwise we won't be able to extract the strings for localization.
100+
101+
# Tests
102+
103+
## Pytest
104+
105+
To run all tests use the command:
106+
```
107+
python -m pytest tests/
108+
```
109+
110+
## Playwright (via Pytest)
111+
112+
Thunderbird-website uses Playwright via the Pytest plugin. For more information on the Playwright Python bindings [click here](https://playwright.dev/python/).
113+
114+
Since the build script only works on Python 2 right now, you'll have to first build the site:
115+
```
116+
python2 build-site.py
117+
```
118+
119+
To run just the playwright tests use the command:
120+
```
121+
python -m pytest tests/ui/
122+
```
123+
124+
Playwright is setup to run UI tests under Firefox and Chromium.

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
[pytest]
3+
addopts = --browser firefox --browser chromium
4+
# webkit doesn't currently work?
5+
# --browser webkit

settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
'zh-hant-hk': 'zh-TW', # Bug 1338072
6666
}
6767

68+
TEST_PORT = 8889
69+
TEST_URL_BASE = 'http://localhost:{}'.format(TEST_PORT)
70+
TEST_URL = '{}/{}'.format(TEST_URL_BASE, LANGUAGE_CODE)
71+
6872
CANONICAL_URL = 'https://www.thunderbird.net'
6973

7074
# url for the server that serves Thunderbird downloads.

tests/ui/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
import builder
4+
import settings
5+
6+
7+
@pytest.fixture(scope="session", autouse=True)
8+
def handle_server():
9+
print("! Starting local test server at {}".format(settings.TEST_URL_BASE))
10+
server = builder.setup_httpd(settings.TEST_PORT, settings.WEBSITE_RENDERPATH)
11+
yield
12+
print("! Shutting down local test server")
13+
server.terminate()
14+
server.join()
15+

tests/ui/test_download_page.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import re
2+
import pytest
3+
from playwright.sync_api import Page, expect
4+
from product_details import thunderbird_desktop
5+
import settings
6+
7+
@pytest.fixture
8+
def download_page_download_states(page: Page):
9+
"""Returns a list of tuples, which contains the download page to goto, and the download version the visible download button should be."""
10+
download_page_url = f"{settings.TEST_URL}/download/"
11+
12+
download_versions = (
13+
thunderbird_desktop.latest_version('release'),
14+
thunderbird_desktop.latest_version('beta'),
15+
thunderbird_desktop.latest_version('daily')
16+
)
17+
18+
return [
19+
(download_page_url, download_versions[0]),
20+
(f"{download_page_url}?downloaded=True", download_versions[0]),
21+
(f"{download_page_url}?downloaded=False", download_versions[0]),
22+
(f"{download_page_url}?download_channel=esr", download_versions[0]),
23+
(f"{download_page_url}?download_channel=beta", download_versions[1]),
24+
(f"{download_page_url}?download_channel=daily", download_versions[2]),
25+
(f"{download_page_url}?download_channel=nonsense", download_versions[0]),
26+
(f"{download_page_url}?download_channel=&downloaded=true&download_channel=beta", download_versions[1]), # Javascript check looks for (esr|beta|daily), empty params are ignored
27+
(f"{download_page_url}?download_channel=&downloaded=true&download_channel=daily&download_channel=beta", download_versions[2]), # Javascript check will only use the first instance
28+
]
29+
30+
31+
def test_download_links_exist(page: Page, download_page_download_states):
32+
"""Tests the existence of the `Try Again` button on our download thank you page."""
33+
for state in download_page_download_states:
34+
page.goto(state[0])
35+
expect(page.locator('.download-link:visible')).to_have_count(1)
36+
37+
38+
def test_download_links_are_correct(page: Page, download_page_download_states):
39+
"""Tests the validity of our download buttons when different download channels have been requested."""
40+
for state in download_page_download_states:
41+
page.goto(state[0])
42+
expect(page.locator('.download-link:visible')).to_have_attribute("href", re.compile(state[1]))
43+

tests/ui/test_local_server.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
import settings
3+
from playwright.sync_api import Page, expect
4+
5+
6+
def test_server_is_working(page: Page):
7+
"""Make sure our test server works correctly"""
8+
response = page.goto(settings.TEST_URL)
9+
assert response is not None
10+
assert response.ok is True
11+
12+
# Make sure our title is correct, and this isn't an empty 200.
13+
expect(page).to_have_title('Thunderbird — Make Email Easier. — Thunderbird')
14+

0 commit comments

Comments
 (0)