(1) Move conftest.py to the top level test directory so that it applies to all test subfolders; (2) Move login() to helper.py so that it could be reused by other test scripts.
parent
4da1c5a641
commit
4024a36021
|
@ -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)}"
|
|
@ -1,40 +1,10 @@
|
||||||
import pytest
|
import pytest
|
||||||
from selenium import webdriver
|
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.ui import Select
|
from selenium.webdriver.support.ui import Select
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
|
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
|
||||||
|
from helper import login
|
||||||
|
|
||||||
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)}"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("course_id, course_name, ta_name", [(1, "Teecloudy - Ashly Course Testing", "Mark")])
|
@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):
|
def test_assign_a_new_ta_to_a_course(course_id, course_name, ta_name, driver, url, admin_username, admin_password, restore_database):
|
||||||
|
|
|
@ -11,7 +11,7 @@ def restore_database():
|
||||||
Benefit: we can reproduce the same test result.
|
Benefit: we can reproduce the same test result.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
PASSWORD = '' # root password
|
PASSWORD = 'p-@va9' # root password
|
||||||
DB_NAME = 'lrr' # database name used for LRR
|
DB_NAME = 'lrr' # database name used for LRR
|
||||||
|
|
||||||
# commands used to import data to DB_NAME
|
# commands used to import data to DB_NAME
|
||||||
|
@ -19,7 +19,7 @@ def restore_database():
|
||||||
f'mysql -u root -p{PASSWORD} -e "DROP DATABASE IF EXISTS {DB_NAME};"',
|
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 "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} -e "GRANT ALL PRIVILEGES ON {DB_NAME}.* TO lrr@localhost WITH GRANT OPTION;"',
|
||||||
f'mysql -u root -p{PASSWORD} {DB_NAME} < ../../lrr_database.sql']
|
f'mysql -u root -p{PASSWORD} {DB_NAME} < ../lrr_database.sql']
|
||||||
|
|
||||||
for command in cmds:
|
for command in cmds:
|
||||||
os.system(command)
|
os.system(command)
|
Loading…
Reference in New Issue