Skip to content

Commit

Permalink
clean up test, remove some waits, introduce alias wait_for
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Feb 3, 2023
1 parent 5a98cb9 commit 95364b7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 32 deletions.
3 changes: 3 additions & 0 deletions tests/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def should_contain(self, text: str) -> None:
return
self.find(text)

def wait_for(self, text: str) -> None:
self.should_contain(text)

def should_not_contain(self, text: str, wait: float = 0.5) -> None:
assert self.selenium.title != text
self.selenium.implicitly_wait(wait)
Expand Down
15 changes: 5 additions & 10 deletions tests/test_auto_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ async def page(client: Client):
screen.should_contain('before connected')
screen.should_contain('after connected')
screen.should_not_contain('one')
screen.wait(0.5)
screen.should_contain('one')
screen.wait_for('one')
screen.should_not_contain('two')
screen.wait(0.5)
screen.should_contain('two')
screen.wait_for('two')
screen.should_not_contain('three')
screen.wait(0.5)
screen.should_contain('three')
screen.wait_for('three')


def test_autoupdate_on_async_event_handler(screen: Screen):
Expand Down Expand Up @@ -102,11 +99,9 @@ async def update():
screen.open('/')
screen.should_contain('0')
screen.should_not_contain('1')
screen.wait(2.0)
screen.should_contain('1')
screen.wait_for('1')
screen.should_not_contain('2')
screen.wait(2.0)
screen.should_contain('2')
screen.wait_for('2')


def test_adding_elements_from_different_tasks(screen: Screen):
Expand Down
1 change: 0 additions & 1 deletion tests/test_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_open_close_dialog(screen: Screen):
screen.open('/')
screen.should_not_contain('Content')
screen.click('Open')
screen.wait(0.5)
screen.should_contain('Content')
screen.click('Close')
screen.wait(0.5)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_click_events(screen: Screen):
screen.click('click_sync_with_args')
screen.click('click_async_no_args')
screen.click('click_async_with_args')
screen.wait(0.5)
screen.should_contain('click_sync_no_args')
screen.should_contain('click_sync_with_args')
screen.should_contain('click_async_no_args')
Expand All @@ -55,7 +54,6 @@ def test_generic_events(screen: Screen):
screen.click('click_sync_with_args')
screen.click('click_async_no_args')
screen.click('click_async_with_args')
screen.wait(0.5)
screen.should_contain('click_sync_no_args')
screen.should_contain('click_sync_with_args')
screen.should_contain('click_async_no_args')
Expand Down
1 change: 0 additions & 1 deletion tests/test_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_open_close_expansion(screen: Screen):
screen.should_contain('Expansion')
screen.should_not_contain('Content')
screen.click('Open')
screen.wait(0.5)
screen.should_contain('Content')
screen.click('Close')
screen.wait(0.5)
Expand Down
27 changes: 13 additions & 14 deletions tests/test_javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@ async def set_title() -> None:
assert screen.selenium.title == 'NiceGUI'
screen.click('change title')
screen.wait(0.5)
assert screen.selenium.title == 'A New Title'
assert screen.selenium.title != 'NiceGUI'
screen.should_contain('A New Title')


def test_run_javascript_on_value_change(screen: Screen):
@ui.page('/')
async def main_page(client: Client):
async def page(client: Client):
async def set_title(e: ValueChangeEventArguments) -> None:
await ui.run_javascript(f'document.title = "{e.value}"')
ui.radio(['Page Title A', 'Page Title B'], on_change=set_title)
await ui.run_javascript(f'document.title = "Page {e.value}"')
ui.radio(['A', 'B'], on_change=set_title)
await client.connected()
await ui.run_javascript('document.title = "Initial Page Title"')
await ui.run_javascript('document.title = "Initial Title"')

screen.open('/')
screen.wait(0.3)
assert screen.selenium.title == 'Initial Page Title'
screen.click('Title B')
screen.wait(0.3)
assert screen.selenium.title == 'Page Title B'
screen.click('Title A')
screen.wait(0.3)
assert screen.selenium.title == 'Page Title A'
screen.wait(0.5)
screen.should_contain('Initial Title')
screen.click('A')
screen.wait(0.5)
screen.should_contain('Page A')
screen.click('B')
screen.wait(0.5)
screen.should_contain('Page B')


def test_run_javascript_before_client_connected(screen: Screen):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ def test_time(screen: Screen):
screen.should_contain('01:23')

screen.click('8')
screen.wait(0.1)
screen.should_contain('08:23')

screen.click('45')
screen.wait(0.1)
screen.should_contain('08:45')

screen.click('PM')
screen.wait(0.1)
screen.should_contain('20:45')
1 change: 0 additions & 1 deletion tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def page():
screen.open('/')
screen.should_not_contain(test_path1.name)
screen.selenium.find_element(By.CLASS_NAME, 'q-uploader__input').send_keys(str(test_path1))
screen.wait(0.3)
screen.should_contain(f'uploaded {test_path1.name}')
screen.switch_to(0)
screen.should_not_contain(f'uploaded {test_path1.name}')

0 comments on commit 95364b7

Please sign in to comment.