Skip to content

Commit

Permalink
splitting screen.find and screen.should_contain_input
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Feb 2, 2023
1 parent 947873a commit 3670653
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions tests/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 3670653

Please sign in to comment.