File tree 5 files changed +100
-0
lines changed
5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ public DynamicLoadingPage clickDynamicLoading(){
61
61
return new DynamicLoadingPage (driver );
62
62
}
63
63
64
+ public MultipleWindowsPage clickMultipleWindows (){
65
+ clickLink ("Multiple Windows" );
66
+ return new MultipleWindowsPage (driver );
67
+ }
68
+
64
69
private void clickLink (String linkText ){
65
70
driver .findElement (By .linkText (linkText )).click ();
66
71
}
Original file line number Diff line number Diff line change
1
+ package pages ;
2
+
3
+ import org .openqa .selenium .By ;
4
+ import org .openqa .selenium .WebDriver ;
5
+
6
+ public class MultipleWindowsPage {
7
+
8
+ private WebDriver driver ;
9
+ private By clickHereLink = By .linkText ("Click Here" );
10
+
11
+ public MultipleWindowsPage (WebDriver driver ){
12
+ this .driver = driver ;
13
+ }
14
+
15
+ public void clickHere (){
16
+ driver .findElement (clickHereLink ).click ();
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ package utils ;
2
+
3
+ import org .openqa .selenium .WebDriver ;
4
+
5
+ public class WindowManager {
6
+
7
+ private WebDriver driver ;
8
+ private WebDriver .Navigation navigate ;
9
+
10
+ public WindowManager (WebDriver driver ){
11
+ this .driver = driver ;
12
+ navigate = driver .navigate ();
13
+ }
14
+
15
+ public void goBack (){
16
+ navigate .back ();
17
+ }
18
+
19
+ public void goForward (){
20
+ navigate .forward ();
21
+ }
22
+
23
+ public void refreshPage (){
24
+ navigate .refresh ();
25
+ }
26
+
27
+ public void goTo (String url ){
28
+ navigate .to (url );
29
+ }
30
+
31
+ public void switchToTab (String tabTitle ){
32
+ var windows = driver .getWindowHandles ();
33
+
34
+ System .out .println ("Number of tabs: " + windows .size ());
35
+
36
+ System .out .println ("Window handles:" );
37
+ windows .forEach (System .out ::println );
38
+
39
+ for (String window : windows ){
40
+ System .out .println ("Switching to window: " + window );
41
+ driver .switchTo ().window (window );
42
+
43
+ System .out .println ("Current window title: " + driver .getTitle ());
44
+
45
+ if (tabTitle .equals (driver .getTitle ())){
46
+ break ;
47
+ }
48
+ }
49
+ }
50
+ }
Original file line number Diff line number Diff line change 6
6
import org .testng .annotations .BeforeClass ;
7
7
import org .testng .annotations .BeforeMethod ;
8
8
import pages .HomePage ;
9
+ import utils .WindowManager ;
9
10
10
11
public class BaseTests {
11
12
@@ -29,4 +30,8 @@ public void goHome(){
29
30
public void tearDown (){
30
31
driver .quit ();
31
32
}
33
+
34
+ public WindowManager getWindowManager (){
35
+ return new WindowManager (driver );
36
+ }
32
37
}
Original file line number Diff line number Diff line change
1
+ package navigation ;
2
+
3
+ import base .BaseTests ;
4
+ import org .testng .annotations .Test ;
5
+
6
+ public class NavigationTests extends BaseTests {
7
+
8
+ @ Test
9
+ public void testNavigator (){
10
+ homePage .clickDynamicLoading ().clickExample1 ();
11
+ getWindowManager ().goBack ();
12
+ getWindowManager ().refreshPage ();
13
+ getWindowManager ().goForward ();
14
+ getWindowManager ().goTo ("https://google.com" );
15
+ }
16
+
17
+ @ Test
18
+ public void testSwitchTab (){
19
+ homePage .clickMultipleWindows ().clickHere ();
20
+ getWindowManager ().switchToTab ("New Window" );
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments