2024-05-21 20:00:32 +08:00
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
from selenium.webdriver.common.action_chains import ActionChains
|
|
|
|
|
|
|
|
from helper import signup
|
|
|
|
|
|
|
|
|
2024-05-26 11:27:15 +08:00
|
|
|
def select_one(driver):
|
|
|
|
question = driver.find_element(By.ID, 'question')
|
2024-05-21 20:00:32 +08:00
|
|
|
# 创建ActionChains对象
|
|
|
|
actions = ActionChains(driver)
|
|
|
|
|
|
|
|
# 模拟鼠标移动到文本元素上
|
2024-05-26 11:27:15 +08:00
|
|
|
actions.move_to_element(question)
|
2024-05-21 20:00:32 +08:00
|
|
|
|
|
|
|
# 模拟鼠标按下并拖动以选择文本
|
2024-05-26 11:27:15 +08:00
|
|
|
actions.double_click()
|
2024-05-21 20:00:32 +08:00
|
|
|
actions.perform()
|
|
|
|
|
2024-05-26 11:27:15 +08:00
|
|
|
# 获取选中的文本
|
|
|
|
return driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
2024-05-21 20:00:32 +08:00
|
|
|
|
2024-05-26 11:27:15 +08:00
|
|
|
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)
|
2024-05-21 20:00:32 +08:00
|
|
|
|
|
|
|
# 模拟鼠标按下并拖动以选择文本
|
|
|
|
actions.double_click()
|
|
|
|
actions.perform()
|
2024-05-26 11:27:15 +08:00
|
|
|
|
2024-05-21 20:00:32 +08:00
|
|
|
|
|
|
|
def test_selected_second_word(driver, URL):
|
|
|
|
try:
|
2024-05-26 11:27:15 +08:00
|
|
|
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)
|
2024-05-21 20:00:32 +08:00
|
|
|
selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
|
|
|
assert selected_second_words.strip() == "", "选中的单词被删除"
|
|
|
|
finally:
|
|
|
|
driver.quit()
|