From cf30889bdd1b0949c2fa63d6e714f0bbd282e4c8 Mon Sep 17 00:00:00 2001 From: yaaqob <3237084594@qq.com> Date: Mon, 4 Dec 2023 12:30:38 +0800 Subject: [PATCH] removed punctuations from sql statement, and added MPIANA selenium test case --- Script.php | 4 +- test/SeleniumMpiana/assign_ta_test.py | 65 +++++++++++++++++++++++++++ test/SeleniumMpiana/test_results.txt | 2 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/SeleniumMpiana/assign_ta_test.py create mode 100644 test/SeleniumMpiana/test_results.txt diff --git a/Script.php b/Script.php index 537b668..b1488be 100644 --- a/Script.php +++ b/Script.php @@ -917,7 +917,7 @@ if (!empty($_GET["assignTA"])) { $ta = mysqli_real_escape_string($con, $_GET["ta"]); // Check if the TA is already assigned to the course - $check_sql = "SELECT * FROM `course_ta` WHERE `Course_ID`='$id' AND `TA`='$ta'"; + $check_sql = "SELECT * FROM course_ta WHERE Course_ID='$id' AND TA='$ta'"; $check_result = $con->query($check_sql); if ($check_result->num_rows > 0) { @@ -928,7 +928,7 @@ if (!empty($_GET["assignTA"])) { "; } else { // Proceed with the TA assignment - $sql = "INSERT INTO `course_ta`(`Course_ID`, `TA`) VALUES ('$id','$ta')"; + $sql = "INSERT INTO course_ta(Course_ID, TA) VALUES ('$id','$ta')"; if ($con->query($sql) === TRUE) { $_SESSION["info_Admin_Courses"] = $type . " Course TA Assigned "; diff --git a/test/SeleniumMpiana/assign_ta_test.py b/test/SeleniumMpiana/assign_ta_test.py new file mode 100644 index 0000000..11b6285 --- /dev/null +++ b/test/SeleniumMpiana/assign_ta_test.py @@ -0,0 +1,65 @@ +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 UnexpectedAlertPresentException + +# New instance of the Chrome driver +driver = webdriver.Chrome() + +# Open the admin url +driver.get("http://localhost/itech/lrr/Admin.php") + +def assign_ta(driver, course_name, ta_name): + course_dropdown = driver.find_element('id', 'courseDropdown') + course_dropdown.click() + selected_course_option = WebDriverWait(driver, 1200).until( + EC.element_to_be_clickable((By.XPATH, f"//option[text()='{course_name}']")) + ) + selected_course_option.click() + + # Select the TA + ta_dropdown = driver.find_element('id', 'taDropdown') + ta_dropdown.click() + + # Check if ta_name is not null before selecting + if ta_name: + selected_ta_option = WebDriverWait(driver, 1200).until( + EC.element_to_be_clickable((By.XPATH, f"//option[text()='{ta_name}']")) + ) + selected_ta_option.click() + + # Click the Assign button + assign_button = driver.find_element('id', 'assignButton') + assign_button.click() + + # Use WebDriverWait for more reliable alert handling + try: + alert = WebDriverWait(driver, 1200).until(EC.alert_is_present()) + alert_text = alert.text + alert.accept() + return alert_text + except UnexpectedAlertPresentException: + return None + +# Generate all combinations of courses and TAs +courses = ["Python", "computer", "testing"] +tas = ["MPIANA", "KABWANGA", "mark"] + +@pytest.mark.parametrize("course_name, ta_name", [(course, ta) for course in courses for ta in tas]) +def assign_ta_test(course_name, ta_name): + alert_text = assign_ta(driver, course_name, ta_name) + + try: + assert "Success" in alert_text or "Error" in alert_text + result = "Passed" + except AssertionError: + result = "Failed" + + # Write the result to the text file + with open('test_results.txt', 'a') as result_file: + result_file.write(f"Course={course_name}, TA={ta_name}, Result={result}, Alert={alert_text}\n") + +# Close the browser window +driver.quit() diff --git a/test/SeleniumMpiana/test_results.txt b/test/SeleniumMpiana/test_results.txt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/test/SeleniumMpiana/test_results.txt @@ -0,0 +1,2 @@ + +