Skip to content

Commit

Permalink
Fix tests with WebDriverWait.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Oct 29, 2018
1 parent 23f7aed commit 9e3ca4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 17 additions & 0 deletions tests/IntegrationTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from selenium import webdriver
import percy

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

TIMEOUT = 20


class IntegrationTests(unittest.TestCase):

Expand All @@ -15,6 +21,17 @@ def percy_snapshot(cls, name=''):
name=snapshot_name
)

def wait_for_element_by_css_selector(self, selector):
return WebDriverWait(self.driver, TIMEOUT).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
)

def wait_for_text_to_equal(self, selector, assertion_text):
return WebDriverWait(self.driver, TIMEOUT).until(
EC.text_to_be_present_in_element((By.CSS_SELECTOR, selector),
assertion_text)
)

@classmethod
def setUpClass(cls):
super(IntegrationTests, cls).setUpClass()
Expand Down
11 changes: 4 additions & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import dash
import time

from dash.dependencies import Input, Output
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from .IntegrationTests import IntegrationTests
from .utils import assert_clean_console, invincible, wait_for
Expand Down Expand Up @@ -61,8 +61,7 @@ def update_output(value):

input1.send_keys('hello world')

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

self.assertEqual(
Expand Down Expand Up @@ -106,17 +105,15 @@ def update_text(data):
return data

self.startServer(app)
output1 = self.wait_for_element_by_id('output-1')
wait_for(lambda: output1.text == 'initial value')
output1 = self.wait_for_text_to_equal('#output-1', 'initial value')
self.percy_snapshot(name='wildcard-callback-1')

input1 = self.wait_for_element_by_id('input')
input1.clear()

input1.send_keys('hello world')

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

self.assertEqual(
Expand Down

0 comments on commit 9e3ca4d

Please sign in to comment.