convert test_table to use playwright
This commit is contained in:
parent
0bf778e270
commit
782dcd020b
@ -3,7 +3,7 @@
|
|||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from selenium.webdriver.common.by import By
|
from playwright.sync_api import Page
|
||||||
|
|
||||||
from reflex.testing import AppHarness
|
from reflex.testing import AppHarness
|
||||||
|
|
||||||
@ -17,11 +17,6 @@ def Table():
|
|||||||
@app.add_page
|
@app.add_page
|
||||||
def index():
|
def index():
|
||||||
return rx.center(
|
return rx.center(
|
||||||
rx.input(
|
|
||||||
id="token",
|
|
||||||
value=rx.State.router.session.client_token,
|
|
||||||
is_read_only=True,
|
|
||||||
),
|
|
||||||
rx.table.root(
|
rx.table.root(
|
||||||
rx.table.header(
|
rx.table.header(
|
||||||
rx.table.row(
|
rx.table.row(
|
||||||
@ -53,7 +48,7 @@ def Table():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def table(tmp_path_factory) -> Generator[AppHarness, None, None]:
|
def table_app(tmp_path_factory) -> Generator[AppHarness, None, None]:
|
||||||
"""Start Table app at tmp_path via AppHarness.
|
"""Start Table app at tmp_path via AppHarness.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -71,47 +66,27 @@ def table(tmp_path_factory) -> Generator[AppHarness, None, None]:
|
|||||||
yield harness
|
yield harness
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_table(page: Page, table_app: AppHarness):
|
||||||
def driver(table: AppHarness):
|
|
||||||
"""GEt an instance of the browser open to the table app.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
table: harness for Table app
|
|
||||||
|
|
||||||
Yields:
|
|
||||||
WebDriver instance.
|
|
||||||
"""
|
|
||||||
driver = table.frontend()
|
|
||||||
try:
|
|
||||||
token_input = driver.find_element(By.ID, "token")
|
|
||||||
assert token_input
|
|
||||||
# wait for the backend connection to send the token
|
|
||||||
token = table.poll_for_value(token_input)
|
|
||||||
assert token is not None
|
|
||||||
|
|
||||||
yield driver
|
|
||||||
finally:
|
|
||||||
driver.quit()
|
|
||||||
|
|
||||||
|
|
||||||
def test_table(driver, table: AppHarness):
|
|
||||||
"""Test that a table component is rendered properly.
|
"""Test that a table component is rendered properly.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
driver: Selenium WebDriver open to the app
|
table_app: Harness for Table app
|
||||||
table: Harness for Table app
|
page: Playwright page instance
|
||||||
"""
|
"""
|
||||||
assert table.app_instance is not None, "app is not running"
|
assert table_app.app_instance is not None, "app is not running"
|
||||||
|
assert table_app.frontend_url is not None, "frontend url is not available"
|
||||||
|
|
||||||
thead = driver.find_element(By.TAG_NAME, "thead")
|
page.goto(table_app.frontend_url)
|
||||||
# poll till page is fully loaded.
|
table = page.get_by_role("table")
|
||||||
table.poll_for_content(element=thead)
|
|
||||||
# check headers
|
headers = table.get_by_role("columnheader").all_inner_texts()
|
||||||
assert thead.find_element(By.TAG_NAME, "tr").text == "Name Age Location"
|
assert headers == ["Name", "Age", "Location"]
|
||||||
# check first row value
|
|
||||||
assert (
|
rows = [
|
||||||
driver.find_element(By.TAG_NAME, "tbody")
|
row.split("\t")
|
||||||
.find_elements(By.TAG_NAME, "tr")[0]
|
for row in table.locator("tbody").all_inner_texts()[0].splitlines()
|
||||||
.text
|
]
|
||||||
== "John 30 New York"
|
|
||||||
)
|
assert rows[0] == ["John", "30", "New York"]
|
||||||
|
assert rows[1] == ["Jane", "31", "San Fransisco"]
|
||||||
|
assert rows[2] == ["Joe", "32", "Los Angeles"]
|
Loading…
Reference in New Issue
Block a user