diff --git a/app/test/test_bug551_XieShangHai.py b/app/test/test_bug551_XieShangHai.py new file mode 100644 index 0000000..4aa02f2 --- /dev/null +++ b/app/test/test_bug551_XieShangHai.py @@ -0,0 +1,49 @@ +import pytest +from selenium import webdriver +from selenium.webdriver.common.action_chains import ActionChains +import time +from webdriver_manager.chrome import ChromeDriverManager + +@pytest.fixture +def driver(): + # 初始化浏览器驱动 + driver = webdriver.Chrome(ChromeDriverManager().install()) + driver.maximize_window() + + yield driver + # 测试结束后关闭浏览器 + driver.quit() + +def test_highlight(driver): + # 打开网页 + driver.get("http://127.0.0.1:5000/") + + # login + elem = driver.find_element_by_link_text('登录') + elem.click() + uname = 'xshh' + password = 'kk123ll' + elem = driver.find_element_by_id('username') + elem.send_keys(uname) + elem = driver.find_element_by_id('password') + elem.send_keys(password) + + elem = driver.find_element_by_class_name('btn') # 找到登录按钮 + elem.click() + + article = driver.find_element_by_id("article") + + # 创建 ActionChains 对象 + actions = ActionChains(driver) + + # 移动鼠标到起点位置 + actions.move_to_element(article) + # 按下鼠标左键 + actions.click_and_hold() + # 拖动鼠标到结束位置 + actions.move_by_offset(450,60) + # 释放鼠标左键 + actions.release() + # 执行操作链 + actions.perform() + time.sleep(15)