for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
Can we rewrite this using Lambda Expression?
I would go for
driver.getWindowHandles().forEach(windowHandle -> {
driver.switchTo().window(windowHandle);
});
which is equivalent to:
for(String windowHandle : driver.getWindowHandles()) {
driver.switchTo().window(windowHandle);
}
forEach method calls can be used for Collections.
You can go parallel with the usage of forEach together with parallelStream. Read further.
driver.switchTo()again in every loop iteration? If not, you can simply usedriver.getWindowHandles().forEach(driver.switchTo()::window)