-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools_QA.java
More file actions
1197 lines (841 loc) · 45.2 KB
/
Copy pathTools_QA.java
File metadata and controls
1197 lines (841 loc) · 45.2 KB
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package project;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import com.google.common.io.Files;
public class Tools_QA {
public static void main(String[] args) throws InterruptedException, IOException
{
//Luanch browser
System.setProperty("webdriver.chrome.driver", "C:\\Users\\dell\\Desktop\\selenium jar\\chromedriver_win32 (1)\\chromedriver.exe");
WebDriver w = new ChromeDriver();
//Window maximize
w.manage().window().maximize();
//open URL
w.get("https://demoqa.com/");
Thread.sleep(2000);
//GetCurrent URL
System.out.println("Current URL: "+ w.getCurrentUrl());
//Get Title
System.out.println("Title: "+ w.getTitle());
//-------------------------------Module 1 : Elements------------------------------------------------------
JavascriptExecutor js = (JavascriptExecutor) w;
js.executeScript("window.scrollBy(0,1500)");
w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div/div[1]/div/div[3]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]")).getText());
// -------------------------------------textbox-------------------------------------------
w.findElement(By.xpath("//*[@id=\"item-0\"]/span")).click();
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
w.findElement(By.id("userName")).sendKeys("Yogita");
w.findElement(By.id("userEmail")).sendKeys("[email protected]");
w.findElement(By.id("currentAddress")).sendKeys("Nashik");
w.findElement(By.id("permanentAddress")).sendKeys("Jalgaon");
Thread.sleep(2000);
JavascriptExecutor jss = (JavascriptExecutor) w;
jss.executeScript("window.scrollTo(0,document.body.scrollHeight)");
w.findElement(By.xpath("//*[@id=\"submit\"]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/form[1]/div[6]/div[1]")).getText());
//------------------------------------------- check box-------------------------------------------------------------
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/ul[1]/li[2]")).click();
Thread.sleep(1000);
String s = w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[1]")).getText(); //gettext
System.out.println("Text: " +s);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/button[1]/*[1]")).click(); // plus
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/ol[1]/li[1]/ol[1]/li[1]/ol[1]/li[1]/span[1]/label[1]/span[1]/*[1]")).click(); // notes
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/ol[1]/li[1]/ol[1]/li[2]/ol[1]/li[1]/ol[1]/li[1]/span[1]/label[1]/span[1]/*[1]")).click(); // react
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/ol[1]/li[1]/ol[1]/li[2]/ol[1]/li[1]/ol[1]/li[2]/span[1]/label[1]/span[1]/*[1]")).click(); // angular
JavascriptExecutor js1 = (JavascriptExecutor) w;
js1.executeScript("window.scrollBy(0,1500)");
w.findElement(By.xpath("//span[contains(text(),'Downloads')]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
//---------------------------------------------- radio button----------------------------------------------------------------------
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/ul[1]/li[3]")).click();
w.findElement(By.xpath("//label[contains(text(),'Yes')]")).click();
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
Thread.sleep(1000);
//-------------------------------------- webtable--------------------------------------------------------------------
w.findElement(By.xpath("//*[@id=\"item-3\"]")).click();
Thread.sleep(1000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
// add record
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[1]/button[1]")).click();
w.findElement(By.id("firstName")).sendKeys("Yogita");
w.findElement(By.id("lastName")).sendKeys("Badhe");
w.findElement(By.id("userEmail")).sendKeys("[email protected]");
w.findElement(By.id("age")).sendKeys("25");
w.findElement(By.id("salary")).sendKeys("25000");
w.findElement(By.id("department")).sendKeys("MCA");
Thread.sleep(3000);
w.findElement(By.xpath("//*[@id=\"submit\"]")).click();
System.out.println("Webtable -Add record");
// edit table
Thread.sleep(3000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[2]/div[1]/div[7]/div[1]/span[1]/*[1]")).click();
w.findElement(By.id("age")).clear();
Thread.sleep(1000);
w.findElement(By.id("age")).sendKeys("30");
Thread.sleep(2000);
w.findElement(By.id("salary")).clear();
Thread.sleep(2000);
w.findElement(By.id("salary")).sendKeys("60000");
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"submit\"]")).click();
Thread.sleep(2000);
System.out.println("Webtable - Edit record");
// delete record
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[1]/div[7]/div[1]/span[2]/*[1]")).click();
System.out.println("Webtable - Delete record");
Thread.sleep(2000);
// search box
w.findElement(By.xpath("//input[@id='searchBox']")).sendKeys("Yogita");
Thread.sleep(2000);
System.out.println("Webtable - Search box");
// scrolling
JavascriptExecutor js2 = (JavascriptExecutor) w;
js2.executeScript("window.scrollBy(0,1500)");
//-------------------------------------- buttons---------------------------------------------------------
w.findElement(By.xpath("//*[@id=\"item-4\"]")).click();
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
// double click
Actions a = new Actions(w);
WebElement web = w.findElement(By.xpath("//button[@id='doubleClickBtn']"));
a.doubleClick(web).build().perform();
System.out.println(w.findElement(By.xpath("//p[@id='doubleClickMessage']")).getText());
Thread.sleep(2000);
// right click
Actions a1 = new Actions(w);
WebElement web1 = w.findElement(By.xpath("//button[@id='rightClickBtn']"));
a.contextClick(web1).build().perform();
System.out.println(w.findElement(By.xpath("//p[@id='rightClickMessage']")).getText());
Thread.sleep(2000);
// click me
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[3]/button[1]")).click();
System.out.println(w.findElement(By.xpath("//p[@id='dynamicClickMessage']")).getText());
Thread.sleep(2000);
// scrolling
JavascriptExecutor js3 = (JavascriptExecutor) w;
js3.executeScript("window.scrollBy(0,1500)");
//------------------------------------- links--------------------------------------------------------------------------
w.findElement(By.xpath("//*[@id=\"item-5\"]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
// new tab
System.out.println(w.findElement(By.xpath("//strong[contains(text(),'Following links will open new tab')]")).getText());
w.findElement(By.xpath("//a[@id='simpleLink']")).click();
Thread.sleep(3000);
// window handling
Set<String> ss = w.getWindowHandles();
Iterator<String> it = ss.iterator();
String pc = it.next();
String cc = it.next();
w.switchTo().window(cc);
Thread.sleep(2000);
w.switchTo().window(pc);
// links will send an api call
JavascriptExecutor js4 = (JavascriptExecutor) w;
js4.executeScript("window.scrollBy(0,300)");
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//strong[contains(text(),'Following links will send an api call')]")).getText());
w.findElement(By.linkText("Created")).click();
System.out.println("Link has responded with staus 201 and status text Created");
Thread.sleep(2000);
w.findElement(By.linkText("No Content")).click();
System.out.println("Link has responded with staus 204 and status text No Content");
Thread.sleep(2000);
w.findElement(By.linkText("Moved")).click();
System.out.println("Link has responded with staus 301 and status text Moved Permanently");
Thread.sleep(2000);
w.findElement(By.linkText("Bad Request")).click();
System.out.println("Link has responded with staus 400 and status text Bad Request");
Thread.sleep(2000);
w.findElement(By.linkText("Unauthorized")).click();
System.out.println("Link has responded with staus 401 and status text Unauthorized");
Thread.sleep(2000);
w.findElement(By.linkText("Forbidden")).click();
System.out.println("Link has responded with staus 403 and status text Forbidden");
Thread.sleep(2000);
w.findElement(By.linkText("Not Found")).click();
System.out.println("Link has responded with staus 404 and status text Not Found");
Thread.sleep(2000);
//------------------------------------------ broken link images-------------------------------------------
w.findElement(By.xpath("//*[@id=\"item-6\"]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
//valid
JavascriptExecutor js5 = (JavascriptExecutor) w;
js5.executeScript("window.scrollBy(0,500)");
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div[1]/a[1]")).click();
Thread.sleep(1000);
System.out.println("Valid Link");
w.navigate().back();
Thread.sleep(2000);
//broken link
JavascriptExecutor js6 = (JavascriptExecutor) w;
js6.executeScript("window.scrollBy(0,500)");
Thread.sleep(2000);
w.findElement(By.linkText("Click Here for Broken Link")).click();
Thread.sleep(2000);
System.out.println("Broken Link");
w.navigate().back();
Thread.sleep(2000);
//------------------------------------------- upload and download------------------------------------------------------------------------
JavascriptExecutor js7 = (JavascriptExecutor) w;
js7.executeScript("window.scrollBy(0,1000)");
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"item-7\"]")).click();
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
w.findElement(By.cssselector("input#uploadFile")).sendKeys("D:\\Yogita Badhe.docx");
Thread.sleep(2000);
w.findElement(By.id("downloadButton")).click();
//-------------------------------------dynamic property----------------------------------------------------------------------------
JavascriptExecutor js8 = (JavascriptExecutor) w;
js8.executeScript("window.scrollBy(0,1000)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Dynamic Properties')]")).click();
Thread.sleep(7000);
System.out.println(w.findElement(By.xpath("//div[contains(text(),'Dynamic Properties')]")).getText());
//-------------------------------------------------Module 2: Practice form-----------------------------------------
w.get("https://demoqa.com/");
Thread.sleep(3000);
JavascriptExecutor jse = (JavascriptExecutor) w; //scrolling
jse.executeScript("window.scrollBy(0,400)");
Thread.sleep(2000);
System.out.println("Current URL:" + w.getCurrentUrl());
System.out.println("URL of page is:"+w.getTitle());
//Click on form module
w.findElement(By.xpath("//h5[contains(text(),'Forms')]")).click();
Thread.sleep(2000);
js.executeScript("window.scrollBy(0,400)");
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/ul[1]/li[1]")).click(); //click practice form
Thread.sleep(2000);
w.findElement(By.id("firstName")).sendKeys("Yogita");
w.findElement(By.id("lastName")).sendKeys("Badhe");
w.findElement(By.id("userEmail")).sendKeys("[email protected]");
w.findElement(By.xpath("//label[contains(text(),'Female')]")).click();
Thread.sleep(2000);
js.executeScript("window.scrollBy(0,500)", "");
w.findElement(By.id("userNumber")).sendKeys("9689145560");
Thread.sleep(2000);
//subjects
// w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/form[1]/div[6]/div[2]/div[1]/div[1]/div[1]")).sendKeys("maths");
//hobbies
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/form[1]/div[7]/div[2]/div[1]/label[1]")).click();
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/form[1]/div[7]/div[2]/div[3]/label[1]")).click();
Thread.sleep(2000);
js.executeScript("window.scrollBy(0,350)", "");
//file upload
w.findElement(By.id("uploadPicture")).sendKeys("D:\\Yogita Badhe.docx");
//Current Address
w.findElement(By.id("currentAddress")).sendKeys("Address");
//select state
w.findElement(By.xpath("//div[contains(text(),'Select State')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//div[contains(text(),'Uttar Pradesh')]")).click();
Thread.sleep(2000);
//select city
w.findElement(By.xpath("//div[contains(text(),'Select City')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//div[contains(text(),'Lucknow')]")).click();
Thread.sleep(2000);
TakesScreenshot sc11= (TakesScreenshot) w;
File src11 = sc11.getScreenshotAs(OutputType.FILE);
Files.copy(src11, new File("D:\\screenshot\\forms1.jpg"));
System.out.println("Screenshot capture successfully");
Thread.sleep(2000);
w.findElement(By.id("submit")).click();
Thread.sleep(2000);
//-----------------------------------------Module 3: Alert, Frames and windows --------------------------------------------------------
w.navigate().to("https://demoqa.com/");
Thread.sleep(2000);
System.out.println("Title of Page="+w.getTitle());
System.out.println("URL of Page="+w.getCurrentUrl());
Thread.sleep(1000);
w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div/div[3]")).click();
System.out.println(w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]")).getText());
System.out.println("Title of Page="+w.getTitle());
System.out.println("URL of Page=" +w.getCurrentUrl());
//window Handling
//window 1
w.findElement(By.xpath("//span[contains(text(),'Browser Windows')]")).click();
w.findElement(By.id("tabButton")).click();
Set <String> window1=w.getWindowHandles();
Iterator <String> it1=window1.iterator();
String par_win1=it1.next();
String child_win1=it1.next();
w.switchTo().window(par_win1);
Thread.sleep(1000);
w.switchTo().window(child_win1);
System.out.println(w.findElement(By.id("sampleHeading")).getText());
System.out.println("new tab opened");
w.switchTo().window(par_win1);
//window2
w.findElement(By.id("windowButton")).click();
Set <String> window2=w.getWindowHandles();
Iterator <String> it2=window2.iterator();
String par_win2=it2.next();
String child_win2=it2.next();
w.switchTo().window(par_win2);
Thread.sleep(1000);
w.switchTo().window(child_win2);
System.out.println(w.findElement(By.id("sampleHeading")).getText());
System.out.println("New window opened");
w.switchTo().window(par_win2);
//window3
w.findElement(By.id("messageWindowButton")).click();
Set <String> window3=w.getWindowHandles();
Iterator <String> it3=window3.iterator();
String par_win3=it3.next();
String child_win3=it3.next();
w.switchTo().window(par_win3);
Thread.sleep(1000);
w.switchTo().window(child_win3);
System.out.println(w.findElement(By.xpath("/html[1]/body[1]")).getText());
System.out.println("New Message window opened");
Thread.sleep(1000);
w.switchTo().window(par_win3);
//Alert
w.findElement(By.xpath("//span[contains(text(),'Alerts')]")).click();
//simple alert
w.findElement(By.id("alertButton")).click();
Thread.sleep(1000);
//for accepting simple alert
Alert a11=w.switchTo().alert();
System.out.println(a11.getText());
System.out.println("Simple Alert");
a11.accept();
System.out.println("Simple Alert accepted");
//wait alert
w.findElement(By.id("timerAlertButton")).click();
Thread.sleep(6000);
//for accepting wait alert
Alert a2=w.switchTo().alert();
System.out.println(a2.getText());
System.out.println("wait alert");
a2.accept();
System.out.println("wait Alert accepted");
//confirm alert
//accepting confirm alert
w.findElement(By.id("confirmButton")).click();
Thread.sleep(1000);
Alert a3=w.switchTo().alert();
System.out.println(a3.getText());
Thread.sleep(1000);
System.out.println("confirm alert");
a3.accept();
System.out.println("confirm Alert accepted");
//dissmiss confirm alert
w.findElement(By.id("confirmButton")).click();
Thread.sleep(1000);
a3=w.switchTo().alert();
System.out.println(a3.getText());
Thread.sleep(1000);
System.out.println("confirm alert");
a3.dismiss();
System.out.println("confirm Alert dissmissed");
//prompt alert
w.findElement(By.id("promtButton")).click();
Thread.sleep(1000);
Alert a4=w.switchTo().alert();
a4.sendKeys("abc123");
System.out.println(a4.getText());
Thread.sleep(1000);
System.out.println("prompt alert");
a4.accept();
System.out.println("prompt Alert accepted");
//prompt alert dismiss
w.findElement(By.id("promtButton")).click();
Thread.sleep(1000);
a4=w.switchTo().alert();
a4.sendKeys("madhuri");
System.out.println(a4.getText());
Thread.sleep(1000);
System.out.println("prompt alert");
a4.dismiss();
System.out.println("prompt Alert dismissed");
//Frames
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[3]/div[1]/ul[1]/li[3]/span[1]")).click();
w.switchTo().frame("frame1");
System.out.println(w.findElement(By.id("sampleHeading")).getText());
System.out.println("from frame1");
w.switchTo().defaultContent();
w.switchTo().frame("frame2");
System.out.println(w.findElement(By.xpath("//h1[@id='sampleHeading']")).getText());
System.out.println("from frame2");
//for counting no. of frames
List<WebElement> l=w.findElements(By.tagName("iframe"));
System.out.println("Total iframes="+ l.size());
//nested frames
w.navigate().back();
JavascriptExecutor js0=(JavascriptExecutor) w;
js0.executeScript("window.scrollBy(0,1500)");
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[3]/div[1]/ul[1]/li[4]/span[1]")).click();
List<WebElement> l2=w.findElements(By.tagName("iframe"));
System.out.println("Total iframes in nested iframes="+ l2.size());
//for dialogue
w.get("https://demoqa.com/modal-dialogs");
//for small modal
w.findElement(By.id("showSmallModal")).click();
System.out.println(w.findElement(By.xpath("/html/body/div[4]/div/div/div[2]")).getText());
w.findElement(By.id("closeSmallModal")).click();
//for large modal
w.findElement(By.id("showLargeModal")).click();
System.out.println(w.findElement(By.xpath("//p[contains(text(),'Lorem Ipsum is simply dummy text of the printing a')]")).getText());
w.findElement(By.id("closeLargeModal")).click();
//----------------------------------------- Module 4 :Widgets ---------------------------------------------------------------------------
w.get("https://demoqa.com/");
w.manage().window().maximize();
Thread.sleep(2000);
w.getTitle();
System.out.println("Title of page is : "+w.getTitle());
w.getCurrentUrl();
System.out.println("Current URL is : "+w.getCurrentUrl());
// Widgets Module
// for scroll down the page & click on widgets
JavascriptExecutor jes= (JavascriptExecutor) w;
jes.executeScript("window.scrollBy(0, 300)");
w.findElement(By.xpath("//h5[contains(text(),'Widgets')]")).click();
w.manage().window().maximize();
jes.executeScript("window.scrollBy(0, 500)");
Thread.sleep(2000);
w.getTitle();
System.out.println("Title of Current page is : "+w.getTitle());
w.getCurrentUrl();
System.out.println("Current URL is : " +w.getCurrentUrl());
// for Accordian
jes.executeScript("window.scrollBy(0,-400)");
Thread.sleep(2000);
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/ul[1]/li[1]/span[1]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//div[@id='section1Heading']")).click();
Thread.sleep(2000);
w.findElement(By.id("section2Heading")).click();
Thread.sleep(2000);
jes.executeScript("window.scrollBy(0,300)");
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"section3Heading\"]")).click();
Thread.sleep(2000);
List<WebElement> L= w.findElements(By.tagName("a"));
System.out.println("Total Links are : "+L.size());
w.navigate().back();
Thread.sleep(2000);
// for Auto Complete
jes.executeScript("window.scrollBy(0,500)");
w.findElement(By.xpath("//span[contains(text(),'Auto Complete')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]")).click();
/* w.findElement(By.xpath("//div[contains(text(),'Red')]")).click();
w.findElement(By.xpath("//div[contains(text(),'Purple')]")).click();
w.findElement(By.xpath("//div[contains(text(),'Indigo')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"autoCompleteSingleContainer\"]/div/div[1]")).click(); //sendKeys("Orange");
w.findElement(By.xpath("//*[@id=\"autoCompleteSingleContainer\"]/div/div[1]/div[1]")).click(); //Defect - not accepting data */
w.navigate().back();
Thread.sleep(2000);
// for Date Picker
jes.executeScript("window.scrollBy(0,250)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Date Picker')]")).click();
Thread.sleep(2000);
// for Select Date
w.findElement(By.id("datePickerMonthYearInput")).click();
Select s1= new Select(w.findElement(By.className("react-datepicker__month-select")));
s1.selectByValue("4");
Thread.sleep(2000);
Select s2= new Select(w.findElement(By.className("react-datepicker__year-select")));
s2.selectByVisibleText("1993");
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]/div[5]/div[5]")).click();
Thread.sleep(2000);
System.out.println("05/27/1993 Date is selected");
// for Date And Time
w.findElement(By.id("dateAndTimePickerInput")).click();
jes.executeScript("window.scrollBy(0,350)");
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/span[1]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"dateAndTimePicker\"]/div[2]/div[2]/div/div/div[2]/div[1]/div[2]/div[1]/div[1]/div[6]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"dateAndTimePicker\"]/div[2]/div[2]/div/div/div[2]/div[1]/div[2]/div[2]/div/span[1]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[13]/a[1]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[1]/a[1]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"dateAndTimePicker\"]/div[2]/div[2]/div/div/div[2]/div[1]/div[2]/div[2]/div[1]/div[6]")).click();
w.findElement(By.xpath("//div[contains(text(),'10')]")).click();
Thread.sleep(2000);
//for time
w.findElement(By.id("dateAndTimePickerInput")).click();
jes.executeScript("window.scrollBy(0,300)");
Thread.sleep(2000);
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]")).click();
jes.executeScript("window.scrollBy(0,-200)");
w.findElement(By.xpath("//li[contains(text(),'17:30')]")).click();
Thread.sleep(2000);
System.out.println("June/10/2022 5:30 PM Date & time is selected");
w.navigate().back();
Thread.sleep(2000);
// for Slider
jes.executeScript("window.scrollBy(0,300)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Slider')]")).click();
System.out.println("Slider WebPage is open");
Thread.sleep(2000);
WebElement slider=w.findElement(By.xpath("//*[@id=\"sliderContainer\"]/div[1]/span/input"));
Actions act= new Actions(w);
act.dragAndDropBy(slider,-150, 100).perform(); //move to backward
Thread.sleep(2000);
act.dragAndDropBy(slider, 200, 100).perform(); // move to forward
Thread.sleep(2000);
TakesScreenshot t = (TakesScreenshot) w;
File src= t.getScreenshotAs(OutputType.FILE);
Files.copy(src, new File ("E:\\Testing Class\\1.jpg"));
w.navigate().back();
Thread.sleep(2000);
// for Progress Bar
jes.executeScript("window.scrollBy(0,500)");
w.findElement(By.xpath("//span[contains(text(),'Progress Bar')]")).click();
System.out.println("Progress Bar WebPage is open");
Thread.sleep(2000);
w.findElement(By.xpath("//*[@id=\"startStopButton\"]")).click();
Thread.sleep(4000);
// w.findElement(By.xpath("//div[contains(text(),'100%')]")).click();
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/button[1]")).click();
Thread.sleep(2000);
w.navigate().back();
Thread.sleep(2000);
// for Tabs
jes.executeScript("window.scrollBy(0,500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Tabs')]")).click();
System.out.println("Tabs WebPage is open");
Thread.sleep(2000);
w.findElement(By.id("demo-tab-origin")).click();
Thread.sleep(2000);
w.findElement(By.id("demo-tab-what")).click();
Thread.sleep(2000);
w.findElement(By.linkText("Use")).click();
Thread.sleep(2000);
// w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/nav[1]/a[4]")).click();
boolean eleEnabled= w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/nav[1]/a[4]")).isEnabled();
System.out.println(eleEnabled);
Thread.sleep(2000);
w.navigate().back();
Thread.sleep(2000);
// for Tool Tips
jes.executeScript("window.scrollBy(0,500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Tool Tips')]")).click();
System.out.println("Tool Tips WebPage is open");
Thread.sleep(2000);
Actions A1 = new Actions(w);
A1.moveToElement(w.findElement(By.xpath("//button[@id='toolTipButton']"))).perform();
Thread.sleep(2000);
WebElement text=w.findElement(By.xpath("//input[@id='toolTipTextField']"));
Actions A2 = new Actions(w);
A2.moveToElement(text).click().keyDown(Keys.SHIFT).sendKeys("Hello").build().perform();
Actions A3 = new Actions(w);
A3.moveToElement(w.findElement(By.xpath("//a[contains(text(),'Contrary')]"))).perform();
Thread.sleep(2000);
jes.executeScript("window.scrollBy(0,300)");
Actions A4 = new Actions(w);
A4.moveToElement(w.findElement(By.xpath("//a[contains(text(),'1.10.32')]"))).perform();
Thread.sleep(2000);
w.navigate().back();
Thread.sleep(2000);
// for Menu
jes.executeScript("window.scrollBy(0,600)");
Thread.sleep(2000);
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/ul[1]/li[8]/span[1]")).click();
System.out.println("Menu WebPage is open");
Thread.sleep(2000);
w.findElement(By.linkText("Main Item 1")).click();
Thread.sleep(2000);
Actions A5 = new Actions(w);
A5.moveToElement(w.findElement(By.xpath("//a[contains(text(),'Main Item 2')]"))).perform();
w.findElement(By.linkText("Sub Item")).click();
Thread.sleep(3000);
Actions A6 = new Actions(w);
A6.moveToElement(w.findElement(By.xpath("//a[contains(text(),'Main Item 2')]"))).perform();
A6.moveToElement(w.findElement(By.xpath("//a[contains(text(),'SUB SUB LIST »')]"))).perform();
w.findElement(By.xpath("//a[contains(text(),'Sub Sub Item 2')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//a[contains(text(),'Main Item 3')]")).click();
w.navigate().back();
w.navigate().back();
Thread.sleep(2000);
// for Select Menu
jes.executeScript("window.scrollBy(0,900)");
Thread.sleep(2000);
w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/ul[1]/li[9]/span[1]")).click();
System.out.println("Select Menu WebPage is open");
Thread.sleep(2000);
//select Value
w.findElement(By.xpath("//*[@id=\"withOptGroup\"]/div/div[1]/div[1]")).click();
w.findElement(By.xpath("//div[contains(text(),'Group 2, option 1')]")).click();
Thread.sleep(2000);
//Select one
w.findElement(By.xpath("//*[@id=\"selectOne\"]/div/div[1]")).click();
w.findElement(By.xpath("//div[contains(text(),'Ms.')]")).click();
Thread.sleep(2000);
// Old Style Select Menu
Select s3= new Select(w.findElement(By.xpath("//select[@id='oldSelectMenu']")));
s3.selectByValue("4");
Thread.sleep(2000);
// multiselect Drop down
jes.executeScript("window.scrollBy(0, 400)", "");
w.findElement(By.xpath("//*[@id=\"selectMenuContainer\"]/div[7]/div/div/div/div[1]")).click();
w.findElement(By.xpath("//div[contains(text(),'Blue')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//div[contains(text(),'Black')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//div[contains(text(),'Green')]")).click();
Thread.sleep(2000);
w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[7]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[2]/*[1]")).click();
Thread.sleep(2000);
// Standard multi select
Select s4= new Select(w.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[8]/div[1]/select[1]")));
s4.selectByVisibleText("Volvo");
s4.selectByValue("audi");
Thread.sleep(2000);
System.out.println(w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[1]/div")).getText());
w.navigate().back();
w.navigate().back();
w.get("https://demoqa.com/");
Thread.sleep(3000);
//-------------------------------------------- Module 5 : Intraction----------------------------------------------
JavascriptExecutor jss11 = (JavascriptExecutor) w;
jss11.executeScript("window.scrollBy(0,1500)");
w.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div/div[5]/div/div[3]/h5")).click();
Thread.sleep(3000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]")).getText());
//sortable
JavascriptExecutor jss1 = (JavascriptExecutor) w;
jss1.executeScript("window.scrollBy(0,1500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Sortable')]")).click();
Thread.sleep(3000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
//list
WebElement dr = w.findElement(By.xpath("//*[@id=\"demo-tabpane-list\"]/div/div[1]"));
WebElement dp = w.findElement(By.xpath("//*[@id=\"demo-tabpane-list\"]/div/div[4]"));
Actions A = new Actions (w);
A.dragAndDrop(dr,dp).build().perform();
Thread.sleep(3000);
System.out.println("Sortable List");
//grid
w.findElement(By.linkText("Grid")).click();
Thread.sleep(3000);
WebElement dr1 = w.findElement(By.xpath("//*[@id=\"demo-tabpane-grid\"]/div/div/div[2]"));
WebElement dp1 = w.findElement(By.xpath("//*[@id=\"demo-tabpane-grid\"]/div/div/div[8]"));
Actions A10 = new Actions (w);
A10.dragAndDrop(dr1,dp1).build().perform();
Thread.sleep(3000);
System.out.println("Sortable Gird");
//selectable
JavascriptExecutor jss2 = (JavascriptExecutor) w;
jss2.executeScript("window.scrollBy(0,1500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Selectable')]")).click();
Thread.sleep(3000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
//list
w.findElement(By.xpath("//li[contains(text(),'Dapibus ac facilisis in')]")).click();
w.findElement(By.xpath("//li[contains(text(),'Porta ac consectetur ac')]")).click();
Thread.sleep(3000);
System.out.println("Selectable List");
//grid
w.findElement(By.linkText("Grid")).click();
w.findElement(By.xpath("//li[contains(text(),'Five')]")).click();
w.findElement(By.xpath("//li[contains(text(),'Three')]")).click();
w.findElement(By.xpath("//li[contains(text(),'Seven')]")).click();
Thread.sleep(3000);
System.out.println("Selectable Grid");
//resizable
JavascriptExecutor jss3 = (JavascriptExecutor) w;
jss3.executeScript("window.scrollBy(0,1500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Resizable')]")).click();
Thread.sleep(3000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
WebElement re = w.findElement(By.xpath("//*[@id=\"resizableBoxWithRestriction\"]/span"));
WebElement re1 = w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[1]/span[1]"));
Actions resize = new Actions(w);
//provide x and y offset
resize.dragAndDropBy(re, 150, 180).build().perform();
Thread.sleep(3000);
JavascriptExecutor jss4 = (JavascriptExecutor)w;
jss4.executeScript("window.scrollTo(0,document.body.scrollHeight)");
Thread.sleep(3000);
resize.dragAndDropBy(re1, 200, 40).build().perform();
Thread.sleep(3000);
//droppable
JavascriptExecutor jss5 = (JavascriptExecutor) w;
jss5.executeScript("window.scrollBy(0,1500)");
Thread.sleep(2000);
w.findElement(By.xpath("//span[contains(text(),'Droppable')]")).click();
Thread.sleep(3000);
System.out.println(w.findElement(By.xpath("//body/div[@id='app']/div[1]/div[1]/div[1]")).getText());
//simple
WebElement dr2 = w.findElement(By.id("draggable"));
WebElement dp2 = w.findElement(By.id("droppable"));
Actions A13 = new Actions(w);
A13.dragAndDrop(dr2, dp2).build().perform();
Thread.sleep(3000);
System.out.println("Droppable Simple");
//accept
w.findElement(By.linkText("Accept")).click();
Thread.sleep(3000);
WebElement dr3 = w.findElement(By.id("acceptable"));
WebElement dp3 = w.findElement(By.xpath("//div[@id='acceptDropContainer']//div[@id='droppable']"));
Actions A14 = new Actions(w);
A14.dragAndDrop(dr3, dp3).build().perform();
Thread.sleep(3000);
WebElement dr4 = w.findElement(By.id("notAcceptable"));