Browse Source

refactoring to make tests more readable

Rodja Trappe 2 years ago
parent
commit
1f36b9b110
2 changed files with 11 additions and 3 deletions
  1. 2 3
      tests/test_pages.py
  2. 9 0
      tests/user.py

+ 2 - 3
tests/test_pages.py

@@ -58,14 +58,13 @@ def test_creating_new_page_after_startup(user: User):
     user.should_see('page created after startup')
     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('/')
     @ui.page('/')
     def page():
     def page():
         ui.joystick()
         ui.joystick()
 
 
     user.open('/')
     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(('joystick.js' in s) for s in srcs)
     assert any(('nipplejs.min.js' in s) for s in srcs)
     assert any(('nipplejs.min.js' in s) for s in srcs)
 
 

+ 9 - 0
tests/user.py

@@ -56,3 +56,12 @@ class User():
 
 
     def get_body(self) -> str:
     def get_body(self) -> str:
         return self.selenium.find_element(By.TAG_NAME, 'body').text
         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)