Update 1: test cases 00-04

SeleniumIbrahimUpdate-Ibrahim
Ibrahim 2021-11-27 23:02:44 +08:00
parent eea3e14c8f
commit a64a4e1053
6 changed files with 69 additions and 50 deletions

View File

@ -51,11 +51,11 @@ if ($_SESSION['user_type'] != "Lecturer") {
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">Batch Create New Student Accounts</a>
<a class="nav-link" data-toggle="tab" href="#menu2" id="batch_tab">Batch Create New Student Accounts</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu1">Existing Accounts</a>
<a class="nav-link" data-toggle="tab" href="#menu1" id="ex_acc">Existing Accounts</a>
</li>
</ul>
@ -66,7 +66,7 @@ if ($_SESSION['user_type'] != "Lecturer") {
<div id="home" class="container tab-pane active"><br>
<b>Create Lecturer/TA Accounts </b>
<form method="post" action="Script.php">
<form method="post" action="Script.php" id="create_acc_frm">
<input type="hidden" name="frm_createlecturrer" value="true" required="" />
Full_Name
<input type="text" name="fullname" placeholder="Full Name" class="form-control" required="">
@ -76,9 +76,9 @@ if ($_SESSION['user_type'] != "Lecturer") {
Passport_Number / ID (Used as Intial Password)
<input type="text" class="form-control" name="passport" placeholder="Passport No./ID" required="">
<br> User Type :
<input type="radio" name="type" value="Lecturer" required=""> Lecturer
<input type="radio" name="type" value="TA" required=""> T/A
<input type="submit" class="btn btn-primary" value="Create"><br>
<input type="radio" name="type" value="Lecturer" required="" id="rad_lec"> Lecturer
<input type="radio" name="type" value="TA" required="" id="rad_ta"> T/A
<input type="submit" class="btn btn-primary" value="Create" id="create_btn"><br>
<?php
error_reporting(E_ALL);
@ -121,10 +121,10 @@ if ($_SESSION['user_type'] != "Lecturer") {
$btn = "<button class='btn-primary' onclick=\"updatePass(" . $row['User_ID'] . ",'$pass')\">Reset</button>";
if ($row['Status'] == "Active") {
$newstatus = "Blocked";
$btnBlock = "<button class='btn-danger' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\">Block</button>";
$btnBlock = "<button class='btn-danger' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\" id=\"block_acc_1\">Block</button>";
} else {
$newstatus = "Active";
$btnBlock = "<button class='btn-success' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\">Activate</button>";
$btnBlock = "<button class='btn-success' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\" id=\"activate_acc_1\">Activate</button>";
}
echo "<tr><td>" . $row['User_ID'] . "</td><td>" . $row['Full_Name'] . "</td><td>" . $row['Email'] . "</td> <td>" . $row['Passport_Number'] . "</td><td>$btn</td><td>$btnBlock</td></tr>";
@ -138,11 +138,11 @@ if ($_SESSION['user_type'] != "Lecturer") {
<div id="menu2" class="container tab-pane fade" style="margin-top:10px">
<b>Separate two student numbers with a space.</b><br>
<form action="batch_insert.php" method="post">
<form action="batch_insert.php" method="post" id="batch_frm">
<p>
<textarea cols="80" rows="16" name="users" required=""></textarea>
</p>
<input type="submit" class="btn btn-primary" value="Register Students"><br>
<input type="submit" class="btn btn-primary" value="Register Students" id="reg_btn"><br>
</form>
</div>

View File

@ -64,7 +64,7 @@ if (mysqli_connect_errno()) {
<?php
if ($_SESSION['user_type'] == "Lecturer") {
echo "&nbsp;&nbsp;&nbsp; <i class=\"fa fa-cog\" style=\"color:#fff;\"> </i> &nbsp;<a style='color:#fff !important' href=\"~\..\Admin.php\">Admin </a>";
echo "&nbsp;&nbsp;&nbsp; <i class=\"fa fa-cog\" style=\"color:#fff;\"> </i> &nbsp;<a style='color:#fff !important' href=\"~\..\Admin.php\" id=\"admin_btn\">Admin </a>";
}
?>

View File

@ -33,18 +33,18 @@ if (isset($_SESSION["user_fullname"])) {
<form method="post" action="Script.php" name="frm_login">
<input type="hidden" name="frm_login" value="true"/>
Student ID / Instructor Email
<input type="text" name="user" placeholder="Email / Student Number" class="form-control" required="required" />
<input type="text" name="user" placeholder="Email / Student Number" class="form-control" required="required" id="uname" />
<br>
Password
<input type="password" class="form-control" name="password" placeholder="password" required="required" />
<input type="password" class="form-control" name="password" placeholder="password" required="required" id="upass" />
<div class="text-center">
<br><input type="submit" class="btn-primary" value="Login">
<br><input type="submit" class="btn-primary" value="Login" id="log_btn">
</div>
<br> <a href="recover_password.php" style="font-weight:normal;color:#2471A3; font-family: Poppins-Regular;
font-size: 17px;">Reset my password</a>
<div class="text-center">
<br><span class="txt1">Don't have an account?</span>
<a class="txt2" href="signup.php" style="font-weight:normal">Sign Up</a>
<a class="txt2" href="signup.php" style="font-weight:normal" id="signup_btn">Sign Up</a>
</a>
</div>

View File

@ -17,24 +17,24 @@ include 'Header.php';
<div class="panel-body">
<form method="post" action="Script.php">
<form method="post" action="Script.php" id="signup_frm">
<input type="hidden" name="frm_signup_2" value="true" />
Full Name
<input type="text" name="fullname" placeholder="Your full name" class="form-control" value="<?php echo $_SESSION['user_fullname']; ?>" required="required" />
<input type="text" name="fullname" placeholder="Your full name" class="form-control" value="<?php echo $_SESSION['user_fullname']; ?>" required="required" id="funame"/>
Student ID
<input type="text" name="user_student_id" placeholder="Entre your student ID" class="form-control" value="<?php echo $_SESSION['user_student_id']; ?>" required="required">
<input type="text" name="user_student_id" placeholder="Entre your student ID" class="form-control" value="<?php echo $_SESSION['user_student_id']; ?>" required="required" id="std_id">
Email
<input type="text" name="email" placeholder="Email" class="form-control" value="<?php echo $_SESSION['user_email']; ?>" required="required" />
<input type="text" name="email" placeholder="Email" class="form-control" value="<?php echo $_SESSION['user_email']; ?>" required="required" id="email" />
Password (<i>must include uppercase and lowercase letters, digits and special characters</i>)
<input type="password" class="form-control" name="password" placeholder="Enter password" required="required" />
<input type="password" class="form-control" name="password" placeholder="Enter password" required="required" id="pass1" />
Confirm Password
<input type="password" class="form-control" name="confirmpassword" placeholder="Confirm password" required="required" />
<input type="password" class="form-control" name="confirmpassword" placeholder="Confirm password" required="required" id="pass2" />
<br>
<input type="submit" class="btn-primary" value="Sign up">
<input type="submit" class="btn-primary" value="Sign up" id="sign_btn">
<?php
error_reporting(E_ALL);
if (isset($_SESSION['info_signup2'])) {

View File

@ -32,12 +32,12 @@ class Admin(Actor):
#Locate "Admin" tab.
wait = WebDriverWait(driver, 10)
admin = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/nav/div/form/a[1]")))
admin = wait.until(EC.presence_of_element_located((By.ID, "admin_btn")))
admin.click()
#Locate "Create Lecturer/TA account" form
wait2 = WebDriverWait(driver, 10)
new_account_form = wait2.until(EC.presence_of_element_located((By.ID, "frm_create_acc")))
new_account_form = wait2.until(EC.presence_of_element_located((By.ID, "create_acc_frm")))
#Fill in the form fields
name_field = new_account_form.find_element(By.XPATH, "//input[@name='fullname']")
@ -53,13 +53,13 @@ class Admin(Actor):
#If "Lecturer" is specified in type parameter, select Lecturer account type, else use default
if type == "Lecturer":
type_radio = new_account_form.find_element(By.XPATH, "//input[@value='Lecturer']")
type_radio = new_account_form.find_element(By.ID, "rad_lec")
else:
type_radio = new_account_form.find_element(By.XPATH, "//input[@value='TA']")
type_radio = new_account_form.find_element(By.ID, "rad_ta")
type_radio.click()
submit_btn = new_account_form.find_element(By.XPATH, "//input[@type='submit'][@value='Create']")
submit_btn = new_account_form.find_element(By.ID, "create_btn")
submit_btn.click()
return 0
@ -92,23 +92,23 @@ class Admin(Actor):
#Locate the "Admin" tab.
wait = WebDriverWait(driver, 10)
admin = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/nav/div/form/a[1]")))
admin = wait.until(EC.presence_of_element_located((By.ID, "admin_btn")))
admin.click()
#Navigate to "Batch create form"
wait2 = WebDriverWait(driver, 10)
batch_tab = wait2.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div[1]/div/ul/li[2]/a")))
batch_tab = wait2.until(EC.presence_of_element_located((By.ID, "batch_tab")))
batch_tab.click()
#Fill in the form
wait3 = WebDriverWait(driver, 10)
batch_form = wait3.until(EC.presence_of_element_located((By.ID, "frm_batch_acc")))
batch_form = wait3.until(EC.presence_of_element_located((By.ID, "batch_frm")))
text_area = batch_form.find_element(By.XPATH, "//textarea[@name='users']")
for i in range(len(lst)):
text_area.send_keys(lst[i]+" ")
submit_btn = batch_form.find_element(By.XPATH, "//input[@type='submit'][@value='Create All']")
submit_btn = batch_form.find_element(By.ID, "reg_btn")
submit_btn.click()
except:
@ -139,22 +139,22 @@ class Admin(Actor):
#Locate the "Admin" tab.
wait = WebDriverWait(driver, 10)
admin = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/nav/div/form/a[1]")))
admin = wait.until(EC.presence_of_element_located((By.ID, "admin_btn")))
admin.click()
#Navigate to "Exisitin Accounts" table
wait2 = WebDriverWait(driver, 10)
exist_acc_tab = wait2.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div[1]/div/ul/li[3]/a")))
exist_acc_tab = wait2.until(EC.presence_of_element_located((By.ID, "ex_acc")))
exist_acc_tab.click()
#Alternate between block and activate
if op == "block":
#Locate first account and block it on existing account table
wait3 = WebDriverWait(driver, 10)
button = driver.find_element_by_id("block_acc_1")
button = driver.find_element(By.ID, "block_acc_1")
elif op == "activate":
wait3 = WebDriverWait(driver, 10)
button = driver.find_element_by_id("activate_acc_1")
button = driver.find_element(By.ID, "activate_acc_1")
driver.execute_script("arguments[0].click();", button)

View File

@ -44,6 +44,7 @@ class MyUtility:
"""
try:
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(self.getPageURL())
return driver
except:
@ -104,26 +105,35 @@ class MyUtility:
driver = self.getSession()
wait = WebDriverWait(driver, 10, ignored_exceptions='StaleElementReferenceException')
#Locate the signup form and fill in the student ID
signup_form = wait.until(EC.presence_of_element_located((By.ID, "signup_frm")))
#Click the sign up button, and fill the sign up form
signup_btn = wait.until(EC.presence_of_element_located((By.ID, "signup_btn")))
signup_btn.click()
#Find and fill full student name
wait2 = WebDriverWait(driver, 10)
signup_form = wait2.until(EC.presence_of_element_located((By.ID, "signup_frm")))
name_field = signup_form.find_element(By.ID, "funame")
name_field.send_keys(name)
#Find and fill student ID
student_id = signup_form.find_element(By.ID, "std_id")
std_id = self.fetch_new_student_id()
student_id.send_keys(std_id)
next_btn = signup_form.find_element(By.ID, "next_btn")
next_btn.click()
#Fill in student data and sign up.
wait2 = WebDriverWait(driver, 10, ignored_exceptions='StaleElementReferenceException')
reg_form = wait2.until(EC.presence_of_element_located((By.ID, "frm")))
name_field = reg_form.find_element(By.XPATH, "//form/input[2]")
name_field.send_keys(name)
email_field = reg_form.find_element(By.XPATH, "//form/input[3]")
#Find and fill email
email_field = signup_form.find_element(By.ID, "email")
email_field.send_keys(email)
password_field = reg_form.find_element(By.XPATH, "//form/input[4]")
#Find and fill password
password_field = signup_form.find_element(By.ID, "pass1")
password_field.send_keys(password)
re_password_field = reg_form.find_element(By.XPATH, "//form/input[5]")
#Find and fill password confirmation
re_password_field = signup_form.find_element(By.ID, "pass2")
re_password_field.send_keys(password)
submit = reg_form.find_element(By.XPATH, "//form/input[6]")
#Sign up new student
submit = signup_form.find_element(By.ID, "sign_btn")
submit.click()
return 0
@ -301,4 +311,13 @@ class MyUtility:
for i in range(ch):
ls.append(chr(random.randint(97,122)))
return ''.join(ls)
return ''.join(ls)
def clean(self, file):
"""This method clean the test scripts directory by resetting some
.txt files.
"""
#Clean 'course_code.txt' file
f = open(file, "w+")
f.close()