From 8f9c34da3f8bb648f854c5ab4ed6cbed6b4d07fa Mon Sep 17 00:00:00 2001 From: newtech7j Date: Mon, 13 May 2024 13:05:11 +0100 Subject: [PATCH 1/2] changes made with respect to the comments --- test/SeleniumNeil/.idea/.gitignore | 8 ++ test/SeleniumNeil/.idea/SeleniumNeil.iml | 15 +++ .../inspectionProfiles/profiles_settings.xml | 6 + test/SeleniumNeil/.idea/misc.xml | 4 + test/SeleniumNeil/.idea/modules.xml | 8 ++ test/SeleniumNeil/.idea/vcs.xml | 6 + .../conftest.cpython-38-pytest-8.0.0.pyc | Bin 0 -> 1614 bytes .../__pycache__/conftest.cpython-38.pyc | Bin 0 -> 1501 bytes .../test_cases.cpython-38-pytest-8.0.0.pyc | Bin 0 -> 3037 bytes test/SeleniumNeil/test_cases.py | 104 ++---------------- 10 files changed, 54 insertions(+), 97 deletions(-) create mode 100644 test/SeleniumNeil/.idea/.gitignore create mode 100644 test/SeleniumNeil/.idea/SeleniumNeil.iml create mode 100644 test/SeleniumNeil/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 test/SeleniumNeil/.idea/misc.xml create mode 100644 test/SeleniumNeil/.idea/modules.xml create mode 100644 test/SeleniumNeil/.idea/vcs.xml create mode 100644 test/SeleniumNeil/__pycache__/conftest.cpython-38-pytest-8.0.0.pyc create mode 100644 test/SeleniumNeil/__pycache__/conftest.cpython-38.pyc create mode 100644 test/SeleniumNeil/__pycache__/test_cases.cpython-38-pytest-8.0.0.pyc diff --git a/test/SeleniumNeil/.idea/.gitignore b/test/SeleniumNeil/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/test/SeleniumNeil/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/test/SeleniumNeil/.idea/SeleniumNeil.iml b/test/SeleniumNeil/.idea/SeleniumNeil.iml new file mode 100644 index 0000000..5fdd65b --- /dev/null +++ b/test/SeleniumNeil/.idea/SeleniumNeil.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/SeleniumNeil/.idea/inspectionProfiles/profiles_settings.xml b/test/SeleniumNeil/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/test/SeleniumNeil/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/test/SeleniumNeil/.idea/misc.xml b/test/SeleniumNeil/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/test/SeleniumNeil/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/SeleniumNeil/.idea/modules.xml b/test/SeleniumNeil/.idea/modules.xml new file mode 100644 index 0000000..aa51822 --- /dev/null +++ b/test/SeleniumNeil/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/SeleniumNeil/.idea/vcs.xml b/test/SeleniumNeil/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/test/SeleniumNeil/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/SeleniumNeil/__pycache__/conftest.cpython-38-pytest-8.0.0.pyc b/test/SeleniumNeil/__pycache__/conftest.cpython-38-pytest-8.0.0.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cfd6b883e58d200ad124821df40ce64cab0e2376 GIT binary patch literal 1614 zcma)6&2Jk;6rWkI?X_d4rc$L+0UCt^7|9MFs*utO#feR^6zs@0B&>|A&Ca-9x?h3-k<8bAf?o&$AaecMaz?w$}WD#>MmOV{>UFcNazzeZ9HN zNc1yaWS(P;PJ2fveBVUUcv9p)Vze|dN^Z*x-B_5<(7EvxWRB2%L`zHaJM$QQg+k*P zkP0UGjr5q15obhB7@>}IP8`ANMRGCPl6Znl1shL&GLAS2oF`uRn24!XaU@}mJ0UEj zH5t`lArkIes|)FHDag!|6Ky~^!A(~7Sjfhn+#xeYTqh))#XO=@cjc8RwJG6IBuOn!-Xt|fwwk@}A!#-SjlD*{McSW|)^WQ(=##{Fu$A1= zBKy5oW6*jjbfNjE*XRsLz4_c2}ebViai~Bb@q?}U89rl^eLT?&$nCB1OC>*QPdOS}nE8p1KZ&l*r9uQ=i z*fc9xe}9`f16z7e3|h9PD-Gb zW~SVK3pT<4f(*V1^c72rr!85qQN8jUfi>Kz8eFmL-2Q||0lU#aZq?OqgWRQ!Td;q{ z#*NXG92$7x?&)bA@_+q$^$J`Ev8lyI&{#Z#o_P0)t;+wkWoJJ4@T31U5j#T6B2H^p zOuPpBY9+N!rk*doP^6{Zcs^RA*GKVOKR&23uIjDM*^GOVrG@oTn!h|Ng0d1HIh?D~ zNOLP}TjHXmbk5WK*gKQ(-_W(8pN*@$auqOFE?tjBXUcjQz^}k(pQv<;H-K2^HnO17 NN`{GxcVU_@=RegQek}k1 literal 0 HcmV?d00001 diff --git a/test/SeleniumNeil/__pycache__/conftest.cpython-38.pyc b/test/SeleniumNeil/__pycache__/conftest.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e23fc2dfe67e90626e03c77f1ddad48128294397 GIT binary patch literal 1501 zcma)5&u<$=6rR~#+iS;(0#&7`5@-|-U?e9%RaHtW6enJarLd0Hh6Kwf+U|_&ZTDAZ z#w1zUT*{xoi7FE1#-9Lx%3e8f=Tvdv%{Xz>G!o2e-p)7k-hAJ@nfLYbat%TI^^g0b zzb%CRRN!he0c=ATBQO+E9HGJdj|UjA5gD;LFfn5IsYOj{{fM69K}n+$Eo)TPs6uUx zDjHR3O(R>QC0f_0N^uW0mj41Soe;I>kxg565|k%I!yjM@tBY)XGD$}p}zDV z`+{xM$VKZ&5(+XAY&40;DCH#fpM}X2A|^V-mxTGjn6QL4W!i)vk+9z)Tu7fwK~6$B z)&#Z42{a63Mx`0u9WF^L#Zv6UPy0P6$s^ zNt#*y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fri, 17 May 2024 06:40:31 +0100 Subject: [PATCH 2/2] new update on the test script this is the demo video https://cloud.zjnu.edu.cn/share/32b27be407c0c5fbe74e051030 --- test/SeleniumNeil/LRR | 1 + test/SeleniumNeil/helper.py | 33 +++++ test/SeleniumNeil/test_cases.py | 106 ---------------- test/SeleniumNeil/test_script_352.py | 177 +++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 106 deletions(-) create mode 160000 test/SeleniumNeil/LRR create mode 100644 test/SeleniumNeil/helper.py delete mode 100644 test/SeleniumNeil/test_cases.py create mode 100644 test/SeleniumNeil/test_script_352.py diff --git a/test/SeleniumNeil/LRR b/test/SeleniumNeil/LRR new file mode 160000 index 0000000..1a01b4f --- /dev/null +++ b/test/SeleniumNeil/LRR @@ -0,0 +1 @@ +Subproject commit 1a01b4facd4c9d1cce59ef84da114f55a57f616d diff --git a/test/SeleniumNeil/helper.py b/test/SeleniumNeil/helper.py new file mode 100644 index 0000000..bea59f9 --- /dev/null +++ b/test/SeleniumNeil/helper.py @@ -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)}" diff --git a/test/SeleniumNeil/test_cases.py b/test/SeleniumNeil/test_cases.py deleted file mode 100644 index 69570eb..0000000 --- a/test/SeleniumNeil/test_cases.py +++ /dev/null @@ -1,106 +0,0 @@ -# Each time you run the test script reset the database. -# For this test script you won't need it since it changes -# the Ta's email and name automatically -import re -import time -import pytest - -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 - -from conftest import url, driver, restore_database - - -def test_function_1(restore_database): - assert restore_database is None -@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) - 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() - -def login_lecturer(drivers): - # Open the website - drivers.get(url()) - drivers.maximize_window() - - username_input = drivers.find_element('name', "user") - - password_input = drivers.find_element('name', "password") - - login_button = drivers.find_element('id', "login_btn") - - # login as a Lecturer - username_input.send_keys("admin@qq.com") - password_input.send_keys("123") - # Click the login button - time.sleep(10) - login_button.click() - admin_tab = drivers.find_element('id', 'admin_tab') - admin_tab.click() - - cte_instructor = drivers.find_element('id', 'tab_ins_accounts') - cte_instructor.click() - time.sleep(15) - - -def test_createTA(url, driver, restore_database): - driver_open = driver(); - driver_open.maximize_window() - login_lecturer(driver_open) - try: - fullname = "lanhuitest1" - email = "lanhuitest1@qq.com" - password = "new1452345678" - 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( - 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(10) - - if txt_alert.find("TA user created successfully") == 0: - 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(13) - logout_button.click() - time.sleep(5) - 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 the new TA - username_input.send_keys(email) # login with credentials of the created TA - password_input.send_keys(password) - # Click the login button - time.sleep(10) - - login_button.click() - - time.sleep(5) - elif txt_alert.find("Email address ") == 0: - - time.sleep(10) - driver_open.quit() - - else: - driver_open.quit() - - time.sleep(5) - - finally: - driver_open.quit() - diff --git a/test/SeleniumNeil/test_script_352.py b/test/SeleniumNeil/test_script_352.py new file mode 100644 index 0000000..d35c51e --- /dev/null +++ b/test/SeleniumNeil/test_script_352.py @@ -0,0 +1,177 @@ +# Each time you run the test script reset the database. +# For this test script you won't need it since it changes +# the Ta's email and name automatically +import re +import time +import pytest + +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_function_1(restore_database): + + assert restore_database is None +@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) + 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() + + +def test_createTA(url, driver, restore_database): + driver_open = driver + driver_open.maximize_window() + login(driver, url, "admin@qq.com", "123") + try: + fullname = "lanhuitest1" + email = "lanhuitest1@qq.com" + password = "new1452345678" + 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( + 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(10) + + if txt_alert.find("TA user created successfully") == 0: + 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(13) + logout_button.click() + time.sleep(5) + 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 the new TA + username_input.send_keys(email) # login with credentials of the created TA + password_input.send_keys(password) + # Click the login button + time.sleep(10) + + login_button.click() + assert result == "Passed", f"Test Case 1 create TA passed" + time.sleep(5) + elif txt_alert.find("Email address ") == 0: + + time.sleep(10) + driver_open.quit() + assert result == "Passed", f"Test Case 1 create TA failed" + else: + driver_open.quit() + + time.sleep(5) + + finally: + driver_open.quit() +def test_generate_password(url, driver, restore_database): + driver_open = driver + login(driver, url, "admin@qq.com", "123") + try: + fullname = "lanhuitest2" + email = "lanhuitest2@qq.com" + password = "" + createTA(driver_open, fullname, email, + password) # CREATE A TA WITH FULLNAME lanhuitest2 email lanhuitest2@qq.com password "" + + get_output = WebDriverWait(driver_open, 15).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(10) + + if txt_alert.find("TA user created successfully") == 0: + time.sleep(15) + email_pattern = r"Use email (\S+) as account name" + password_pattern = r" (\S+)\ as password." + email_match = re.search(email_pattern, txt_alert) + password_match = re.search(password_pattern, txt_alert) + if email_match and password_match: + # Extract email and password from the matches + email = email_match.group(1) + password = password_match.group(1) + logout_button = WebDriverWait(driver_open, 15).until( + EC.element_to_be_clickable( + (By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]")) + ) + logout_button.click() + 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") + # login as the new TA + username_input.send_keys(email) # login with credentials of the created TA + password_input.send_keys(password) + # Click the login button + time.sleep(15) + + login_button.click() + assert result == "Passed", f"Test Case 2 generate passsword passed" + time.sleep(5) + + elif txt_alert.find("Email address ") == 0: + time.sleep(15) + driver_open.quit() + assert result == "Passed", f"Test Case 2 generate passsword failed" + else: + driver_open.quit() + + time.sleep(5) + + finally: + driver_open.quit() + +def test_existingTA(url, driver, restore_database): + driver_open = driver + login(driver, url, "admin@qq.com", "123") + try: +# Use email nreyes@example.com as account name and new1452345678 as password. + fullname = "lanhuitest1" + email = "lanhuitest1@qq.com" + password = "new1452345678" + 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( + 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(15) + + if txt_alert.find("TA user created successfully") == 0: + assert result == "Passed", f"Test Case 2 existing account passed" + time.sleep(5) + + + elif txt_alert.find("Email address ") == 0: + time.sleep(15) + + assert result == "Passed", f"Test Case 2 existing account failed" + driver_open.quit() + + else: + driver_open.quit() + + time.sleep(5) + + finally: + driver_open.quit() + -- 2.17.1