1
0
Fork 0

Compare commits

...

7 Commits

Author SHA1 Message Date
万梓锟 7af9b4656f 更新 app/test/test_bug561_wanzikun.py 2024-05-27 11:04:19 +08:00
万梓锟 a662626dc4 上传文件至 app/test
更新脚本
2024-05-26 20:07:38 +08:00
万梓锟 deb5fa9c54 删除 app/test/test_bug561_wanzikun.py
更新脚本
2024-05-26 20:06:42 +08:00
万梓锟 b68c62a7b8 上传文件至 app/test
更新了test内容
2024-05-17 15:35:50 +08:00
万梓锟 4ff33b377f 删除 test_bug561_WanZiKun.py
更新test内容并更换位置
2024-05-17 15:31:39 +08:00
万梓锟 3e3aa44087 test_bug561_WanZiKun
bug测试代码
2024-05-08 21:39:41 +08:00
万梓锟 13323ed123 DeBug561-WanZiKun
修复bug561前后切换文章无法正常显示生词高光的功能
2024-05-08 21:36:01 +08:00
2 changed files with 74 additions and 0 deletions

View File

@ -232,6 +232,9 @@
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
check_next(data['result_of_generate_article']); check_next(data['result_of_generate_article']);
// 在加载新文章后调用高亮函数
toggleHighlighting();
} }
} }
}); });
@ -245,6 +248,8 @@
if(data['today_article']){ if(data['today_article']){
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
// 在加载新文章后调用高亮函数
toggleHighlighting();
} }
} }
}); });

View File

@ -0,0 +1,69 @@
import time
import pytest
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 NoSuchElementException, TimeoutException
from selenium.webdriver import ActionChains
# 导入 app/test/conftest.py 中的 signup 函数
from app.test.conftest import signup
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(URL, driver):
try:
driver.maximize_window()
username, password = signup(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.")