|
1 | 1 | import dash
|
2 | 2 | import dash_core_components as dcc
|
3 | 3 | import dash_html_components as html
|
| 4 | +import dash.testing.wait as wait |
| 5 | +import time |
| 6 | + |
4 | 7 |
|
5 | 8 | from selenium.webdriver.common.action_chains import ActionChains
|
6 | 9 | from selenium.webdriver.common.keys import Keys
|
7 | 10 |
|
8 | 11 |
|
9 |
| -def test_clp001_clipboard_text(dash_dcc): |
| 12 | +def test_clp001_clipboard_text(dash_dcc_headed): |
10 | 13 | copy_text = "Hello, Dash!"
|
11 | 14 | app = dash.Dash(__name__, prevent_initial_callbacks=True)
|
12 | 15 | app.layout = html.Div(
|
13 | 16 | [
|
14 |
| - html.Div(copy_text, id="copy"), |
15 |
| - dcc.Clipboard(id="copy_icon", target_id="copy"), |
16 |
| - dcc.Textarea(id="paste"), |
| 17 | + html.Div(copy_text, id="copy1"), |
| 18 | + dcc.Clipboard(id="copy_icon1", target_id="copy1"), |
| 19 | + dcc.Textarea(id="paste1"), |
17 | 20 | ]
|
18 | 21 | )
|
19 |
| - dash_dcc.start_server(app) |
| 22 | + dash_dcc_headed.start_server(app) |
| 23 | + dash_dcc_headed.driver.execute_script("navigator.clipboard.writeText('')") |
20 | 24 |
|
21 |
| - dash_dcc.find_element("#copy_icon").click() |
22 |
| - dash_dcc.find_element("#paste").click() |
23 |
| - ActionChains(dash_dcc.driver).key_down(Keys.CONTROL).send_keys("v").key_up( |
| 25 | + dash_dcc_headed.find_element("#copy_icon1").click() |
| 26 | + time.sleep(2) |
| 27 | + dash_dcc_headed.find_element("#paste1").click() |
| 28 | + ActionChains(dash_dcc_headed.driver).key_down(Keys.CONTROL).send_keys("v").key_up( |
24 | 29 | Keys.CONTROL
|
25 | 30 | ).perform()
|
26 | 31 |
|
27 |
| - elem = dash_dcc.find_element("#paste") |
28 |
| - val = elem.get_attribute("value") |
29 |
| - assert val == copy_text |
| 32 | + wait.until( |
| 33 | + lambda: dash_dcc_headed.find_element("#paste1").get_attribute("value") |
| 34 | + == copy_text, |
| 35 | + timeout=3, |
| 36 | + ) |
30 | 37 |
|
31 | 38 |
|
32 |
| -def test_clp002_clipboard_text(dash_dcc): |
33 |
| - copy_text = "Copy" |
| 39 | +def test_clp002_clipboard_text(dash_dcc_headed): |
| 40 | + copy_text = "Copy this text to the clipboard" |
34 | 41 | app = dash.Dash(__name__, prevent_initial_callbacks=True)
|
35 | 42 | app.layout = html.Div(
|
36 |
| - [dcc.Clipboard(id="copy_icon", text=copy_text), dcc.Textarea(id="paste")] |
| 43 | + [dcc.Clipboard(id="copy_icon2", text=copy_text), dcc.Textarea(id="paste2")] |
37 | 44 | )
|
38 |
| - dash_dcc.start_server(app) |
| 45 | + dash_dcc_headed.start_server(app) |
| 46 | + dash_dcc_headed.driver.execute_script("navigator.clipboard.writeText('')") |
39 | 47 |
|
40 |
| - dash_dcc.find_element("#copy_icon").click() |
41 |
| - dash_dcc.find_element("#paste").click() |
42 |
| - ActionChains(dash_dcc.driver).key_down(Keys.CONTROL).send_keys("v").key_up( |
| 48 | + dash_dcc_headed.find_element("#copy_icon2").click() |
| 49 | + time.sleep(2) |
| 50 | + dash_dcc_headed.find_element("#paste2").click() |
| 51 | + ActionChains(dash_dcc_headed.driver).key_down(Keys.CONTROL).send_keys("v").key_up( |
43 | 52 | Keys.CONTROL
|
44 | 53 | ).perform()
|
45 | 54 |
|
46 |
| - elem = dash_dcc.find_element("#paste") |
47 |
| - val = elem.get_attribute("value") |
48 |
| - assert val == copy_text |
| 55 | + wait.until( |
| 56 | + lambda: dash_dcc_headed.find_element("#paste2").get_attribute("value") |
| 57 | + == copy_text, |
| 58 | + timeout=3, |
| 59 | + ) |
0 commit comments