Skip to content

Instantly share code, notes, and snippets.

@ultimate-qa2
Created February 28, 2021 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultimate-qa2/cd47ba19533aa67852ae35da3399653f to your computer and use it in GitHub Desktop.
Save ultimate-qa2/cd47ba19533aa67852ae35da3399653f to your computer and use it in GitHub Desktop.
@Test
public void windowFrames() {
driver.navigate().to("https://the-internet.herokuapp.com/windows");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(("window.open('https://the-internet.herokuapp.com/windows/new')"));
String originalWindow = driver.getWindowHandle();
Set handles = driver.getWindowHandles();
handles.remove(originalWindow);
String nextWindow = String.valueOf(handles.iterator().next());
driver.switchTo().window(nextWindow);
Assert.assertEquals("New Window", driver.getTitle());
driver.close();
driver.switchTo().window(originalWindow);
Assert.assertEquals("The Internet", driver.getTitle());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment