[java] Fixing WindowSwitchingTest local rule broken by the recently extracted global one
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
import static org.openqa.selenium.testing.TestUtilities.isInternetExplorer;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
public class WindowSwitchingTest extends JUnit4TestBase {
- @Rule
- public final TestRule switchToMainWindow = new TestWatcher() {
private String mainWindow;
- @Override
- protected void starting(Description description) {
- super.starting(description);
+ @Before
+ public void storeMainWindowHandle() {
mainWindow = driver.getWindowHandle();
}
- @Override
- protected void finished(Description description) {
+ @After
+ public void closeAllWindowsExceptForTheMainOne() {
try {
driver.getWindowHandles().stream().filter(handle -> ! mainWindow.equals(handle))
.forEach(handle -> driver.switchTo().window(handle).close());
@@ -74,10 +74,9 @@ protected void finished(Description description) {
try {
driver.switchTo().window(mainWindow);
} catch (Exception ignore) {
+ System.err.println("Ignoring: " + ignore.getMessage());
}
- super.finished(description);
}
- };
@SwitchToTopAfterTest
@NoDriverAfterTest(failedOnly = true)
