Compare commits

..

No commits in common. "5bbd812189c92b4128aa4c6f97a7a2a26bafd28e" and "64ffc3af1c9bdca2bfc0704288e846aaf3cba0ba" have entirely different histories.

9 changed files with 73 additions and 356 deletions

View File

@ -72,7 +72,7 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
Email
<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)
<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:
<?php

View File

@ -86,22 +86,22 @@ include 'Header.php';
<ul class="nav nav-tabs" id="myTab">
<li class="nav-item">
<a class="nav-link <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>" data-toggle="tab" href="#menu1">New</a>
<a class="nav-link active" href="#menu1">New</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>" data-toggle="tab" href="#menu2">Missed</a>
<a class="nav-link" href="#menu2">Missed</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>" data-toggle="tab" href="#menu3">Submitted</a>
<a class="nav-link" href="#menu3">Submitted</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>" data-toggle="tab" href="#menu4">Marked</a>
<a class="nav-link" href="#menu4">Marked</a>
</li>
</ul>
<div class="tab-content">
<div id="menu1" class="tab-pane <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>">
<div id="menu1" class="tab-pane active">
<?php
@ -185,7 +185,7 @@ include 'Header.php';
<div id="menu2" class="tab-pane <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>">
<div id="menu2" class="tab-pane">
<?php
$group_id = $_SESSION['group_id'];
@ -251,7 +251,7 @@ include 'Header.php';
<div id="menu3" class="tab-pane <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>">
<div id="menu3" class="tab-pane">
<?php
$group_id = $_SESSION['group_id'];
@ -371,7 +371,7 @@ include 'Header.php';
?>
<div id="menu4" class="tab-pane <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>">
<div id="menu4" class="tab-pane">
<?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

View File

@ -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,11 +168,13 @@ 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 "
@ -791,8 +793,8 @@ if (!empty($_GET["remarking"])) {
if ($con->query($sql) === TRUE) {
$_SESSION["info_general"] = "Remarking Request Sent";
header("Location: Course.php?url=" . $url . "&tab=Marked");
$_SESSION["info_general"] = "Remarking request sent";
header("Location: Course.php?url=" . $url);
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}

View File

@ -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', '$2y$10$8GCG6lTo1LFRD3bOkAyKYeOMOrFSBUgrTxaPLS5ynWN1bYDHf89pO', '', 'Kamal', 'Admin', '0', NULL, 'Active'),
(3, 'admin@qq.com', '123', '', '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'),

View File

@ -1,33 +0,0 @@
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)}"

View File

@ -1,122 +0,0 @@
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()

View File

@ -4,17 +4,14 @@
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
def test_restore_database(restore_database):
assert restore_database is None
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)
@ -27,58 +24,56 @@ def createTA(driver, TA_name, emails, password):
click_create = driver.find_element('name', 'create_btn')
click_create.click()
def login_lecturer(driver, url):
def login_lecturer(drivers):
# Open the website
driver.get(url)
driver.maximize_window()
drivers.get("http://localhost/lrr/")
drivers.maximize_window()
username_input = driver.find_element('name', "user")
username_input = drivers.find_element('name', "user")
password_input = driver.find_element('name', "password")
password_input = drivers.find_element('name', "password")
login_button = driver.find_element('id', "login_btn")
login_button = drivers.find_element('id', "login_btn")
# login as a Lecturer
username_input.send_keys("admin@qq.com")
password_input.send_keys("123")
username_input.send_keys("lanhui@qq.com")
password_input.send_keys("nil1234H@")
# Click the login button
time.sleep(2)
time.sleep(5)
login_button.click()
admin_tab = driver.find_element('id', 'admin_tab')
admin_tab = drivers.find_element('id', 'admin_tab')
admin_tab.click()
cte_instructor = driver.find_element('id', 'tab_ins_accounts')
cte_instructor = drivers.find_element('id', 'tab_ins_accounts')
cte_instructor.click()
time.sleep(2)
time.sleep(25)
def test_createTA(driver, url):
driver_open = driver
def test_createTA():
driver_open = webdriver.Chrome()
driver_open.maximize_window()
login_lecturer(driver_open, url)
login_lecturer(driver_open)
try:
fullname = "lanhuitest1"
email = "lanhuitest1@qq.com"
fullname = faker.name()
email = faker.email()
password = "new1452345678"
createTA(driver_open, fullname, email,password) # CREATE A TA WITH 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
get_output = WebDriverWait(driver_open, 20).until(
get_output = WebDriverWait(driver_open, 10).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(2)
time.sleep(20)
if txt_alert.find("TA user created successfully") == 0:
logout_button = WebDriverWait(driver_open, 20).until(
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(2)
time.sleep(5)
logout_button.click()
time.sleep(2)
time.sleep(10)
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")
@ -86,45 +81,45 @@ def test_createTA(driver, url):
username_input.send_keys(email) # login with credentials of the created TA
password_input.send_keys(password)
# Click the login button
time.sleep(2)
time.sleep(20)
login_button.click()
time.sleep(2)
time.sleep(20)
elif txt_alert.find("Email address ") == 0:
time.sleep(2)
time.sleep(22)
driver_open.quit()
else:
driver_open.quit()
time.sleep(2)
time.sleep(5)
finally:
driver_open.quit()
def test_generate_password(driver, url):
driver_open = driver
login_lecturer(driver_open, url)
def test_generate_password():
driver_open = webdriver.Chrome()
login_lecturer(driver_open)
try:
fullname = "lanhuitest2"
email = "lanhuitest2@qq.com"
fullname = faker.name()
email = faker.email()
password = ""
createTA(driver_open, fullname, email,
password) # CREATE A TA WITH FULLNAME lanhuitest2 email lanhuitest2@qq.com password ""
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
get_output = WebDriverWait(driver_open, 20).until(
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(2)
time.sleep(20)
if txt_alert.find("TA user created successfully") == 0:
time.sleep(2)
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)
@ -133,12 +128,12 @@ def test_generate_password(driver, url):
# Extract email and password from the matches
email = email_match.group(1)
password = password_match.group(1)
logout_button = WebDriverWait(driver_open, 20).until(
logout_button = WebDriverWait(driver_open, 10).until(
EC.element_to_be_clickable(
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
)
logout_button.click()
time.sleep(2)
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")
@ -146,56 +141,54 @@ def test_generate_password(driver, url):
username_input.send_keys(email) # login with credentials of the created TA
password_input.send_keys(password)
# Click the login button
time.sleep(2)
time.sleep(20)
login_button.click()
time.sleep(2)
time.sleep(20)
elif txt_alert.find("Email address ") == 0:
time.sleep(2)
time.sleep(22)
driver_open.quit()
else:
driver_open.quit()
time.sleep(2)
time.sleep(5)
finally:
driver_open.quit()
def test_existingTA(driver, url, restore_database):
driver_open = driver
login_lecturer(driver, url)
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 = "lanhuitest1"
email = "lanhuitest1@qq.com"
fullname = "Maria"
email = "nreyes@example.com"
password = "new1452345678"
createTA(driver_open, fullname, email,
password) # CREATE A TA WITH FULLNAME lanhuitest1 email lanhuitest1@qq.com password new1452345678
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678
get_output = WebDriverWait(driver_open, 20).until(
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(2)
time.sleep(20)
if txt_alert.find("TA user created successfully") == 0:
time.sleep(2)
time.sleep(20)
elif txt_alert.find("Email address ") == 0:
time.sleep(2)
time.sleep(22)
driver_open.quit()
else:
driver_open.quit()
time.sleep(2)
time.sleep(5)
finally:
driver_open.quit()
driver_open.quit()

View File

@ -1,77 +0,0 @@
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()

View File

@ -1,46 +0,0 @@
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'