EnglishPal/app/test/helper.py

34 lines
1.0 KiB
Python
Raw Normal View History

2024-04-09 12:11:30 +08:00
import uuid
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException
def signup(URL, driver):
username = 'TestUser' + str(uuid.uuid1()).split('-')[0].title()
password = '[Abc+123]'
driver.get(URL)
elem = driver.find_element_by_link_text('注册')
elem.click()
elem = driver.find_element_by_id('username')
elem.send_keys(username)
elem = driver.find_element_by_id('password')
elem.send_keys(password)
elem = driver.find_element_by_id('password2')
elem.send_keys(password)
2024-04-09 13:21:44 +08:00
elem = driver.find_element_by_class_name('btn') # 找到"注册"按钮
2024-04-09 12:11:30 +08:00
elem.click()
try:
WebDriverWait(driver, 1).until(EC.alert_is_present())
driver.switch_to.alert.accept()
except (UnexpectedAlertPresentException, NoAlertPresentException):
pass
return username, password