From a0c9b82ee7aaed8c10cd268f03e45e0ec0d7033d Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 27 May 2024 14:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83=E4=BA=86=E4=B8=80=E4=B8=8Bta?= =?UTF-8?q?ngxinyuan=E5=B0=8F=E7=BB=84=E7=9A=84=E5=86=99=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E9=80=89=E5=8F=96=E5=8D=95=E8=AF=8D=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=94=B1=E6=A8=A1=E6=8B=9F=E9=BC=A0=E6=A0=87=E9=80=89?= =?UTF-8?q?=E5=8F=96=E5=8D=95=E8=AF=8D=E6=94=B9=E4=B8=BA=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?id=E8=8E=B7=E5=8F=96=E6=96=87=E7=AB=A0=EF=BC=8C=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E4=BB=8E=E6=96=87=E7=AB=A0=E4=B8=AD=E6=8C=91=E9=80=89?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8D=95=E8=AF=8D=E6=94=BE=E5=85=A5=E7=94=9F?= =?UTF-8?q?=E8=AF=8D=E6=A1=86=E4=B8=AD=EF=BC=8C=E8=BF=99=E6=A0=B7=E6=98=AF?= =?UTF-8?q?=E4=B8=80=E5=AE=9A=E5=8F=AF=E4=BB=A5=E9=80=89=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=B8=AD=E7=9A=84=E5=8D=95=E8=AF=8D=E3=80=82?= =?UTF-8?q?=20=E7=84=B6=E5=90=8E=E6=A0=B9=E6=8D=AEspan=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E5=88=B0=E9=80=89=E6=8B=A9=E7=9A=84=E7=94=9F?= =?UTF-8?q?=E8=AF=8D=EF=BC=8C=E5=8F=8C=E5=87=BB=E5=86=8D=E6=AC=A1=E9=80=89?= =?UTF-8?q?=E6=8B=A9=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=9C=A8=E7=94=9F=E8=AF=8D?= =?UTF-8?q?=E6=A1=86=E4=B8=AD=E5=88=A0=E9=99=A4=E8=AF=A5=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/test_bug545_HuangHuiLing.py | 39 +++++++++------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/app/test/test_bug545_HuangHuiLing.py b/app/test/test_bug545_HuangHuiLing.py index 4ebc504..21ddeea 100644 --- a/app/test/test_bug545_HuangHuiLing.py +++ b/app/test/test_bug545_HuangHuiLing.py @@ -8,33 +8,24 @@ from selenium.webdriver.common.action_chains import ActionChains from helper import signup +def has_punctuation(s): + return any(c in string.punctuation for c in s) def select_one(driver): - question = driver.find_element(By.ID, 'question') - # 创建ActionChains对象 - actions = ActionChains(driver) - - # 模拟鼠标移动到文本元素上 - actions.move_to_element(question) - - # 模拟鼠标按下并拖动以选择文本 - actions.double_click() - actions.perform() - - # 获取选中的文本 - return driver.find_element(By.ID, 'selected-words').get_attribute('value') + elem = driver.find_element(By.ID, 'article') + essay_content = elem.text + valid_word = random.choice([word for word in essay_content.split() if len(word) >= 6 and not has_punctuation( + word) and 'font>' not in word and 'br>' not in word and 'p>' not in word]) + driver.find_element(By.ID, 'selected-words').send_keys(valid_word) + driver.find_element(By.ID, 'article').click() + return valid_word def select_two(driver): - question = driver.find_element(By.ID, 'question') - article = driver.find_element(By.ID, 'article_title') + word = driver.find_element(By.CLASS_NAME, 'highlighted') -# 创建ActionChains对象 + # 创建ActionChains对象 actions = ActionChains(driver) - actions.move_to_element(article) - actions.click() - time.sleep(1) -# 模拟鼠标移动到文本元素上 - actions.move_to_element(question) + actions.move_to_element(word) # 模拟鼠标按下并拖动以选择文本 actions.double_click() @@ -45,12 +36,6 @@ def test_selected_second_word(driver, URL): try: 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')