Compare commits
22 Commits
64ffc3af1c
...
5bbd812189
Author | SHA1 | Date |
---|---|---|
Lan Hui | 5bbd812189 | |
Lan Hui | 162de63b4d | |
mrlan | 88d20ed476 | |
Lan Hui | 5d0d0d91f7 | |
mrlan | fea32072c3 | |
nartey | 5639ce4c6b | |
nartey | 8f3919d3bb | |
Lan Hui | 23e192568f | |
Lan Hui | dc3ff79b5d | |
Lan Hui | 690db8d5fe | |
mrlan | 1a01b4facd | |
Lan Hui | 4024a36021 | |
KOUONTCHOU NEIL ARMSTRONG | f600f2bc24 | |
KOUONTCHOU NEIL ARMSTRONG | 8e200b647f | |
KOUONTCHOU NEIL ARMSTRONG | dcd0e522c7 | |
Lan Hui | 4da1c5a641 | |
Lan Hui | f2aa60c994 | |
Lan Hui | 5b72461eda | |
Lan Hui | ff092f2a8e | |
YAAQOB ABDULSATTAR HAMID ABDULQADER | 622ed4350f | |
Nartey Sylvester Amanor | 9f03d380cd | |
Nartey Sylvester Amanor | c1f95ce017 |
16
Course.php
16
Course.php
|
@ -86,22 +86,22 @@ include 'Header.php';
|
|||
|
||||
<ul class="nav nav-tabs" id="myTab">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="#menu1">New</a>
|
||||
<a class="nav-link <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>" data-toggle="tab" href="#menu1">New</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#menu2">Missed</a>
|
||||
<a class="nav-link <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>" data-toggle="tab" href="#menu2">Missed</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#menu3">Submitted</a>
|
||||
<a class="nav-link <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>" data-toggle="tab" href="#menu3">Submitted</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#menu4">Marked</a>
|
||||
<a class="nav-link <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>" data-toggle="tab" href="#menu4">Marked</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
<div id="menu1" class="tab-pane active">
|
||||
<div id="menu1" class="tab-pane <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>">
|
||||
|
||||
<?php
|
||||
|
||||
|
@ -185,7 +185,7 @@ include 'Header.php';
|
|||
|
||||
|
||||
|
||||
<div id="menu2" class="tab-pane">
|
||||
<div id="menu2" class="tab-pane <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>">
|
||||
|
||||
<?php
|
||||
$group_id = $_SESSION['group_id'];
|
||||
|
@ -251,7 +251,7 @@ include 'Header.php';
|
|||
|
||||
|
||||
|
||||
<div id="menu3" class="tab-pane">
|
||||
<div id="menu3" class="tab-pane <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>">
|
||||
<?php
|
||||
|
||||
$group_id = $_SESSION['group_id'];
|
||||
|
@ -371,7 +371,7 @@ include 'Header.php';
|
|||
?>
|
||||
|
||||
|
||||
<div id="menu4" class="tab-pane">
|
||||
<div id="menu4" class="tab-pane <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>">
|
||||
<?php
|
||||
$resultx = mysqli_query($con, "SELECT Submission_ID, Submission_Date, lab_reports_table.Lab_Report_ID, Student_id, Course_Group_id, Notes, lab_report_submissions.Marks, lab_report_submissions.Remarking_Reason, Status, lab_reports_table.Title Lab_Title, lab_reports_table.Marks Original_marks
|
||||
FROM lab_report_submissions
|
||||
|
|
10
Script.php
10
Script.php
|
@ -119,7 +119,7 @@ if (!empty($_POST["form_signup"])) {
|
|||
if (!empty($_POST["form_signup"])) {
|
||||
$fullname = mysqli_real_escape_string($con, $_POST["fullname"]);
|
||||
$student_id = mysqli_real_escape_string($con, $_POST["user_student_id"]);
|
||||
<<<<<<< HEAD
|
||||
|
||||
$email = mysqli_real_escape_string($con, $_POST["email"]);
|
||||
$password = mysqli_real_escape_string($con, $_POST["password"]);
|
||||
$confirmpassword = mysqli_real_escape_string($con, $_POST["confirmpassword"]);
|
||||
|
@ -168,13 +168,11 @@ if (!empty($_POST["form_signup"])) {
|
|||
return;
|
||||
}
|
||||
|
||||
=======
|
||||
$_SESSION['user_fullname'] = $fullname;
|
||||
|
||||
$_SESSION['user_type'] = "Student";
|
||||
$_SESSION['user_email'] = $email;
|
||||
$_SESSION['user_student_id'] = $student_id;
|
||||
|
||||
>>>>>>> fde44f76006082d6bda9431727d06cbd23a134be
|
||||
// apply password_hash()
|
||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`, `Student_ID`) VALUES "
|
||||
|
@ -793,8 +791,8 @@ if (!empty($_GET["remarking"])) {
|
|||
|
||||
if ($con->query($sql) === TRUE) {
|
||||
|
||||
$_SESSION["info_general"] = "Remarking request sent";
|
||||
header("Location: Course.php?url=" . $url);
|
||||
$_SESSION["info_general"] = "Remarking Request Sent";
|
||||
header("Location: Course.php?url=" . $url . "&tab=Marked");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $con->error;
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ CREATE TABLE `users_table` (
|
|||
--
|
||||
|
||||
INSERT INTO `users_table` (`User_ID`, `Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`, `Passport_Number`, `Status`) VALUES
|
||||
(3, 'admin@qq.com', '123', '', 'Kamal', 'Admin', '0', NULL, 'Active'),
|
||||
(3, 'admin@qq.com', '$2y$10$8GCG6lTo1LFRD3bOkAyKYeOMOrFSBUgrTxaPLS5ynWN1bYDHf89pO', '', 'Kamal', 'Admin', '0', NULL, 'Active'),
|
||||
(8, 'lanhui@qq.com', '1234', '', 'Lanhui', 'Lecturer', NULL, '123', 'Active'),
|
||||
(9, 'mohamed@qq.com', '123', '', 'Mohamed', 'Student', '201825800050', 'P00581929', 'Active'),
|
||||
(10, 'mark@qq.com', '123', '', 'Mark ', 'TA', NULL, '123', 'Active'),
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
|
||||
|
||||
|
||||
def login(driver, url, username, password):
|
||||
try:
|
||||
driver.get(url)
|
||||
|
||||
# Fill in the login form
|
||||
user_input = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "user_name"))
|
||||
)
|
||||
user_input.send_keys(username)
|
||||
|
||||
password_input = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "user_password"))
|
||||
)
|
||||
password_input.send_keys(password)
|
||||
|
||||
# Click the login button
|
||||
login_button = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "login_btn"))
|
||||
)
|
||||
login_button.click()
|
||||
|
||||
# Wait for the admin_tab to become clickable
|
||||
admin_tab = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "admin_tab"))
|
||||
)
|
||||
except (NoSuchElementException, UnexpectedAlertPresentException) as e:
|
||||
return f"Error: {str(e)}"
|
|
@ -0,0 +1,122 @@
|
|||
import pytest
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import Select
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
|
||||
from helper import login
|
||||
|
||||
@pytest.mark.parametrize("course_id, course_name, ta_name", [(1, "Teecloudy - Ashly Course Testing", "Mark")])
|
||||
def test_assign_a_new_ta_to_a_course(course_id, course_name, ta_name, driver, url, admin_username, admin_password, restore_database):
|
||||
try:
|
||||
driver.maximize_window()
|
||||
|
||||
login(driver, url, admin_username, admin_password)
|
||||
|
||||
admin_tab = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "admin_tab"))
|
||||
)
|
||||
admin_tab.click()
|
||||
|
||||
# Locate the form and select the TA
|
||||
ta_form = WebDriverWait(driver, 15).until(
|
||||
EC.presence_of_element_located((By.XPATH, f"//form[@id='drop_menu_form_{course_id}']"))
|
||||
)
|
||||
|
||||
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
|
||||
ta_dropdown.select_by_visible_text(ta_name)
|
||||
|
||||
# Submit the form using JavaScript
|
||||
driver.execute_script("arguments[0].submit();", ta_form)
|
||||
|
||||
# find table courses
|
||||
table_courses = WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
|
||||
)
|
||||
# find the row with matching course_name
|
||||
course_row = table_courses.find_element(By.XPATH, f".//tr[td='{course_name}']")
|
||||
# find the column with TA name
|
||||
ta_column = course_row.find_element(By.XPATH, ".//td[4]")
|
||||
|
||||
# assert the TA name in the column
|
||||
assert ta_name in ta_column.text, f"Error: TA name {ta_name} not found in the column {ta_column.text}"
|
||||
|
||||
except NoSuchElementException as e:
|
||||
return f"Error: {str(e)}"
|
||||
except UnexpectedAlertPresentException as e:
|
||||
return f"Error: {str(e)}"
|
||||
except AssertionError as e:
|
||||
return f"Error: {str(e)}"
|
||||
except Exception as e:
|
||||
return f"Error: {str(e)}"
|
||||
finally:
|
||||
driver.quit()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("course_id, course_name, ta_name", [(1, "Teecloudy - Ashly Course Testing", "Mark")])
|
||||
def test_assign_the_same_ta_to_the_same_course_twice(course_id, course_name, ta_name, driver, url, admin_username, admin_password, restore_database):
|
||||
try:
|
||||
driver.maximize_window()
|
||||
login(driver, url, admin_username, admin_password)
|
||||
|
||||
admin_tab = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "admin_tab"))
|
||||
)
|
||||
admin_tab.click()
|
||||
|
||||
# Hui: assign the TA for the first time
|
||||
# (1) Locate the form and select the TA
|
||||
ta_form = WebDriverWait(driver, 15).until(
|
||||
EC.presence_of_element_located((By.XPATH,
|
||||
f"//form[@id='drop_menu_form_{course_id}']")) )
|
||||
|
||||
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
|
||||
ta_dropdown.select_by_visible_text(ta_name)
|
||||
|
||||
# (2) Submit the form using JavaScript
|
||||
driver.execute_script("arguments[0].submit();", ta_form)
|
||||
|
||||
# (3) Find table courses
|
||||
table_courses_before = WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
|
||||
)
|
||||
# (4) Find the row with matching course_name
|
||||
course_row_before = table_courses_before.find_element(By.XPATH, f".//tr[td='{course_name}']")
|
||||
# (5) Find the column with TA name
|
||||
old_cell_content = course_row_before.find_element(By.XPATH, ".//td[4]").text
|
||||
|
||||
|
||||
# Hui: assign the same TA again
|
||||
ta_form = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, f"//form[@id='drop_menu_form_{course_id}']")))
|
||||
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
|
||||
ta_dropdown.select_by_visible_text(ta_name)
|
||||
driver.execute_script("arguments[0].submit();", ta_form)
|
||||
|
||||
# Wait for an expected alert and accept it
|
||||
WebDriverWait(driver, 10).until(EC.alert_is_present())
|
||||
alert = driver.switch_to.alert
|
||||
alert_text = alert.text
|
||||
alert.accept()
|
||||
|
||||
# find table courses
|
||||
table_courses_after = WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
|
||||
)
|
||||
# find the row with matching course_name
|
||||
course_row_after = table_courses_after.find_element(By.XPATH, f".//tr[td='{course_name}']")
|
||||
# find the column with TA name
|
||||
new_cell_content = course_row_after.find_element(By.XPATH, ".//td[4]").text
|
||||
|
||||
# assert the TA name in the column
|
||||
assert old_cell_content == new_cell_content, f"Error: TA name in the column has changed from {old_cell_content} to {new_cell_content}"
|
||||
|
||||
except NoSuchElementException as e:
|
||||
return f"Error: {str(e)}"
|
||||
except UnexpectedAlertPresentException as e:
|
||||
return f"Error: {str(e)}"
|
||||
except AssertionError as e:
|
||||
return f"Error: {str(e)}"
|
||||
except Exception as e:
|
||||
return f"Error: {str(e)}"
|
||||
finally:
|
||||
driver.quit()
|
|
@ -4,14 +4,17 @@
|
|||
import re
|
||||
import time
|
||||
import pytest
|
||||
from faker import Faker
|
||||
|
||||
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
|
||||
|
||||
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):
|
||||
full_name = driver.find_element('name', 'fullname')
|
||||
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.click()
|
||||
|
||||
def login_lecturer(drivers):
|
||||
|
||||
def login_lecturer(driver, url):
|
||||
# Open the website
|
||||
drivers.get("http://localhost/lrr/")
|
||||
drivers.maximize_window()
|
||||
driver.get(url)
|
||||
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
|
||||
username_input.send_keys("lanhui@qq.com")
|
||||
password_input.send_keys("nil1234H@")
|
||||
username_input.send_keys("admin@qq.com")
|
||||
password_input.send_keys("123")
|
||||
# Click the login button
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
login_button.click()
|
||||
admin_tab = drivers.find_element('id', 'admin_tab')
|
||||
admin_tab = driver.find_element('id', 'admin_tab')
|
||||
admin_tab.click()
|
||||
|
||||
cte_instructor = drivers.find_element('id', 'tab_ins_accounts')
|
||||
cte_instructor = driver.find_element('id', 'tab_ins_accounts')
|
||||
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()
|
||||
login_lecturer(driver_open)
|
||||
login_lecturer(driver_open, url)
|
||||
try:
|
||||
fullname = faker.name()
|
||||
email = faker.email()
|
||||
fullname = "lanhuitest1"
|
||||
email = "lanhuitest1@qq.com"
|
||||
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"))
|
||||
)
|
||||
get_output.click()
|
||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||
txt_alert = get_output_msg.text
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
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(
|
||||
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
|
||||
)
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
logout_button.click()
|
||||
time.sleep(10)
|
||||
time.sleep(2)
|
||||
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")
|
||||
|
@ -81,45 +86,45 @@ def test_createTA():
|
|||
username_input.send_keys(email) # login with credentials of the created TA
|
||||
password_input.send_keys(password)
|
||||
# Click the login button
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
login_button.click()
|
||||
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
elif txt_alert.find("Email address ") == 0:
|
||||
|
||||
time.sleep(22)
|
||||
time.sleep(2)
|
||||
driver_open.quit()
|
||||
|
||||
else:
|
||||
driver_open.quit()
|
||||
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
|
||||
finally:
|
||||
driver_open.quit()
|
||||
|
||||
|
||||
def test_generate_password():
|
||||
driver_open = webdriver.Chrome()
|
||||
login_lecturer(driver_open)
|
||||
def test_generate_password(driver, url):
|
||||
driver_open = driver
|
||||
login_lecturer(driver_open, url)
|
||||
try:
|
||||
fullname = faker.name()
|
||||
email = faker.email()
|
||||
fullname = "lanhuitest2"
|
||||
email = "lanhuitest2@qq.com"
|
||||
password = ""
|
||||
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"))
|
||||
)
|
||||
get_output.click()
|
||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||
txt_alert = get_output_msg.text
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
if txt_alert.find("TA user created successfully") == 0:
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
email_pattern = r"Use email (\S+) as account name"
|
||||
password_pattern = r" (\S+)\ as password."
|
||||
email_match = re.search(email_pattern, txt_alert)
|
||||
|
@ -128,12 +133,12 @@ def test_generate_password():
|
|||
# Extract email and password from the matches
|
||||
email = email_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(
|
||||
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
|
||||
)
|
||||
logout_button.click()
|
||||
time.sleep(15)
|
||||
time.sleep(2)
|
||||
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")
|
||||
|
@ -141,54 +146,56 @@ def test_generate_password():
|
|||
username_input.send_keys(email) # login with credentials of the created TA
|
||||
password_input.send_keys(password)
|
||||
# Click the login button
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
login_button.click()
|
||||
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
elif txt_alert.find("Email address ") == 0:
|
||||
time.sleep(22)
|
||||
time.sleep(2)
|
||||
driver_open.quit()
|
||||
|
||||
else:
|
||||
driver_open.quit()
|
||||
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
|
||||
finally:
|
||||
driver_open.quit()
|
||||
|
||||
def test_existingTA():
|
||||
driver_open = webdriver.Chrome()
|
||||
login_lecturer(driver_open)
|
||||
|
||||
def test_existingTA(driver, url, restore_database):
|
||||
driver_open = driver
|
||||
login_lecturer(driver, url)
|
||||
try:
|
||||
# Use email nreyes@example.com as account name and new1452345678 as password.
|
||||
fullname = "Maria"
|
||||
email = "nreyes@example.com"
|
||||
fullname = "lanhuitest1"
|
||||
email = "lanhuitest1@qq.com"
|
||||
password = "new1452345678"
|
||||
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"))
|
||||
)
|
||||
get_output.click()
|
||||
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
|
||||
txt_alert = get_output_msg.text
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
if txt_alert.find("TA user created successfully") == 0:
|
||||
time.sleep(20)
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
elif txt_alert.find("Email address ") == 0:
|
||||
time.sleep(22)
|
||||
time.sleep(2)
|
||||
driver_open.quit()
|
||||
|
||||
else:
|
||||
driver_open.quit()
|
||||
time.sleep(5)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
finally:
|
||||
driver_open.quit()
|
|
@ -0,0 +1,77 @@
|
|||
import pytest
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
||||
import time
|
||||
import traceback
|
||||
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
try:
|
||||
# Navigate to the page with tabs
|
||||
driver.get("http://localhost:8080/lrr/")
|
||||
driver.maximize_window()
|
||||
wait = WebDriverWait(driver, 10)
|
||||
|
||||
# Login as a Lecturer
|
||||
username_input = wait.until(EC.presence_of_element_located((By.NAME, "user")))
|
||||
password_input = driver.find_element(By.NAME, "password")
|
||||
login_button = driver.find_element(By.ID, "login_btn")
|
||||
|
||||
username_input.send_keys("ashly@qq.com")
|
||||
password_input.send_keys("admin123")
|
||||
time.sleep(5)
|
||||
login_button.click()
|
||||
|
||||
course_but= driver.find_element(By.XPATH, "(//div[@class='btn btn-default'])[1]") # Adjust this XPATH as needed
|
||||
|
||||
|
||||
# Click on the alert
|
||||
course_but.click()
|
||||
time.sleep(5)
|
||||
|
||||
marked_tab = wait.until(
|
||||
EC.element_to_be_clickable((By.XPATH, "//a[text()='Marked']"))
|
||||
)
|
||||
marked_tab.click()
|
||||
|
||||
# Wait for the Marked tab content to be present
|
||||
marked_tab_content = wait.until(
|
||||
EC.presence_of_element_located((By.XPATH, "//div[@id='menu4' and contains(@class, 'active')]"))
|
||||
)
|
||||
|
||||
time.sleep(5)
|
||||
remark_but = wait.until(
|
||||
EC.presence_of_element_located((By.XPATH, "//button[normalize-space()='Request remarking']"))
|
||||
)
|
||||
remark_but.click()
|
||||
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
# Switch to the alert
|
||||
alert = driver.switch_to.alert
|
||||
|
||||
# Send keys to the prompt
|
||||
alert.send_keys("Number 2 was correct")
|
||||
|
||||
# Accept the prompt (click OK)
|
||||
alert.accept()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
|
||||
except NoSuchElementException as e:
|
||||
print("NoSuchElementException: Could not find an element.")
|
||||
traceback.print_exc()
|
||||
except TimeoutException as e:
|
||||
print("TimeoutException: An element took too long to load.")
|
||||
traceback.print_exc()
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred: {e}")
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
driver.quit()
|
|
@ -0,0 +1,46 @@
|
|||
import os
|
||||
import pytest
|
||||
from selenium import webdriver
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def restore_database():
|
||||
''' Restore the database.
|
||||
It is useful for making sure that each end-to-end test
|
||||
starts with the same database.
|
||||
Benefit: we can reproduce the same test result.
|
||||
'''
|
||||
|
||||
PASSWORD = 'p-@va9' # root password
|
||||
DB_NAME = 'lrr' # database name used for LRR
|
||||
|
||||
# commands used to import data to DB_NAME
|
||||
cmds = [
|
||||
f'mysql -u root -p{PASSWORD} -e "DROP DATABASE IF EXISTS {DB_NAME};"',
|
||||
f'mysql -u root -p{PASSWORD} -e "CREATE DATABASE {DB_NAME};"',
|
||||
f'mysql -u root -p{PASSWORD} -e "GRANT ALL PRIVILEGES ON {DB_NAME}.* TO lrr@localhost WITH GRANT OPTION;"',
|
||||
f'mysql -u root -p{PASSWORD} {DB_NAME} < ../lrr_database.sql']
|
||||
|
||||
for command in cmds:
|
||||
os.system(command)
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def url():
|
||||
return 'http://localhost/LRR/' # URL of LRR
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def driver():
|
||||
return webdriver.Chrome()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_username():
|
||||
return 'admin@qq.com'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_password():
|
||||
return '123'
|
Loading…
Reference in New Issue