From 64a82bee228e2c6bacbea300f595760556a4afa8 Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Sun, 26 May 2024 11:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=E4=B9=9F?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=B8=BA?= =?UTF-8?q?=E4=BA=86=E9=81=BF=E5=85=8D=E9=80=89=E6=8B=A9=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E8=AF=8D=E5=87=BA=E7=8E=B0=E7=A9=BA=E6=A0=BC=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E8=8B=A5=E9=80=89=E4=B8=AD=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=EF=BC=8C=E5=88=99=E6=9B=B4=E6=8D=A2=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E9=80=89=E6=8B=A9=EF=BC=8C=E8=BF=99=E6=A0=B7?= =?UTF-8?q?=E6=80=BB=E4=BC=9A=E9=80=89=E6=8B=A9=E5=88=B0=E9=9D=9E=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E5=8D=95=E8=AF=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug545_HuangHuiLing.py | 71 +++++++++++++--------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 4b80afa..4ebc504 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -9,55 +9,50 @@ from selenium.webdriver.common.action_chains import ActionChains from helper import signup -def select(driver): - text_element = driver.find_element(By.ID, 'article') - +def select_one(driver): + question = driver.find_element(By.ID, 'question') # 创建ActionChains对象 actions = ActionChains(driver) # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) - - # 模拟鼠标按下并拖动以选择文本 - actions.click() - actions.perform() - time.sleep(1) - # 找到包含要选择文字的元素 - text_element = driver.find_element(By.ID, 'article_title') - - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) + actions.move_to_element(question) # 模拟鼠标按下并拖动以选择文本 actions.double_click() actions.perform() - actions.release() # 释放鼠标按钮 + + # 获取选中的文本 + return driver.find_element(By.ID, 'selected-words').get_attribute('value') + +def select_two(driver): + question = driver.find_element(By.ID, 'question') + article = driver.find_element(By.ID, 'article_title') + +# 创建ActionChains对象 + actions = ActionChains(driver) + actions.move_to_element(article) + actions.click() + time.sleep(1) +# 模拟鼠标移动到文本元素上 + actions.move_to_element(question) + + # 模拟鼠标按下并拖动以选择文本 + actions.double_click() + actions.perform() + def test_selected_second_word(driver, URL): try: - username, password = signup(URL, driver) - # 找到包含要选择文字的元素 - text_element = driver.find_element(By.ID, 'article_title') - - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(text_element) - - # 模拟鼠标按下并拖动以选择文本 - actions.double_click() - actions.perform() - - # 获取选中的文本 - selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') - - #再次选取 - select(driver) - time.sleep(1) + signup(URL, driver) + selected_words = select_one(driver); + while selected_words.strip() == "": + load_next_article = driver.find_element(By.ID, "load_next_article") + action_chains = ActionChains(driver) + action_chains.click(load_next_article).perform() + time.sleep(1) + selected_words = select_one(driver) + assert selected_words.strip() != "", "选中的单词被放置框中" + select_two(driver) selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value') assert selected_second_words.strip() == "", "选中的单词被删除" finally: