1
0
Fork 0
EnglishPal/app/test/test_add_word.py

32 lines
872 B
Python
Raw Normal View History

2024-07-04 10:18:47 +08:00
import time
from helper import signup
2021-04-06 16:22:03 +08:00
2024-07-04 10:18:47 +08:00
def test_add_word(URL, driver):
2021-04-06 16:22:03 +08:00
try:
2024-07-04 10:18:47 +08:00
username, password = signup(URL, driver) # sign up a new account and automatically log in
time.sleep(1)
2021-04-06 16:22:03 +08:00
2024-07-04 10:18:47 +08:00
# enter the word in the text area
elem = driver.find_element_by_id('selected-words')
word = 'devour'
2021-04-06 16:22:03 +08:00
elem.send_keys(word)
2024-07-04 10:18:47 +08:00
elem = driver.find_element_by_xpath('//form[1]//button[1]') # 找到"把生词加入我的生词库"按钮
2021-04-06 16:22:03 +08:00
elem.click()
2024-07-04 10:18:47 +08:00
elem = driver.find_element_by_name('add-btn') # 找到"加入我的生词簿"按钮
2021-04-06 16:22:03 +08:00
elem.click()
elems = driver.find_elements_by_xpath("//p[@class='new-word']/a")
2024-07-04 10:18:47 +08:00
2021-04-06 16:22:03 +08:00
found = 0
for elem in elems:
if word in elem.text:
found = 1
break
2024-07-04 10:18:47 +08:00
2021-04-06 16:22:03 +08:00
assert found == 1
2024-07-04 10:18:47 +08:00
finally:
2021-04-06 16:22:03 +08:00
driver.quit()