SynchronisationService extends BaseServiceHub { public void switchToMainWindow() { if (mainWindowHandle.get() != null) getWebDriver().switchTo().window(mainWindowHandle.get()); }  boolean waitForExpectedCondition(ExpectedCondition<?> condition, int timeout); boolean waitForExpectedCondition(ExpectedCondition<?> condition); void waitAndAssertForExpectedCondition(ExpectedCondition<?> condition, int timeout); void waitAndAssertForExpectedCondition(ExpectedCondition<?> condition); boolean checkForExpectedCondition(ExpectedCondition<?> condition); void checkAndAssertForExpectedCondition(ExpectedCondition<?> condition); void waitAndSwitchToNewBrowserWindow(int timeout); void waitAndSwitchToNewBrowserWindow(); void switchToMainWindow(); void switchToLatestPopupWindow();  }
@Test public void testSwitchToMainWindow() throws Exception { seleniumNavigationService.navigate_to_url(TEST_PAGE_URL); seleniumSynchronisationService.checkAndAssertForExpectedCondition(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[id='textField']"))); driver.findElement(By.cssSelector("input[id='textField']")).sendKeys("file: seleniumElementService.findExpectedElement(By.cssSelector("button[id='openBrowserWindow']")).click(); seleniumSynchronisationService.waitAndSwitchToNewBrowserWindow(seleniumManager.getTimeout()); assertEquals(1, driver.findElements(By.xpath(" seleniumSynchronisationService.switchToMainWindow(); assertEquals(1, driver.findElements(By.cssSelector("input[id='textField']")).size()); seleniumSynchronisationService.switchToLatestPopupWindow(); assertEquals(1, driver.findElements(By.xpath(" driver.close(); seleniumSynchronisationService.switchToMainWindow(); }