diff --git a/tests/screen.py b/tests/screen.py index ed0bf048c..7ffc02b26 100644 --- a/tests/screen.py +++ b/tests/screen.py @@ -85,6 +85,15 @@ def should_not_contain(self, text: str) -> None: self.find(text) self.selenium.implicitly_wait(2) + def should_contain_input(self, text: str) -> None: + deadline = time.time() + self.IMPLICIT_WAIT + while time.time() < deadline: + for input in self.selenium.find_elements(By.TAG_NAME, 'input'): + if input.get_attribute('value') == text: + return + self.wait(0.1) + raise AssertionError(f'Could not find input with value "{text}"') + def click(self, target_text: str) -> WebElement: element = self.find(target_text) try: @@ -112,11 +121,6 @@ def find(self, text: str) -> WebElement: raise AssertionError(f'Found "{text}" but it is hidden') return element except NoSuchElementException as e: - self.selenium.implicitly_wait(0) - for input in self.selenium.find_elements(By.TAG_NAME, 'input'): - if input.get_attribute('value') == text: - return input - self.selenium.implicitly_wait(self.IMPLICIT_WAIT) raise AssertionError(f'Could not find "{text}"') from e def render_js_logs(self) -> str: diff --git a/tests/test_binding.py b/tests/test_binding.py index d01bae821..f3a3c87d3 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -70,16 +70,16 @@ class Model: element = ui.input().bind_value(data, 'text') screen.open('/') - screen.should_contain('one') + screen.should_contain_input('one') screen.type(Keys.TAB) screen.type('two') - screen.should_contain('two') + screen.should_contain_input('two') assert data.text == 'two' data.text = 'three' - screen.should_contain('three') + screen.should_contain_input('three') element.set_value('four') - screen.should_contain('four') + screen.should_contain_input('four') assert data.text == 'four' element.value = 'five' - screen.should_contain('five') + screen.should_contain_input('five') assert data.text == 'five'