Skip to content

Commit 9e3ca4d

Browse files
committed
Fix tests with WebDriverWait.
1 parent 23f7aed commit 9e3ca4d

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tests/IntegrationTests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from selenium import webdriver
66
import percy
77

8+
from selenium.webdriver.common.by import By
9+
from selenium.webdriver.support.ui import WebDriverWait
10+
from selenium.webdriver.support import expected_conditions as EC
11+
12+
TIMEOUT = 20
13+
814

915
class IntegrationTests(unittest.TestCase):
1016

@@ -15,6 +21,17 @@ def percy_snapshot(cls, name=''):
1521
name=snapshot_name
1622
)
1723

24+
def wait_for_element_by_css_selector(self, selector):
25+
return WebDriverWait(self.driver, TIMEOUT).until(
26+
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
27+
)
28+
29+
def wait_for_text_to_equal(self, selector, assertion_text):
30+
return WebDriverWait(self.driver, TIMEOUT).until(
31+
EC.text_to_be_present_in_element((By.CSS_SELECTOR, selector),
32+
assertion_text)
33+
)
34+
1835
@classmethod
1936
def setUpClass(cls):
2037
super(IntegrationTests, cls).setUpClass()

tests/test_integration.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import dash
1212
import time
1313

14-
from dash.dependencies import Input, Output
14+
from dash.dependencies import Input, Output, State
1515
from dash.exceptions import PreventUpdate
1616
from .IntegrationTests import IntegrationTests
1717
from .utils import assert_clean_console, invincible, wait_for
@@ -61,8 +61,7 @@ def update_output(value):
6161

6262
input1.send_keys('hello world')
6363

64-
output1 = lambda: self.wait_for_element_by_id('output-1')
65-
wait_for(lambda: output1().text == 'hello world')
64+
output1 = self.wait_for_text_to_equal('#output-1', 'hello world')
6665
self.percy_snapshot(name='simple-callback-2')
6766

6867
self.assertEqual(
@@ -106,17 +105,15 @@ def update_text(data):
106105
return data
107106

108107
self.startServer(app)
109-
output1 = self.wait_for_element_by_id('output-1')
110-
wait_for(lambda: output1.text == 'initial value')
108+
output1 = self.wait_for_text_to_equal('#output-1', 'initial value')
111109
self.percy_snapshot(name='wildcard-callback-1')
112110

113111
input1 = self.wait_for_element_by_id('input')
114112
input1.clear()
115113

116114
input1.send_keys('hello world')
117115

118-
output1 = lambda: self.wait_for_element_by_id('output-1')
119-
wait_for(lambda: output1().text == 'hello world')
116+
output1 = self.wait_for_text_to_equal('#output-1', 'hello world')
120117
self.percy_snapshot(name='wildcard-callback-2')
121118

122119
self.assertEqual(

0 commit comments

Comments
 (0)