-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da81cc4
commit 051e946
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
webdriver_java/src/main/java/pages/MultipleWindowsPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pages; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
public class MultipleWindowsPage { | ||
|
||
private WebDriver driver; | ||
private By clickHereLink = By.linkText("Click Here"); | ||
|
||
public MultipleWindowsPage(WebDriver driver){ | ||
this.driver = driver; | ||
} | ||
|
||
public void clickHere(){ | ||
driver.findElement(clickHereLink).click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package utils; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
|
||
public class WindowManager { | ||
|
||
private WebDriver driver; | ||
private WebDriver.Navigation navigate; | ||
|
||
public WindowManager(WebDriver driver){ | ||
this.driver = driver; | ||
navigate = driver.navigate(); | ||
} | ||
|
||
public void goBack(){ | ||
navigate.back(); | ||
} | ||
|
||
public void goForward(){ | ||
navigate.forward(); | ||
} | ||
|
||
public void refreshPage(){ | ||
navigate.refresh(); | ||
} | ||
|
||
public void goTo(String url){ | ||
navigate.to(url); | ||
} | ||
|
||
public void switchToTab(String tabTitle){ | ||
var windows = driver.getWindowHandles(); | ||
|
||
System.out.println("Number of tabs: " + windows.size()); | ||
|
||
System.out.println("Window handles:"); | ||
windows.forEach(System.out::println); | ||
|
||
for(String window : windows){ | ||
System.out.println("Switching to window: " + window); | ||
driver.switchTo().window(window); | ||
|
||
System.out.println("Current window title: " + driver.getTitle()); | ||
|
||
if(tabTitle.equals(driver.getTitle())){ | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
webdriver_java/src/test/java/navigation/NavigationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package navigation; | ||
|
||
import base.BaseTests; | ||
import org.testng.annotations.Test; | ||
|
||
public class NavigationTests extends BaseTests { | ||
|
||
@Test | ||
public void testNavigator(){ | ||
homePage.clickDynamicLoading().clickExample1(); | ||
getWindowManager().goBack(); | ||
getWindowManager().refreshPage(); | ||
getWindowManager().goForward(); | ||
getWindowManager().goTo("https://google.com"); | ||
} | ||
|
||
@Test | ||
public void testSwitchTab(){ | ||
homePage.clickMultipleWindows().clickHere(); | ||
getWindowManager().switchToTab("New Window"); | ||
} | ||
} |