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

Basic UI testing via playwright, requires Python3 #416

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,39 @@ You can contribute to content translation of www.thunderbird.net pages using [Po

# Donation FAQ

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.
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.

# Tests

In order to run tests you will need to install the test dependencies:
```
pip install -r requirements-test.txt
```

If you'll be testing with playwright, you'll also need to do a one-time setup with playwright:
```
playwright install
```

## Pytest

To run all tests use the command:
```
python -m pytest tests/
```

## Playwright (via Pytest)

Thunderbird-website uses Playwright via the Pytest plugin. For more information on the Playwright Python bindings [click here](https://playwright.dev/python/).

Since the build script only works on Python 2 right now, you'll have to first build the site:
```
python2 build-site.py
```

To run just the playwright tests use the command:
```
python -m pytest tests/ui/
```

Playwright is setup to run UI tests under Firefox and Chromium.
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[pytest]
addopts = --browser firefox --browser chromium
# webkit doesn't currently work?
# --browser webkit
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Specific requirements for testing
pytest==7.3.1
pytest-playwright==0.3.3
4 changes: 4 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
'zh-hant-hk': 'zh-TW', # Bug 1338072
}

TEST_PORT = 8889
TEST_URL_BASE = 'http://localhost:{}'.format(TEST_PORT)
TEST_URL = '{}/{}'.format(TEST_URL_BASE, LANGUAGE_CODE)

CANONICAL_URL = 'https://www.thunderbird.net'

# url for the server that serves Thunderbird downloads.
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

import builder
import settings


@pytest.fixture(scope="session", autouse=True)
def handle_server():
print("! Starting local test server at {}".format(settings.TEST_URL_BASE))
server = builder.setup_httpd(settings.TEST_PORT, settings.WEBSITE_RENDERPATH)
yield
print("! Shutting down local test server")
server.terminate()
server.join()

43 changes: 43 additions & 0 deletions tests/ui/test_download_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re
import pytest
from playwright.sync_api import Page, expect
from product_details import thunderbird_desktop
import settings

@pytest.fixture
def download_page_download_states(page: Page):
"""Returns a list of tuples, which contains the download page to goto, and the download version the visible download button should be."""
download_page_url = f"{settings.TEST_URL}/download/"

download_versions = (
thunderbird_desktop.latest_version('release'),
thunderbird_desktop.latest_version('beta'),
thunderbird_desktop.latest_version('daily')
)

return [
(download_page_url, download_versions[0]),
(f"{download_page_url}?downloaded=True", download_versions[0]),
(f"{download_page_url}?downloaded=False", download_versions[0]),
(f"{download_page_url}?download_channel=esr", download_versions[0]),
(f"{download_page_url}?download_channel=beta", download_versions[1]),
(f"{download_page_url}?download_channel=daily", download_versions[2]),
(f"{download_page_url}?download_channel=nonsense", download_versions[0]),
(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
(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
]


def test_download_links_exist(page: Page, download_page_download_states):
"""Tests the existence of the `Try Again` button on our download thank you page."""
for state in download_page_download_states:
page.goto(state[0])
expect(page.locator('.download-link:visible')).to_have_count(1)


def test_download_links_are_correct(page: Page, download_page_download_states):
"""Tests the validity of our download buttons when different download channels have been requested."""
for state in download_page_download_states:
page.goto(state[0])
expect(page.locator('.download-link:visible')).to_have_attribute("href", re.compile(state[1]))

14 changes: 14 additions & 0 deletions tests/ui/test_local_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
import settings
from playwright.sync_api import Page, expect


def test_server_is_working(page: Page):
"""Make sure our test server works correctly"""
response = page.goto(settings.TEST_URL)
assert response is not None
assert response.ok is True

# Make sure our title is correct, and this isn't an empty 200.
expect(page).to_have_title('Thunderbird — Make Email Easier. — Thunderbird')