|
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. |
2 | 4 |
|
| 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 |
3 | 11 | from playwright.sync_api import Page, expect |
4 | 12 |
|
5 | 13 |
|
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 | + |
7 | 33 | # Navigate to page |
8 | 34 | page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint") |
9 | 35 |
|
10 | 36 | # Assert repo text is present |
11 | 37 | expect(page.get_by_role("article")).to_contain_text("Playwright Python Blueprint") |
12 | 38 |
|
13 | 39 | # 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() |
15 | 41 |
|
16 | 42 | # Assert license text |
17 | 43 | 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