-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCode.java
204 lines (169 loc) · 9.02 KB
/
Code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package Testing;
import java.util.NoSuchElementException;
import java.util.Scanner;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Code
{
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://localhost/E-tuitions/index.php");
// Checking for logo link is working or not in navbar
System.out.println("\n Test Case:"+ 1 + "\n Checking that 'Logo' is working or not\n");
driver.findElement(By.className("navbar-brand")).click();
String URL1 = driver.getCurrentUrl();
if(URL1.equals("http://localhost/E-tuitions/"))
System.out.println(" The Logo is working. It successfully navigates To Home page");
else
System.out.println(" The logo is not working. Some Error was occurred");
System.out.println("------------------------------------------------------------------------------------------------------------------\n");
// Checking for Internal links for More Teachers is working or not on homepage
System.out.println(" Test Case 2: \n Checking For 'More Teachers' is internal link Or external link");
try
{
driver.findElement(By.linkText("More Teachers")).click();
String URL3 = driver.getCurrentUrl();
if (URL3.contains("E-tuitions"))
System.out.println(" It is an Internal Link - Redirecting to another page in the Same Application - Passed");
}
catch (NoSuchElementException e) {
System.out.println(" It is an External Link - Redirecting to another page in different Application - Failed");}
System.out.println("------------------------------------------------------------------------------------------------------------------\n");
// Checking for View Profile Link is working or not in search students page
System.out.println(" Test Case:"+ 3 + "\n Checking that 'view profile link' is working or not in search Teacher page \n");
driver.findElement(By.linkText("View Profile")).click();
String URL7 = driver.getCurrentUrl();
if(URL7.equals("http://localhost/E-tuitions/studentlogin.php"))
System.out.println(" The link is working. It successfully navigates To student login page");
else
System.out.println("The link is not working. Some Error was occurred");
System.out.println("------------------------------------------------------------------------------------------------------------------\n");
driver.get("http://localhost/E-tuitions/");
// Checking for Internal link of More Students is working or not on homepage
System.out.println(" Test Case 4: \n Checking For 'More Students' is internal link or external link");
try
{
driver.findElement(By.linkText("More Students")).click();
String URL2 = driver.getCurrentUrl();
if (URL2.contains("E-tuitions"))
System.out.println(" It is an Internal Link - Redirecting to another page in the Same Application - Passed");
}
catch (NoSuchElementException e) {
System.out.println(" It is an External Link - Redirecting to another page in different Application - Failed");}
System.out.println("-------------------------------------------------------------------------------------------------------------");
// Checking for View Profile Link is working or not in search students page
System.out.println("\n Test Case:"+ 5 + "\n Checking that 'view profile link' is working or not in search students page \n");
driver.get("http://localhost/E-tuitions/students.php");
driver.findElement(By.linkText("View Profile")).click();
String URL6 = driver.getCurrentUrl();
if(URL6.equals("http://localhost/E-tuitions/teacherlogin.php"))
System.out.println(" The link is working. It successfully navigates To teacher login page");
else
System.out.println("The link is not working. Some Error was occurred");
System.out.println("-------------------------------------------------------------------------------------------------------------");
// Checking for About Us Link is working or not in navbar
System.out.println("\n Test Case:"+ 6 + "\n Checking that 'About Us link' is working or not\n");
driver.findElement(By.linkText("About Us")).click();
URL1 = driver.getCurrentUrl();
if(URL1.equals("http://localhost/E-tuitions/aboutus.php"))
System.out.println(" The About Us Page is working. It successfully navigates To About Us page");
else
System.out.println(" The About Us link is not working. Some Error was occurred");
System.out.println("------------------------------------------------------------------------------------------------------------------\n");
// Checking for Reach Us Link is working or not in navbar
System.out.println(" Test Case:"+ 7 + "\n Checking that 'Reach Us link' is working or not\n");
driver.findElement(By.linkText("Reach Us")).click();
URL1 = driver.getCurrentUrl();
if(URL1.equals("http://localhost/E-tuitions/contactus.php"))
System.out.println(" The Reach Us Page is working. It successfully navigates To Contact Us page");
else
System.out.println(" The Reach Us link is not working. Some Error was occurred");
// Now Test will start for teacher login Input Section
int i=8;
System.out.println("\n\n========================== Now The Test will start for Teacher Login Input Section ===========================");
teacherLoginLoop: while(true)
{
Scanner obj = new Scanner(System.in);
System.out.println("\nPress 1: For Test Teacher Login");
System.out.println("Press 2: For Exit From Teacher Login Section");
System.out.print("\nPut Your Choice Here: ");
int choice=obj.nextInt();
switch(choice)
{
case 1:
System.out.println("\n---------------------------------------------------------------------------------------------------------\n");
System.out.println(" Test Case:"+ i + "\n Checking For 'Teacher Login' is valid or not\n");
driver.get("http://localhost/E-tuitions/teacherlogin.php");
Scanner sc = new Scanner(System.in);
System.out.print(" Enter UserId: ");
String userid = sc.nextLine();
System.out.print(" Enter Password: ");
String password = sc.nextLine();
driver.findElement(By.className("teacherid")).sendKeys(userid);
driver.findElement(By.className("teacherpassword")).sendKeys(password);
driver.findElement(By.id("go")).click();
String URL4 = driver.getCurrentUrl();
if (URL4.contains("afterteacherlogin.php"))
{
System.out.println("\n Login Successful!!");
System.out.println("\n-------------------------------------------------------------------------------------------");
}
else
{
System.out.println("\n Login Unsuccessful!!");
System.out.println("\n-------------------------------------------------------------------------------------------------------------------------------");
}
i++;
break;
case 2:
break teacherLoginLoop;
default:
System.out.print("\nPlease Choose From Given Choice Only");
}
}
// Test will start for Student login Input Section
System.out.println("\n========================== Now the test will start for Student Login Input Section ===========================\n");
studentLoginLoop: while(true)
{
Scanner obj = new Scanner(System.in);
System.out.println("\nPress 1: For Test Student Login");
System.out.println("Press 2: For Exit From Student Login Section");
System.out.print("\nPut Your Choice Here: ");
int choice=obj.nextInt();
switch(choice)
{
case 1:
System.out.println("\n-------------------------------------------------------------------------------------------------------------------------\n");
System.out.println(" Test Case:"+ i + "\n Checking For 'Teacher Login' is valid or not\n");
driver.get("http://localhost/E-tuitions/studentlogin.php");
System.out.print(" Enter UserId: ");
Scanner sc = new Scanner(System.in);
String userid = sc.nextLine();
System.out.print(" Enter Password: ");
String password = sc.nextLine();
driver.findElement(By.className("teacherid")).sendKeys(userid);
driver.findElement(By.className("teacherpassword")).sendKeys(password);
driver.findElement(By.id("go")).click();
String URL5 = driver.getCurrentUrl();
if (URL5.contains("afterstudentlogin.php"))
{
System.out.println("\n Login Successful!!");
System.out.println("\n-------------------------------------------------------------------------------------------------------------");
}
else
{
System.out.println("\n Login Unsuccessful!!");
System.out.println("\n-------------------------------------------------------------------------------------------------------------------");
}
i++;
break;
case 2:
break studentLoginLoop;
default:
System.out.print("\nPlease Choose From Given Choice Only");
}
}
driver.close();
}
}