Falko Schindler 2 年之前
父节点
当前提交
55c3365bf8
共有 2 个文件被更改,包括 5 次插入7 次删除
  1. 2 2
      tests/test_pages.py
  2. 3 5
      tests/user.py

+ 2 - 2
tests/test_pages.py

@@ -85,9 +85,9 @@ def test_automatic_loading_of_keyboard_dependency_after_startup(user: User):
         ui.button('activate keyboard', on_click=lambda: ui.keyboard())
 
     user.open('/')
-    assert not any(('keyboard.js' in s) for s in user.get_attributes('script', 'src'))
+    assert not any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
     user.click('activate keyboard')
-    assert any(('keyboard.js' in s) for s in user.get_attributes('script', 'src'))
+    assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
     user.sleep(2)  # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)
 
 

+ 3 - 5
tests/user.py

@@ -1,4 +1,3 @@
-import logging
 import threading
 import time
 
@@ -6,7 +5,6 @@ from nicegui import globals as nicegui_globals
 from nicegui import ui
 from selenium import webdriver
 from selenium.common.exceptions import NoSuchElementException
-from selenium.webdriver.common.by import By
 from selenium.webdriver.remote.webelement import WebElement
 
 
@@ -50,15 +48,15 @@ class User():
 
     def find(self, text: str) -> WebElement:
         try:
-            return self.selenium.find_element(By.XPATH, f'//*[contains(text(),"{text}")]')
+            return self.selenium.find_element_by_xpath(f'//*[contains(text(),"{text}")]')
         except NoSuchElementException:
             raise AssertionError(f'Could not find "{text}" on:\n{self.get_body()}')
 
     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)
+        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)]