2
Java Source Code for simulating Student login to Class Allocation system import static org.junit.Assert.*; import java.util.Random; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class TestJunit4{ String[] StudentID = {<Student IDs>}; String randomStudentID = (StudentID[new Random().nextInt(StudentID.length)]); String StudentPassword = "PASSWORD"; private WebDriver driver; private String baseUrl; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { //use Firefox driver driver = new FirefoxDriver(); //use demo.mahara.org site for testing baseUrl = "https://test.cas.uwa.edu.au"; //timeout if site page does not load in 30 seconds driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @After public void tearDown() throws Exception { //quit the test driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } @Test public void ValidLoginStudentModuleMainNavigation() throws

Java Source Code for simulating Student login to Class Allocation system

Embed Size (px)

Citation preview

Page 1: Java Source Code for simulating Student login to Class Allocation system

Java Source Code for simulating Student login to Class Allocation system

import static org.junit.Assert.*;import java.util.Random;import java.util.concurrent.TimeUnit;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;

public class TestJunit4{String[] StudentID = {<Student IDs>};String randomStudentID = (StudentID[new Random().nextInt(StudentID.length)]);String StudentPassword = "PASSWORD";private WebDriver driver;

private String baseUrl; private StringBuffer verificationErrors = new StringBuffer();

@Before public void setUp() throws Exception { //use Firefox driver driver = new FirefoxDriver(); //use demo.mahara.org site for testing baseUrl = "https://test.cas.uwa.edu.au"; //timeout if site page does not load in 30 seconds driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }

@After public void tearDown() throws Exception { //quit the test driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }

@Test public void ValidLoginStudentModuleMainNavigation() throws InterruptedException {

//navigate to base url driver.get(baseUrl + "/"); //clear username filed driver.findElement(By.name("USER")).clear(); //enter user name driver.findElement(By.name("USER")).sendKeys(randomStudentID); // driver.findElement(By.name("USER")).sendKeys("12121212"); //clear password driver.findElement(By.name("PASSWORD")).clear();

Page 2: Java Source Code for simulating Student login to Class Allocation system

//enter password driver.findElement(By.name("PASSWORD")).sendKeys(StudentPassword); //click on submit button driver.findElement(By.className("form")).submit(); //Check Student module login was a success assertEquals(driver.getTitle(),"Allocate+ Student"); //Navigate header menu (Home | Timetable | Preferences ) driver.findElement(By.linkText("Timetable")).click(); driver.findElement(By.linkText("Preferences")).click(); //driver.findElement(By.linkText("LiveCal")).click(); driver.findElement(By.linkText("Home")).click(); // Search subject code or description driver.findElement(By.id("search_box")).clear(); //enter valid subject code driver.findElement(By.id("search_box")).sendKeys("ANTH"); driver.findElement(By.id("search-submit-div")).submit(); //click on the view button driver.findElement(By.className("button-cell")).click(); /*click on the logout button on CAS Student module*/ driver.findElement(By.linkText("Logout")).click(); /* Click the END SSO Session button */ driver.findElement(By.linkText("End SSO session")).click(); assertEquals(driver.getTitle(), "Login : Single sign-on network : The University of Western

Australia"); }

}