From 9c013085e77d48d3f4d563475bde0204ae4df9d9 Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Fri, 12 Apr 2024 19:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20app/test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug546_lixiaofeng.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/test/test_bug546_lixiaofeng.py diff --git a/app/test/test_bug546_lixiaofeng.py b/app/test/test_bug546_lixiaofeng.py new file mode 100644 index 0000000..24135db --- /dev/null +++ b/app/test/test_bug546_lixiaofeng.py @@ -0,0 +1,54 @@ +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 = 'lxf' + password = 'kklo567' + 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() + + # 取消勾选“划词入库按钮” + highlight_checkbox = driver.find_element_by_id("test1") + driver.execute_script("arguments[0].click();", highlight_checkbox) + + article = driver.find_element_by_id("article") + + # 创建 ActionChains 对象 + actions = ActionChains(driver) + + # 移动鼠标到起点位置 + actions.move_to_element(article) + # actions.move_to_element_with_offset(article, 50, 100) + # 按下鼠标左键 + actions.click_and_hold() + # 拖动鼠标到结束位置 + actions.move_by_offset(400,50) + # 释放鼠标左键 + actions.release() + # 执行操作链 + actions.perform() + time.sleep(10)