-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.java
333 lines (265 loc) · 12.7 KB
/
Functions.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package FunctionLibrary;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
//import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Functions {
//TC001
//@Test
public void Fun_Launch_Ocart() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/");
//String x= driver.findElement(By.xpath("/html/body/header/div/div/div[1]/div/h1/a")).getText();
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
String x= driver.findElement(By.xpath(p.getProperty("launch"))).getText();
String y="Your Store";
if(x.equals(y))
{
System.out.println("User can able to launch the opencart application in firefox browser.\r\n");
}
else
System.out.println("User is not able to launch the opencart application in firefox browser");
}
//TC002
public void Fun_ViewMyAccount() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/");
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click();
driver.findElement(By.xpath(p.getProperty("myacc"))).click();
String str1="Register";
//String str2=driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[1]/a")).getText();
String str2=driver.findElement(By.xpath(p.getProperty("reg"))).getText();
String str3="Login";
// String str4=driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[2]/a")).getText();
String str4=driver.findElement(By.xpath(p.getProperty("login"))).getText();
if(str1.equals(str2) && str3.equals(str4))
{
System.out.println("User can able to get two options Register and Login");
}
else
System.out.println("User not able to get two options Register and Login");
}
//TC003
public void Fun_ClickRegister() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/");
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click(); //account
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[1]/a")).click(); //register
driver.findElement(By.xpath(p.getProperty("myacc"))).click();
driver.findElement(By.xpath(p.getProperty("reg"))).click();
String s1="Register Account";
// String s2=driver.findElement(By.xpath("/html/body/div[2]/div/div/h1")).getText();
String s2=driver.findElement(By.xpath(p.getProperty("register2"))).getText();
if(s1.equals(s2))
{
System.out.println("The user can able to click on Register and get the register page");
}
else
System.out.println("unable to get register page");
driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[1]/a")).click();
}
//TC004
public void Fun_CountInputBox() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/");
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click();
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[1]/a")).click();
driver.findElement(By.xpath(p.getProperty("myacc"))).click();
driver.findElement(By.xpath(p.getProperty("reg"))).click();
List<WebElement> L=driver.findElements(By.tagName("input"));
System.out.println("Count of no.of inputs "+L.size());
if(L.size()==9)
{
System.out.println("Test case has passed");
}
else
System.out.println("Test case has failed");
}
//TC005
public void Fun_RegisterUser() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/");
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click();
// driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[1]/a")).click();
driver.findElement(By.xpath(p.getProperty("myacc"))).click();
driver.findElement(By.xpath(p.getProperty("reg"))).click();
driver.findElement(By.id("input-firstname")).sendKeys("abcde");
driver.findElement(By.id("input-lastname")).sendKeys("vvv");
driver.findElement(By.id("input-email")).sendKeys("[email protected]");
driver.findElement(By.id("input-telephone")).sendKeys("1134567890");
driver.findElement(By.id("input-password")).sendKeys("blalala");
driver.findElement(By.id("input-confirm")).sendKeys("blalala");
//driver.findElement(By.xpath("/html/body/div[2]/div/div/form/div/div/input[1]")).click();// clicking privary policy
// driver.findElement(By.xpath("/html/body/div[2]/div/div/form/div/div/input[2]")).click();
driver.findElement(By.xpath(p.getProperty("policy"))).click();
driver.findElement(By.xpath(p.getProperty("continue"))).click();
/*String a="Continue";
// String b= driver.findElement(By.cssSelector("input.btn")).getText();
String b=driver.findElement(By.xpath(p.getProperty("continue"))).getText();
if(a.equals(b))
{
System.out.println("User can able to click on continue button \"Your Account Has Been Created");
}
else
System.out.println("user unable to click onto continue button");*/
}
//TC006
public void Fun_Login() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
FileReader r1=new FileReader("D:\\CoreJava\\TestData.properties");
Properties p=new Properties();
Properties p1=new Properties();
p.load(r);
p1.load(r1);
//driver.get("https://demo.opencart.com/");
//driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click();
driver.get("https://demo.opencart.com/index.php?route=account/login");
driver.findElement(By.id("input-email")).click(); //able to click and send username
// driver.findElement(By.id("input-email")).sendKeys("[email protected]");
driver.findElement(By.id("input-email")).sendKeys(p1.getProperty("email1"));
//login functionality
driver.findElement(By.id("input-password")).click();//able to click and send password
driver.findElement(By.id("input-password")).sendKeys("gggggggg");
driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).click();
//driver.findElement(By.xpath(p.getProperty("login2"))).click();
/*String a="Login";
// String b= driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).getText();
String b= driver.findElement(By.xpath(p.getProperty("login2"))).getText();
if(a.equals(b))
{
System.out.println("User can able to click on Login Button ang get account page with My Account string");
}
else
System.out.println("Unable to login");*/
}
//TC00_6(2)
public void Fun_LoginInvalid() throws Exception
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/index.php?route=account/login");
// driver.findElement(By.id("input-email")).click();
driver.findElement(By.id("input-email")).sendKeys("[email protected]");
//login functionality
// driver.findElement(By.id("input-password")).click();
driver.findElement(By.id("input-password")).sendKeys("gggggggg");
driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).click();
// password change
driver.findElement(By.xpath("/html/body/div[2]/div/aside/div/a[3]")).click();
//driver.findElement(By.xpath(p.getProperty("pwd"))).click();
driver.findElement(By.xpath("//*[@id=\"input-password\"]")).sendKeys("ssssssss");
driver.findElement(By.xpath("//*[@id=\"input-confirm\"]")).sendKeys("ssssssss");
driver.findElement(By.xpath("/html/body/div[2]/div/div/form/div/div[2]/input")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).click();
driver.findElement(By.id("input-password")).click();
driver.findElement(By.id("input-password")).sendKeys("gggggggg");
//driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).click();
/* String s1=driver.findElement(By.xpath("/html/body/div[2]/div[1]")).getText();
String s2="Warning: No match for E-Mail Address and/or Password.";
if(s1.equals(s2))
{
System.out.println("User can able to click on Login Button and get the Warning message saying \"Warning : No matches for Email and/or password");
}
else
System.out.println("Unable to get warning message");
// gives incorrect password error and asks for valid password*/
}
//TC007
public void Fun_Logout() throws InterruptedException
{
String s= "C:\\Users\\TRNG\\Downloads\\gecko\\geckodriver.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",s);
driver = new FirefoxDriver();
driver.get("https://demo.opencart.com/index.php?route=account/account");
driver.findElement(By.id("input-email")).click();
driver.findElement(By.id("input-email")).sendKeys("[email protected]");
driver.findElement(By.id("input-password")).click();
driver.findElement(By.id("input-password")).sendKeys("gggggggg");
driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/form/input")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/a/span[1]")).click();
driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[5]/a")).click();
/*FileReader r=new FileReader("D:\\CoreJava\\Framework.properties");
Properties p=new Properties();
p.load(r);
driver.findElement(By.xpath(p.getProperty("login2"))).click();
driver.findElement(By.xpath(p.getProperty("myacc"))).click();
driver.findElement(By.xpath(p.getProperty("logout"))).click();*/
/* String a="Logout";
String b= driver.findElement(By.xpath("/html/body/nav/div/div[2]/ul/li[2]/ul/li[5]/a")).getText();
if(a.equals(b))
{
System.out.println("Logedin user can able to logout from Ocart successfully");
}
else
{
System.out.println("user couldn't logout properly");
}*/
String month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
String amPm[] = { "AM", "PM" };
GregorianCalendar gcal = new GregorianCalendar();
try {
FileWriter fw=new FileWriter("D:\\CoreJava\\HybridFramework\\src\\LogInformation\\log.txt");
fw.write("Date: "+ month[gcal.get(Calendar.MONTH)] + " "+ gcal.get(Calendar.DATE) + ", "+ gcal.get(Calendar.YEAR) + "\n"
+ "Time: "+ gcal.get(Calendar.HOUR) + ":"+ gcal.get(Calendar.MINUTE) + ":"+ gcal.get(Calendar.SECOND) + " "
+ amPm[gcal.get(Calendar.AM_PM)]);
fw.close();
}
catch (IOException e) {
System.out.println("exception occoured"+ e);
}
}
}