|
1 | 1 | from selenium.webdriver import Keys |
| 2 | +from selenium import webdriver |
| 3 | +import os |
2 | 4 |
|
3 | 5 | import dash_ag_grid as dag |
4 | 6 | from dash import Dash, html |
5 | 7 | from . import utils |
6 | 8 |
|
| 9 | +from selenium.webdriver.chrome.options import Options |
| 10 | +from selenium.webdriver.common.by import By |
| 11 | +from selenium.webdriver.support.ui import WebDriverWait |
| 12 | +from selenium.webdriver.support import expected_conditions as EC |
| 13 | + |
| 14 | +from dash.testing.wait import until |
| 15 | + |
7 | 16 | def test_cd001_cell_data_types_override(dash_duo): |
| 17 | + os.environ['LANGUAGE'] = 'en-US' |
| 18 | + chrome_options = Options() |
| 19 | + driver = webdriver.Chrome(options=chrome_options) # run this test with a Chrome driver to control the locale |
| 20 | + |
8 | 21 | app = Dash(__name__) |
9 | 22 |
|
10 | 23 | rowData = [ |
@@ -60,23 +73,33 @@ def test_cd001_cell_data_types_override(dash_duo): |
60 | 73 | ) |
61 | 74 |
|
62 | 75 | dash_duo.start_server(app) |
| 76 | + try: |
| 77 | + driver.get(dash_duo.server_url) |
| 78 | + WebDriverWait(driver, 10).until( |
| 79 | + EC.presence_of_element_located((By.ID, "grid-cell-data-types-override-full-JS")) |
| 80 | + ) |
| 81 | + |
| 82 | + action = utils.ActionChains(driver) |
| 83 | + |
| 84 | + get_driver_cell = lambda id, row, col: driver.find_element(By.CSS_SELECTOR, f'#{id} .ag-center-cols-container .ag-row:nth-child({row + 1}) .ag-cell:nth-child({col + 1})') |
63 | 85 |
|
64 | | - action = utils.ActionChains(dash_duo.driver) |
| 86 | + # same tests for both grids |
| 87 | + for id in ["grid-cell-data-types-override-full-JS", "grid-cell-data-types-override"]: |
65 | 88 |
|
66 | | - # same tests for both grids |
67 | | - for id in ["grid-cell-data-types-override-full-JS", "grid-cell-data-types-override"]: |
68 | | - grid = utils.Grid(dash_duo, id) |
| 89 | + until(lambda: get_driver_cell(id, 0, 0).text == "7.5%", timeout=3) |
69 | 90 |
|
70 | | - # test overriden number cell data type |
71 | | - action.double_click(grid.get_cell(0, 0)).perform() |
72 | | - date_input_element = dash_duo.find_element(f'#{grid.id} .ag-number-field-input') |
73 | | - date_input_element.send_keys("0.1" + Keys.ENTER) |
| 91 | + # test overriden number cell data type |
| 92 | + action.double_click(get_driver_cell(id,0, 0)).perform() |
| 93 | + date_input_element = driver.find_element(By.CSS_SELECTOR,f'#{id} .ag-number-field-input') |
| 94 | + date_input_element.send_keys("0.1" + Keys.ENTER) |
74 | 95 |
|
75 | | - grid.wait_for_cell_text(0, 0, "10.0%") |
| 96 | + until(lambda: get_driver_cell(id,0, 0).text == "10.0%", timeout=3) |
76 | 97 |
|
77 | | - # test overriden dateString cell data type |
78 | | - action.double_click(grid.get_cell(0, 1)).perform() |
79 | | - date_input_element = dash_duo.find_element(f'#{grid.id} .ag-date-field-input') |
80 | | - date_input_element.send_keys("01172024" + Keys.ENTER) |
| 98 | + # test overriden dateString cell data type |
| 99 | + action.double_click(get_driver_cell(id,0, 1)).perform() |
| 100 | + date_input_element = driver.find_element(By.CSS_SELECTOR, f'#{id} .ag-date-field-input') |
| 101 | + date_input_element.send_keys("01172024" + Keys.ENTER) |
81 | 102 |
|
82 | | - grid.wait_for_cell_text(0, 1, "17/01/2024") |
| 103 | + until(lambda: get_driver_cell(id,0, 1).text == "17/01/2024", timeout=3) |
| 104 | + finally: |
| 105 | + driver.quit() |
0 commit comments