测试文件也进行了修改,为了避免选择的单词出现空格的情况,增加了一个判断,若选中空格,则更换文章再次选择,这样总会选择到非空格的单词。
parent
9537024339
commit
64a82bee22
|
@ -9,55 +9,50 @@ from selenium.webdriver.common.action_chains import ActionChains
|
||||||
from helper import signup
|
from helper import signup
|
||||||
|
|
||||||
|
|
||||||
def select(driver):
|
def select_one(driver):
|
||||||
text_element = driver.find_element(By.ID, 'article')
|
question = driver.find_element(By.ID, 'question')
|
||||||
|
|
||||||
# 创建ActionChains对象
|
# 创建ActionChains对象
|
||||||
actions = ActionChains(driver)
|
actions = ActionChains(driver)
|
||||||
|
|
||||||
# 模拟鼠标移动到文本元素上
|
# 模拟鼠标移动到文本元素上
|
||||||
actions.move_to_element(text_element)
|
actions.move_to_element(question)
|
||||||
|
|
||||||
# 模拟鼠标按下并拖动以选择文本
|
|
||||||
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.double_click()
|
|
||||||
actions.perform()
|
|
||||||
actions.release() # 释放鼠标按钮
|
|
||||||
|
|
||||||
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.double_click()
|
||||||
actions.perform()
|
actions.perform()
|
||||||
|
|
||||||
# 获取选中的文本
|
# 获取选中的文本
|
||||||
selected_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
return driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
||||||
|
|
||||||
#再次选取
|
def select_two(driver):
|
||||||
select(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)
|
time.sleep(1)
|
||||||
|
# 模拟鼠标移动到文本元素上
|
||||||
|
actions.move_to_element(question)
|
||||||
|
|
||||||
|
# 模拟鼠标按下并拖动以选择文本
|
||||||
|
actions.double_click()
|
||||||
|
actions.perform()
|
||||||
|
|
||||||
|
|
||||||
|
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')
|
selected_second_words = driver.find_element(By.ID, 'selected-words').get_attribute('value')
|
||||||
assert selected_second_words.strip() == "", "选中的单词被删除"
|
assert selected_second_words.strip() == "", "选中的单词被删除"
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue