Improve the test script

Hui-Organize
Lan Hui 2024-09-22 11:28:02 +08:00
parent b1dbd94b00
commit 33f997412b
1 changed files with 8 additions and 7 deletions

View File

@ -1,15 +1,16 @@
from helper import login
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def test_admin_can_create_lecturer_account(driver, url, admin_username, admin_password, restore_database):
# Administrator (admin@qq.com, password 123) logs in
driver.maximize_window()
login(driver, url, admin_username, admin_password)
# Create a Lecture account for mrlan@qq.com, password [123Abc!]
# Create a Lecturer account for Mr Lan (mrlan@qq.com, password [123Abc!])
tab = driver.find_element(By.ID, 'tab_ins_accounts')
tab.click()
elem = driver.find_element(By.NAME, 'fullname')
@ -22,20 +23,20 @@ def test_admin_can_create_lecturer_account(driver, url, admin_username, admin_pa
radio_button.click()
button = driver.find_element(By.NAME, 'create_btn')
button.click()
time.sleep(1)
# Log out Admin
# Log out Admin account
logout_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable(
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]")
)
)
logout_button.click()
time.sleep(1)
# Log in Lecture account
# Log in Lecturer account
login(driver, url, 'mrlan@qq.com', '123Abc!!')
elems = driver.find_elements(By.CLASS_NAME, 'nav-link')
assert '(Lecturer)' in elems[0].text
assert 'Mr Lan' in elems[0].text
driver.quit()