From deb5fa9c54f4b6a1636a108f226312518f3dce09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E6=A2=93=E9=94=9F?= <1640384813@qq.com> Date: Sun, 26 May 2024 20:06:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20app/test/test=5Fbug561=5Fw?= =?UTF-8?q?anzikun.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新脚本 --- app/test/test_bug561_wanzikun.py | 93 -------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 app/test/test_bug561_wanzikun.py diff --git a/app/test/test_bug561_wanzikun.py b/app/test/test_bug561_wanzikun.py deleted file mode 100644 index 4d420c4..0000000 --- a/app/test/test_bug561_wanzikun.py +++ /dev/null @@ -1,93 +0,0 @@ -import time -import uuid -from selenium import webdriver -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException, NoSuchElementException, TimeoutException -from selenium.webdriver import ActionChains - -def signup(URL, driver): - username = 'TestUser' + str(uuid.uuid1()).split('-')[0].title() - password = '[Abc+123]' - - driver.get(URL) - try: - WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, '注册'))).click() - WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, 'username'))).send_keys(username) - driver.find_element(By.ID, 'password').send_keys(password) - driver.find_element(By.ID, 'password2').send_keys(password) - driver.find_element(By.CLASS_NAME, 'btn').click() - - WebDriverWait(driver, 10).until(EC.alert_is_present()) - driver.switch_to.alert.accept() - print(f"Registration successful: {username}") - except (UnexpectedAlertPresentException, NoAlertPresentException, TimeoutException, NoSuchElementException) as e: - print(f"Error during signup: {e}") - raise - return username, password - -def select_text_in_article(driver): - elem = driver.find_element(By.CSS_SELECTOR, '#article') - - action = ActionChains(driver) - # 从左上角点击并按住 - action.move_to_element_with_offset(elem, 0, 0) - action.click_and_hold() - # 移动到右下角的某个位置(例如,右下角偏移100, 100) - action.move_by_offset(100, 100) - action.release() - action.perform() - -def verify_highlight(driver): - # 检查是否有高亮的元素 - highlighted_elements = driver.execute_script(""" - return Array.from(document.querySelectorAll('#article mark')).map(mark => mark.innerText); - """) - print("Highlighted elements:", highlighted_elements) - return len(highlighted_elements) > 0 - -def test_bug561(): - driver = webdriver.Edge() - try: - driver.maximize_window() - base_url = "http://118.25.96.118:90/" - username, password = signup(base_url, driver) - - time.sleep(3) # 等待页面加载完成 - - select_text_in_article(driver) - if verify_highlight(driver): - print("Text highlighted after selection") - else: - print("No text highlighted after selection") - - # 点击“下一页”按钮 - next_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_next_article'))) - next_button.click() - print("Clicked next article button.") - - # 等待“上一页”按钮加载完成 - WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article'))) - print("Next article loaded.") - - # 点击“上一页”按钮 - prev_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article'))) - prev_button.click() - print("Clicked previous article button.") - - # 确认高亮是否保留 - if verify_highlight(driver): - print("Highlighted text preserved after switching articles") - else: - print("Highlighted text not preserved after switching articles") - - except Exception as e: - print(f"Error during test: {e}") - finally: - driver.quit() - print("Driver closed.") - -if __name__ == "__main__": - test_bug561() - input("Press Enter to continue...") # 保持终端窗口打开