Create Utils and Pass driver instance and windowTitle.
public static void moveToNewWindows(WebDriver driver, String windowTitle) {
boolean windowExists = false;
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) {
windowExists = true;
logger.info(windowTitle
+ " Title window exists, Switched to new window");
break;
}
}
if (!windowExists) {
Assert.fail(windowTitle + " Title window not exists");
}
}