From 782dcd020b7e45ffe3337b52ef672c8cd3b867bd Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 24 Oct 2024 21:22:42 +0200 Subject: [PATCH] convert test_table to use playwright --- .../{ => tests_playwright}/test_table.py | 67 ++++++------------- 1 file changed, 21 insertions(+), 46 deletions(-) rename tests/integration/{ => tests_playwright}/test_table.py (57%) diff --git a/tests/integration/test_table.py b/tests/integration/tests_playwright/test_table.py similarity index 57% rename from tests/integration/test_table.py rename to tests/integration/tests_playwright/test_table.py index 09004a874..c92a1a74b 100644 --- a/tests/integration/test_table.py +++ b/tests/integration/tests_playwright/test_table.py @@ -3,7 +3,7 @@ from typing import Generator import pytest -from selenium.webdriver.common.by import By +from playwright.sync_api import Page from reflex.testing import AppHarness @@ -17,11 +17,6 @@ def Table(): @app.add_page def index(): return rx.center( - rx.input( - id="token", - value=rx.State.router.session.client_token, - is_read_only=True, - ), rx.table.root( rx.table.header( rx.table.row( @@ -53,7 +48,7 @@ def Table(): @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. Args: @@ -71,47 +66,27 @@ def table(tmp_path_factory) -> Generator[AppHarness, None, None]: yield harness -@pytest.fixture -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): +def test_table(page: Page, table_app: AppHarness): """Test that a table component is rendered properly. Args: - driver: Selenium WebDriver open to the app - table: Harness for Table app + table_app: 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") - # poll till page is fully loaded. - table.poll_for_content(element=thead) - # check headers - assert thead.find_element(By.TAG_NAME, "tr").text == "Name Age Location" - # check first row value - assert ( - driver.find_element(By.TAG_NAME, "tbody") - .find_elements(By.TAG_NAME, "tr")[0] - .text - == "John 30 New York" - ) + page.goto(table_app.frontend_url) + table = page.get_by_role("table") + + headers = table.get_by_role("columnheader").all_inner_texts() + assert headers == ["Name", "Age", "Location"] + + rows = [ + row.split("\t") + for row in table.locator("tbody").all_inner_texts()[0].splitlines() + ] + + assert rows[0] == ["John", "30", "New York"] + assert rows[1] == ["Jane", "31", "San Fransisco"] + assert rows[2] == ["Joe", "32", "Los Angeles"]