Calmcode - playwright: another test

Adding one more test.

1 2 3 4 5 6 7 8 9

Let's now add a second test. The video shows you how you might do this step by step using the code generator. This eventually leads to a file with two tests.

from playwright.sync_api import Page, expect


def test_path_to_datasette(page: Page) -> None:
    page.goto("https://calmcode.io/")
    page.get_by_role("button", name="More").click()
    page.locator("#dropdown-button-1").get_by_role("link", name="Datasets").click()
    page.get_by_role("row", name="bigmac logo bigmac.csv An economic indicator? csv 1331 71KB Detailed Info").get_by_role("link", name="Detailed Info").click()
    page.get_by_role("button", name="Explore bigmac.csv").click()
    expect(page).to_have_url("https://calmcode-datasette.fly.dev/calmcode/bigmac", timeout=1000)


def test_navigation_img_and_link(page: Page) -> None:
    page.goto("https://calmcode.io/")

    # Use img to navigate
    page.locator(".flex-grow").click()
    page.get_by_role("link", name="args kwargs logo").click()
    img_elem = page.get_by_role("img", name="Calmcode -")
    expect(img_elem).to_be_visible()

    # Use link to navigate
    page.goto("https://calmcode.io/")
    page.get_by_role("link", name="args kwargs", exact=True).click()
    img_elem = page.get_by_role("img", name="Calmcode -")
    expect(img_elem).to_be_visible()

The main thing to observe in this new test_navigation_img_and_link test is that we're re-using the except function from before. It's just that now we're using it on on an element instead of on the entire page. Which opens the door to lots of things to check. You'd typically check if the element is visible, or that it has specific text values, but there are many things that you could check.

You can read this section on asserttions to learn more about what you can "expect".