From b33d6a77f72c1bdd0646236752d7aa9072b75a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B0=9A=E6=B5=B7?= <1337633392@qq.com> Date: Sun, 19 May 2024 18:27:54 +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_bug551_XieShangHai.py | 67 ++++++++++------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/app/test/test_bug551_XieShangHai.py b/app/test/test_bug551_XieShangHai.py index 4aa02f2..1d14554 100644 --- a/app/test/test_bug551_XieShangHai.py +++ b/app/test/test_bug551_XieShangHai.py @@ -1,49 +1,28 @@ -import pytest -from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import time -from webdriver_manager.chrome import ChromeDriverManager +from helper import signup -@pytest.fixture -def driver(): - # 初始化浏览器驱动 - driver = webdriver.Chrome(ChromeDriverManager().install()) - driver.maximize_window() +def test_highlight(driver, URL): + try: + # 打开网页 + driver.maximize_window() + driver.get(URL) + + # 注册 + time.sleep(1) + signup(URL, driver) + time.sleep(2) - yield driver - # 测试结束后关闭浏览器 - driver.quit() + # 选中单词(移动鼠标到起点位置、按下鼠标左键、拖动鼠标到结束位置、释放鼠标左键、执行操作链) + article = driver.find_element_by_id("article") + actions = ActionChains(driver) + actions.move_to_element(article).click_and_hold().move_by_offset(450,60).release().perform() -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) + # 判断所有高亮单词是否有间隔 + marks = driver.find_elements_by_tag_name("mark") + for mark in marks: + assert mark.value_of_css_property("padding") == '0px' + finally: + # 测试结束后关闭浏览器 + driver.quit() + \ No newline at end of file