Testing (playwright)
How to test
Click X, then Y, then Z. Finally, assert that XYZ is visible on the page.
Finding elements
Locators
TODO Find specific element
TODO Find elements of specific type (e.g. count rows in a table
Taking actions
TODO Click, fill input, check/uncheck checkboxes
Initial page navigation
@pytest.mark.asyncio
async def test_index_url(self) -> None:
await self.page.goto(f"{self.server_url}")
Buttons and other elements
await element.click()
Input fields
await my_input_element.fill("my text or numbers")
await my_input_element.type("enter text slowly over time")
await my_input_element.press("Enter")
Assertions
Playwright will automatically retry assertions as javascript code is being executed. Sometimes elements or text are not available until the page has fully loaded (sometimes it takes a few seconds).
Always use expect as it will retry multiple times until the expected situation appears or the timeout (default 5000ms) hits. Do not use assert directly as it doesn't have this retry mechanic.
await expect(my_input).to_have_value("test_value")
await expect(my_div_element).to_have_text("test_text")
await expect(table_tbody_rows).to_have_count(7)
await expect(dialog).to_be_visible()
await expect(dialog).not_to_be_visible()
Other
Sometimes you have to explicitly wait for events to happen, e.g. an alert dialog opening
await page.wait_for_timeout(1000) # Time in ms
Debugger support
Works out of the box