Skip to content

Commit

Permalink
refactoring to make tests more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Sep 21, 2022
1 parent 40c6d75 commit 1f36b9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ def page():
user.should_see('page created after startup')


def test_automatic_loading_of_dependencies(user: User):
def test_automatic_loading_of_joystick_dependency(user: User):
@ui.page('/')
def page():
ui.joystick()

user.open('/')
script_tags = user.selenium.find_elements_by_tag_name('script')
srcs = [tag.get_attribute('src') for tag in script_tags]
srcs = user.get_attributes('script', 'src')
assert any(('joystick.js' in s) for s in srcs)
assert any(('nipplejs.min.js' in s) for s in srcs)

Expand Down
9 changes: 9 additions & 0 deletions tests/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ def find(self, text: str) -> WebElement:

def get_body(self) -> str:
return self.selenium.find_element(By.TAG_NAME, 'body').text

def get_tags(self, name: str) -> list[WebElement]:
return self.selenium.find_elements(By.TAG_NAME, name)

def get_attributes(self, tag: str, attribute: str) -> list[str]:
return [t.get_attribute(attribute) for t in self.get_tags(tag)]

def sleep(self, t: float) -> None:
time.sleep(t)

0 comments on commit 1f36b9b

Please sign in to comment.