72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
import time
|
|
|
|
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
|
|
|
|
|
|
driver_open = webdriver.Chrome()
|
|
|
|
# Open the website
|
|
driver_open.get("http://localhost/lrr/")
|
|
|
|
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 a TA
|
|
username_input.send_keys("lanhui@qq.com")
|
|
password_input.send_keys("nil1234H@")
|
|
# Click the login button
|
|
login_button.click()
|
|
admin_tab = driver_open.find_element('id', 'admin_tab')
|
|
admin_tab.click()
|
|
print("login sucessfully")
|
|
cte_instructor = driver_open.find_element('id', 'tab_ins_accounts')
|
|
cte_instructor.click()
|
|
print(" everything is ok here ")
|
|
t = time.localtime()
|
|
current_time = time.strftime("%H:%M:%S", t)
|
|
time.sleep(25)
|
|
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()
|
|
|
|
|
|
try:
|
|
createTA(driver_open,"lanhuitest","lanhuitest@test.com","lanhui12345678") # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
|
|
|
get_output = WebDriverWait(driver_open, 25).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
|
|
print(f" alert message is : {txt_alert}")
|
|
|
|
try:
|
|
with open('TEST_CREATING_TA.txt', 'a') as test_output:
|
|
test_output.write(f"\n {current_time} check this message : {txt_alert}")
|
|
except Exception as e:
|
|
print(f"unexpected error: {e}")
|
|
|
|
time.sleep(10)
|
|
|
|
finally:
|
|
driver_open.quit()
|
|
|
|
|
|
|