Merge pull request 'Bug352-Neil-Revised' (#69) from Bug352-Neil-Revised into Hui-Organize
Reviewed-on: #69Bug486-Nartey
commit
fea32072c3
|
@ -72,7 +72,7 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
|
||||||
Email
|
Email
|
||||||
<input type="text" name="email" placeholder="Email / Student Number" class="form-control" > <br>
|
<input type="text" name="email" placeholder="Email / Student Number" class="form-control" > <br>
|
||||||
Initial password (Enter a strong password or leave it empty to let LRR generate one)
|
Initial password (Enter a strong password or leave it empty to let LRR generate one)
|
||||||
<input type="password" class="form-control" name="password" minlength="8" placeholder="Initial password" > <br>
|
<input type="password" class="form-control" name="password" minlength="8" placeholder="Initial password" > <br>
|
||||||
User type:
|
User type:
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,17 @@
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import pytest
|
import pytest
|
||||||
from faker import Faker
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
faker = Faker()
|
|
||||||
@pytest.mark.skip(reason="function to be used in the test_scripts")
|
def test_restore_database(restore_database):
|
||||||
|
assert restore_database is None
|
||||||
|
|
||||||
|
|
||||||
def createTA(driver, TA_name, emails, password):
|
def createTA(driver, TA_name, emails, password):
|
||||||
full_name = driver.find_element('name', 'fullname')
|
full_name = driver.find_element('name', 'fullname')
|
||||||
full_name.send_keys(TA_name)
|
full_name.send_keys(TA_name)
|
||||||
|
@ -24,56 +27,58 @@ def createTA(driver, TA_name, emails, password):
|
||||||
click_create = driver.find_element('name', 'create_btn')
|
click_create = driver.find_element('name', 'create_btn')
|
||||||
click_create.click()
|
click_create.click()
|
||||||
|
|
||||||
def login_lecturer(drivers):
|
|
||||||
|
def login_lecturer(driver, url):
|
||||||
# Open the website
|
# Open the website
|
||||||
drivers.get("http://localhost/lrr/")
|
driver.get(url)
|
||||||
drivers.maximize_window()
|
driver.maximize_window()
|
||||||
|
|
||||||
username_input = drivers.find_element('name', "user")
|
username_input = driver.find_element('name', "user")
|
||||||
|
|
||||||
password_input = drivers.find_element('name', "password")
|
password_input = driver.find_element('name', "password")
|
||||||
|
|
||||||
login_button = drivers.find_element('id', "login_btn")
|
login_button = driver.find_element('id', "login_btn")
|
||||||
|
|
||||||
# login as a Lecturer
|
# login as a Lecturer
|
||||||
username_input.send_keys("lanhui@qq.com")
|
username_input.send_keys("admin@qq.com")
|
||||||
password_input.send_keys("nil1234H@")
|
password_input.send_keys("123")
|
||||||
# Click the login button
|
# Click the login button
|
||||||
time.sleep(5)
|
time.sleep(2)
|
||||||
login_button.click()
|
login_button.click()
|
||||||
admin_tab = drivers.find_element('id', 'admin_tab')
|
admin_tab = driver.find_element('id', 'admin_tab')
|
||||||
admin_tab.click()
|
admin_tab.click()
|
||||||
|
|
||||||
cte_instructor = drivers.find_element('id', 'tab_ins_accounts')
|
cte_instructor = driver.find_element('id', 'tab_ins_accounts')
|
||||||
cte_instructor.click()
|
cte_instructor.click()
|
||||||
time.sleep(25)
|
time.sleep(2)
|
||||||
|
|
||||||
def test_createTA():
|
|
||||||
driver_open = webdriver.Chrome()
|
def test_createTA(driver, url):
|
||||||
|
driver_open = driver
|
||||||
driver_open.maximize_window()
|
driver_open.maximize_window()
|
||||||
login_lecturer(driver_open)
|
login_lecturer(driver_open, url)
|
||||||
try:
|
try:
|
||||||
fullname = faker.name()
|
fullname = "lanhuitest1"
|
||||||
email = faker.email()
|
email = "lanhuitest1@qq.com"
|
||||||
password = "new1452345678"
|
password = "new1452345678"
|
||||||
createTA(driver_open, fullname, email,password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
createTA(driver_open, fullname, email,password) # CREATE A TA WITH FULLNAME lanhuitest1 email lanhuitest1@qq.com password new1452345678
|
||||||
|
|
||||||
get_output = WebDriverWait(driver_open, 10).until(
|
get_output = WebDriverWait(driver_open, 20).until(
|
||||||
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
||||||
)
|
)
|
||||||
get_output.click()
|
get_output.click()
|
||||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||||
txt_alert = get_output_msg.text
|
txt_alert = get_output_msg.text
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
if txt_alert.find("TA user created successfully") == 0:
|
if txt_alert.find("TA user created successfully") == 0:
|
||||||
logout_button = WebDriverWait(driver_open, 15).until(
|
logout_button = WebDriverWait(driver_open, 20).until(
|
||||||
EC.element_to_be_clickable(
|
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')]"))
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(2)
|
||||||
logout_button.click()
|
logout_button.click()
|
||||||
time.sleep(10)
|
time.sleep(2)
|
||||||
username_input = driver_open.find_element('name', "user")
|
username_input = driver_open.find_element('name', "user")
|
||||||
password_input = driver_open.find_element('name', "password")
|
password_input = driver_open.find_element('name', "password")
|
||||||
login_button = driver_open.find_element('id', "login_btn")
|
login_button = driver_open.find_element('id', "login_btn")
|
||||||
|
@ -81,45 +86,45 @@ def test_createTA():
|
||||||
username_input.send_keys(email) # login with credentials of the created TA
|
username_input.send_keys(email) # login with credentials of the created TA
|
||||||
password_input.send_keys(password)
|
password_input.send_keys(password)
|
||||||
# Click the login button
|
# Click the login button
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
login_button.click()
|
login_button.click()
|
||||||
|
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
elif txt_alert.find("Email address ") == 0:
|
elif txt_alert.find("Email address ") == 0:
|
||||||
|
|
||||||
time.sleep(22)
|
time.sleep(2)
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
|
|
||||||
def test_generate_password():
|
def test_generate_password(driver, url):
|
||||||
driver_open = webdriver.Chrome()
|
driver_open = driver
|
||||||
login_lecturer(driver_open)
|
login_lecturer(driver_open, url)
|
||||||
try:
|
try:
|
||||||
fullname = faker.name()
|
fullname = "lanhuitest2"
|
||||||
email = faker.email()
|
email = "lanhuitest2@qq.com"
|
||||||
password = ""
|
password = ""
|
||||||
createTA(driver_open, fullname, email,
|
createTA(driver_open, fullname, email,
|
||||||
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
password) # CREATE A TA WITH FULLNAME lanhuitest2 email lanhuitest2@qq.com password ""
|
||||||
|
|
||||||
get_output = WebDriverWait(driver_open, 5).until(
|
get_output = WebDriverWait(driver_open, 20).until(
|
||||||
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
||||||
)
|
)
|
||||||
get_output.click()
|
get_output.click()
|
||||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||||
txt_alert = get_output_msg.text
|
txt_alert = get_output_msg.text
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
if txt_alert.find("TA user created successfully") == 0:
|
if txt_alert.find("TA user created successfully") == 0:
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
email_pattern = r"Use email (\S+) as account name"
|
email_pattern = r"Use email (\S+) as account name"
|
||||||
password_pattern = r" (\S+)\ as password."
|
password_pattern = r" (\S+)\ as password."
|
||||||
email_match = re.search(email_pattern, txt_alert)
|
email_match = re.search(email_pattern, txt_alert)
|
||||||
|
@ -128,12 +133,12 @@ def test_generate_password():
|
||||||
# Extract email and password from the matches
|
# Extract email and password from the matches
|
||||||
email = email_match.group(1)
|
email = email_match.group(1)
|
||||||
password = password_match.group(1)
|
password = password_match.group(1)
|
||||||
logout_button = WebDriverWait(driver_open, 10).until(
|
logout_button = WebDriverWait(driver_open, 20).until(
|
||||||
EC.element_to_be_clickable(
|
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()
|
logout_button.click()
|
||||||
time.sleep(15)
|
time.sleep(2)
|
||||||
username_input = driver_open.find_element('name', "user")
|
username_input = driver_open.find_element('name', "user")
|
||||||
password_input = driver_open.find_element('name', "password")
|
password_input = driver_open.find_element('name', "password")
|
||||||
login_button = driver_open.find_element('id', "login_btn")
|
login_button = driver_open.find_element('id', "login_btn")
|
||||||
|
@ -141,54 +146,56 @@ def test_generate_password():
|
||||||
username_input.send_keys(email) # login with credentials of the created TA
|
username_input.send_keys(email) # login with credentials of the created TA
|
||||||
password_input.send_keys(password)
|
password_input.send_keys(password)
|
||||||
# Click the login button
|
# Click the login button
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
login_button.click()
|
login_button.click()
|
||||||
|
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
elif txt_alert.find("Email address ") == 0:
|
elif txt_alert.find("Email address ") == 0:
|
||||||
time.sleep(22)
|
time.sleep(2)
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
def test_existingTA():
|
|
||||||
driver_open = webdriver.Chrome()
|
def test_existingTA(driver, url, restore_database):
|
||||||
login_lecturer(driver_open)
|
driver_open = driver
|
||||||
|
login_lecturer(driver, url)
|
||||||
try:
|
try:
|
||||||
# Use email nreyes@example.com as account name and new1452345678 as password.
|
# Use email nreyes@example.com as account name and new1452345678 as password.
|
||||||
fullname = "Maria"
|
fullname = "lanhuitest1"
|
||||||
email = "nreyes@example.com"
|
email = "lanhuitest1@qq.com"
|
||||||
password = "new1452345678"
|
password = "new1452345678"
|
||||||
createTA(driver_open, fullname, email,
|
createTA(driver_open, fullname, email,
|
||||||
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
|
password) # CREATE A TA WITH FULLNAME lanhuitest1 email lanhuitest1@qq.com password new1452345678
|
||||||
|
|
||||||
get_output = WebDriverWait(driver_open, 5).until(
|
get_output = WebDriverWait(driver_open, 20).until(
|
||||||
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
|
||||||
)
|
)
|
||||||
get_output.click()
|
get_output.click()
|
||||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||||
txt_alert = get_output_msg.text
|
txt_alert = get_output_msg.text
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
if txt_alert.find("TA user created successfully") == 0:
|
if txt_alert.find("TA user created successfully") == 0:
|
||||||
time.sleep(20)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
elif txt_alert.find("Email address ") == 0:
|
elif txt_alert.find("Email address ") == 0:
|
||||||
time.sleep(22)
|
time.sleep(2)
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
||||||
time.sleep(5)
|
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
driver_open.quit()
|
driver_open.quit()
|
Loading…
Reference in New Issue