Skip to content

Commit 652ae72

Browse files
Enhanced Examples (#12)
This enhances the examples that were initially committed to add further context and guidance, as well as adding a new test.
1 parent c1d5cfe commit 652ae72

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

blueprint/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ addopts =
88
--json-report-file=test-results/results.json
99
--json-report-omit=collectors
1010
markers =
11-
subjects: tests for subject-based scenarios
11+
example: tests used for example purposes
1212
branch: tests designed to run at a branch level
1313
main: tests designed to run against the main branch
1414
release: tests designed to run specifically against a release branch

blueprint/tests/test_example.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,75 @@
1-
# This file provides a very basic test to confirm the configuration is working
1+
"""
2+
This file provides a very basic test to confirm how to get started with test execution, and also
3+
a way to prove that the blueprint has been copied and built correctly for teams getting stated.
24
5+
You can invoke this test once the blueprint has been installed by using the following command
6+
to see the test executing and producing a trace report:
7+
pytest --tracing on --headed
8+
"""
9+
10+
import pytest
311
from playwright.sync_api import Page, expect
412

513

6-
def test_basic_example(page: Page):
14+
@pytest.mark.example
15+
def test_basic_example(page: Page) -> None:
16+
'''
17+
This test demonstrates how to quickly get started using Playwright Python.
18+
19+
This example starts with @pytest.mark.example, which indicates this test has been tagged
20+
with the term "example", to demonstrate how tests can be independently tagged.
21+
22+
When running via the command line, Playwright automatically instantiates certain objects
23+
available for use, including the Page object (which is how Playwright interacts with the
24+
system under test).
25+
26+
This test does the following:
27+
1) Navigates to this repository
28+
2) Asserts that the README contents rendered by GitHub includes the text "Playwright Python Blueprint"
29+
3) Clicks the MIT license link
30+
4) Asserts that the LICENCE contents rendered by GitHub includes the text "MIT Licence"
31+
'''
32+
733
# Navigate to page
834
page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")
935

1036
# Assert repo text is present
1137
expect(page.get_by_role("article")).to_contain_text("Playwright Python Blueprint")
1238

1339
# Click license link
14-
page.get_by_role("link", name="MIT license").click()
40+
page.get_by_role("link", name="MIT license", exact=True).click()
1541

1642
# Assert license text
1743
expect(page.get_by_role("article")).to_contain_text("MIT Licence")
44+
45+
46+
@pytest.mark.example
47+
def test_textbox_example(page: Page) -> None:
48+
"""
49+
This test demonstrates another example of quickly getting started using Playwright Python.
50+
51+
This is specifically designed to outline some of the principals that Playwright uses, for
52+
example when looking for a specific textbox to enter information into, rather than using a
53+
direct HTML or CSS reference, you can use attributes of the field (in this case the placeholder
54+
text) to find the element as a user would navigating your application. You can also use
55+
locators to find specific HTML or CSS elements as required (in this case the locator for the
56+
assertion).
57+
58+
This test does the following:
59+
1) Navigates to this repository
60+
2) Uses the "Go to file" textbox and searches for this file, "text_example.py"
61+
3) Selects the label for the dropdown element presented for the search results and clicks
62+
4) Asserts that the filename for the now selected file is "test_example.py"
63+
"""
64+
65+
# Navigate to page
66+
page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")
67+
68+
# Select the "Go to file" textbox and search for this file
69+
page.get_by_placeholder("Go to file").fill("test_example.py")
70+
71+
# Click the file name presented in the dropdown
72+
page.get_by_label("blueprint/tests/test_example.").click()
73+
74+
# Confirm we are viewing the correct file
75+
expect(page.locator("#file-name-id-wide")).to_contain_text("test_example.py")

0 commit comments

Comments
 (0)