2023-12-28 05:29:25 +08:00
|
|
|
# Each time you run the test script reset the database.
|
|
|
|
# For this test script you won't need it since it changes
|
|
|
|
# the Ta's email and name automatically
|
2023-12-22 21:59:17 +08:00
|
|
|
import re
|
|
|
|
import time
|
|
|
|
import pytest
|
2023-12-28 05:29:25 +08:00
|
|
|
from faker import Faker
|
2023-12-22 21:59:17 +08:00
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
faker = Faker()
|
|
|
|
@pytest.mark.skip(reason="function to be used in the test_scripts")
|
|
|
|
def createTA(driver, TA_name, emails, password):
|
|
|
|
full_name = driver.find_element('name', 'fullname')
|
|
|
|
full_name.send_keys(TA_name)
|
|
|
|
email = driver.find_element('name', 'email')
|
|
|
|
email.send_keys(emails)
|
|
|
|
pas = driver.find_element('name', 'password')
|
|
|
|
pas.send_keys(password)
|
|
|
|
usr_type = driver.find_element('name', 'type')
|
|
|
|
usr_type.click()
|
|
|
|
click_create = driver.find_element('name', 'create_btn')
|
|
|
|
click_create.click()
|
|
|
|
|
|
|
|
def login_lecturer(drivers):
|
2023-12-22 21:59:17 +08:00
|
|
|
# Open the website
|
2023-12-28 05:29:25 +08:00
|
|
|
drivers.get("http://localhost/lrr/")
|
|
|
|
drivers.maximize_window()
|
2023-12-22 21:59:17 +08:00
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
username_input = drivers.find_element('name', "user")
|
2023-12-22 21:59:17 +08:00
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
password_input = drivers.find_element('name', "password")
|
2023-12-22 21:59:17 +08:00
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
login_button = drivers.find_element('id', "login_btn")
|
2023-12-22 21:59:17 +08:00
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
# login as a Lecturer
|
2023-12-22 21:59:17 +08:00
|
|
|
username_input.send_keys("lanhui@qq.com")
|
|
|
|
password_input.send_keys("nil1234H@")
|
|
|
|
# Click the login button
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(5)
|
2023-12-22 21:59:17 +08:00
|
|
|
login_button.click()
|
2023-12-28 05:29:25 +08:00
|
|
|
admin_tab = drivers.find_element('id', 'admin_tab')
|
2023-12-22 21:59:17 +08:00
|
|
|
admin_tab.click()
|
2023-12-28 05:29:25 +08:00
|
|
|
|
|
|
|
cte_instructor = drivers.find_element('id', 'tab_ins_accounts')
|
2023-12-22 21:59:17 +08:00
|
|
|
cte_instructor.click()
|
|
|
|
time.sleep(25)
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
def test_createTA():
|
|
|
|
driver_open = webdriver.Chrome()
|
|
|
|
driver_open.maximize_window()
|
|
|
|
login_lecturer(driver_open)
|
2023-12-22 21:59:17 +08:00
|
|
|
try:
|
2023-12-28 05:29:25 +08:00
|
|
|
fullname = faker.name()
|
|
|
|
email = faker.email()
|
|
|
|
password = "new1452345678"
|
|
|
|
createTA(driver_open, fullname, email,password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
2023-12-22 21:59:17 +08:00
|
|
|
|
|
|
|
get_output = WebDriverWait(driver_open, 10).until(
|
|
|
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
2023-12-28 05:29:25 +08:00
|
|
|
)
|
2023-12-22 21:59:17 +08:00
|
|
|
get_output.click()
|
|
|
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
|
|
|
txt_alert = get_output_msg.text
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(20)
|
2023-12-22 21:59:17 +08:00
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
if txt_alert.find("TA user created successfully") == 0:
|
|
|
|
logout_button = WebDriverWait(driver_open, 15).until(
|
|
|
|
EC.element_to_be_clickable(
|
|
|
|
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
|
|
|
|
)
|
|
|
|
time.sleep(5)
|
2023-12-22 21:59:17 +08:00
|
|
|
logout_button.click()
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(10)
|
2023-12-22 21:59:17 +08:00
|
|
|
username_input = driver_open.find_element('name', "user")
|
|
|
|
password_input = driver_open.find_element('name', "password")
|
|
|
|
login_button = driver_open.find_element('id', "login_btn")
|
|
|
|
# login as the new TA
|
|
|
|
username_input.send_keys(email) # login with credentials of the created TA
|
|
|
|
password_input.send_keys(password)
|
|
|
|
# Click the login button
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
login_button.click()
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(20)
|
|
|
|
elif txt_alert.find("Email address ") == 0:
|
|
|
|
|
|
|
|
time.sleep(22)
|
|
|
|
driver_open.quit()
|
2023-12-22 21:59:17 +08:00
|
|
|
|
|
|
|
else:
|
|
|
|
driver_open.quit()
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(5)
|
2023-12-22 21:59:17 +08:00
|
|
|
|
|
|
|
finally:
|
|
|
|
driver_open.quit()
|
|
|
|
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
def test_generate_password():
|
|
|
|
driver_open = webdriver.Chrome()
|
|
|
|
login_lecturer(driver_open)
|
2023-12-22 21:59:17 +08:00
|
|
|
try:
|
2023-12-28 05:29:25 +08:00
|
|
|
fullname = faker.name()
|
|
|
|
email = faker.email()
|
2023-12-22 21:59:17 +08:00
|
|
|
password = ""
|
|
|
|
createTA(driver_open, fullname, email,
|
|
|
|
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
|
|
|
|
|
|
|
get_output = WebDriverWait(driver_open, 5).until(
|
|
|
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
|
|
|
)
|
|
|
|
get_output.click()
|
|
|
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
|
|
|
txt_alert = get_output_msg.text
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
if txt_alert.find("TA user created successfully") == 0:
|
|
|
|
time.sleep(20)
|
|
|
|
email_pattern = r"Use email (\S+) as account name"
|
|
|
|
password_pattern = r" (\S+)\ as password."
|
|
|
|
email_match = re.search(email_pattern, txt_alert)
|
|
|
|
password_match = re.search(password_pattern, txt_alert)
|
|
|
|
if email_match and password_match:
|
|
|
|
# Extract email and password from the matches
|
|
|
|
email = email_match.group(1)
|
|
|
|
password = password_match.group(1)
|
2023-12-28 05:29:25 +08:00
|
|
|
logout_button = WebDriverWait(driver_open, 10).until(
|
|
|
|
EC.element_to_be_clickable(
|
|
|
|
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
|
|
|
|
)
|
2023-12-22 21:59:17 +08:00
|
|
|
logout_button.click()
|
|
|
|
time.sleep(15)
|
|
|
|
username_input = driver_open.find_element('name', "user")
|
|
|
|
password_input = driver_open.find_element('name', "password")
|
|
|
|
login_button = driver_open.find_element('id', "login_btn")
|
|
|
|
# login as the new TA
|
|
|
|
username_input.send_keys(email) # login with credentials of the created TA
|
|
|
|
password_input.send_keys(password)
|
|
|
|
# Click the login button
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
login_button.click()
|
|
|
|
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
elif txt_alert.find("Email address ") == 0:
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(22)
|
|
|
|
driver_open.quit()
|
|
|
|
|
2023-12-22 21:59:17 +08:00
|
|
|
else:
|
|
|
|
driver_open.quit()
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
time.sleep(5)
|
2023-12-22 21:59:17 +08:00
|
|
|
|
|
|
|
finally:
|
|
|
|
driver_open.quit()
|
|
|
|
|
2023-12-28 05:29:25 +08:00
|
|
|
def test_existingTA():
|
|
|
|
driver_open = webdriver.Chrome()
|
|
|
|
login_lecturer(driver_open)
|
|
|
|
try:
|
|
|
|
# Use email nreyes@example.com as account name and new1452345678 as password.
|
|
|
|
fullname = "Maria"
|
|
|
|
email = "nreyes@example.com"
|
|
|
|
password = "new1452345678"
|
|
|
|
createTA(driver_open, fullname, email,
|
|
|
|
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
|
|
|
|
|
|
|
get_output = WebDriverWait(driver_open, 5).until(
|
|
|
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
|
|
|
)
|
|
|
|
get_output.click()
|
|
|
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
|
|
|
txt_alert = get_output_msg.text
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
if txt_alert.find("TA user created successfully") == 0:
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
|
|
|
|
elif txt_alert.find("Email address ") == 0:
|
|
|
|
time.sleep(22)
|
|
|
|
driver_open.quit()
|
|
|
|
|
|
|
|
else:
|
|
|
|
driver_open.quit()
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
driver_open.quit()
|