Java 类org.openqa.selenium.NoSuchWindowException 实例源码

项目:domui    文件:WebDriverConnector.java   
/**
 * Wait for the window handle to disappear.
 * @throws Exception
 */
public void waitForHandleNotPresent() throws Exception {
    try {
        timed(getWaitTimeout(), getWaitInterval(), new Action<Boolean>() {
            @Override
            @Nullable
            public Boolean execute() throws Exception {
                if(!driver().getWindowHandles().contains(driver().getWindowHandle())) {
                    return null;
                }
                return Boolean.FALSE;
            }
        });
    } catch(NoSuchWindowException e) {
        //Already gone, fine!
    }
}
项目:kc-rice    文件:WebDriverAftBase.java   
protected void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(isPassed())) {
            try {
                acceptAlertIfPresent();
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString() + " if using a remote hub did you include the port?");
    }
}
项目:kc-rice    文件:JiraIssueCreation.java   
private void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(passed)) {
            try {
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString());
    }
}
项目:kc-rice    文件:JenkinsJsonJobResultsBase.java   
protected void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(passed)) {
            try {
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString());
    }
}
项目:automation-test-engine    文件:CaseRunner.java   
/**
 * Tear down.
 */
@AfterMethod(alwaysRun = true)
public void tearDown() {
    try {
        if (null != mainDriver) {
            mainDriver.quit();
        }
        if (null != context) {

            Map<String, IMyWebDriver> myWebDrivers = context
                    .getBeansOfType(IMyWebDriver.class);
            for (IMyWebDriver myWebDriver2 : myWebDrivers.values()) {
                WebDriver weD = myWebDriver2.getWebDriver();
                if (null != weD)
                    weD.quit();
            }
        }
    } catch (UnreachableBrowserException | NoSuchWindowException e) { // NOPMD
        // browser has been closed, no action needs to be done here.
    }
    if (null != context) {
        ((ConfigurableApplicationContext) context).close();
    }

}
项目:automation-test-engine    文件:MultiWindowsHandler.java   
private void checkCloseWindowAlert(String winh)
        throws NoAlertPresentException {
    try {
        Alert alt = getDriver().switchTo().alert();
        if (alt == null)
            throw GlobalUtils.createInternalError("web driver");
        PopupPromptDialog aDialog = new PopupPromptDialog(getDriver(), alt,
                alerts.size());
        aDialog.setClosingWindowHandle(winh);
        alerts.add(aDialog);
    } catch (UnreachableBrowserException error) {
        if (getNumberOfOpenWindows() > 0)
            throw GlobalUtils
                    .createInternalError("ATE multi windows handler", error);
    } catch (UnsupportedOperationException e) {

            throw GlobalUtils
                    .createInternalError("Driver doesn't support alert handling yet", e);
    } catch (NoSuchWindowException windClosedAlready) {
        //do nothing if window closed without alert dialog intervention. for example in Chrome.
        throw new NoAlertPresentException(windClosedAlready);
    }
}
项目:rice    文件:WebDriverAftBase.java   
protected void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(isPassed())) {
            try {
                acceptAlertIfPresent();
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString() + " if using a remote hub did you include the port?");
    }
}
项目:rice    文件:JiraIssueCreation.java   
private void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(passed)) {
            try {
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString());
    }
}
项目:rice    文件:JenkinsJsonJobResultsBase.java   
protected void closeAndQuitWebDriver() {
    if (driver != null) {
        if (WebDriverUtils.dontTearDownPropertyNotSet() && WebDriverUtils.dontTearDownOnFailure(passed)) {
            try {
                driver.close();
            } catch (NoSuchWindowException nswe) {
                System.out.println("NoSuchWindowException closing WebDriver " + nswe.getMessage());
            } finally {
                if (driver != null) {
                    driver.quit();
                }
            }
        }
    } else {
        System.out.println("WebDriver is null for " + this.getClass().toString());
    }
}
项目:darcy-webdriver    文件:TakeScreenshotTest.java   
@SuppressWarnings("unchecked")
@Test
public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws IOException {
    TargetedWebDriver driver = mock(TargetedWebDriver.class);
    OutputStream outputStream = mock(OutputStream.class);
    Browser browser = new WebDriverBrowser(driver,
            new StubWebDriverParentContext(),
            new StubWebDriverElementContext());

    when(driver.getScreenshotAs(OutputType.BYTES))
            .thenThrow(NoSuchWindowException.class);
    try {
        browser.takeScreenshot(outputStream);
        fail("Expected FindableNotPresentException to be thrown");
    } catch (Exception e) {
        assertThat("Expected FindableNotPresentException to be thrown",
                e.getClass(), equalTo(FindableNotPresentException.class));
    }

    verify(outputStream).close();
}
项目:robotframework-seleniumlibrary-java    文件:WindowManager.java   
protected static void selectMatching(WebDriver webDriver, Matcher matcher, String error) {
    String startingHandle = null;
    try {
        startingHandle = webDriver.getWindowHandle();
    } catch (NoSuchWindowException e) {
        // Window of current WebDriver instance is already closed
    }

    for (String handle : webDriver.getWindowHandles()) {
        webDriver.switchTo().window(handle);
        if (matcher.match(getCurrentWindowInfo(webDriver))) {
            return;
        }
    }

    if (startingHandle != null) {
        webDriver.switchTo().window(startingHandle);
    }
    throw new SeleniumLibraryNonFatalException(error);
}
项目:robotframework-seleniumlibrary-java    文件:WindowManager.java   
public static List<List<String>> getWindowInfos(WebDriver webDriver) {
    String startingHandle = null;
    try {
        startingHandle = webDriver.getWindowHandle();
    } catch (NoSuchWindowException e) {
        // Window of current WebDriver instance is already closed
    }

    List<List<String>> windowInfos = new ArrayList<List<String>>();
    try {
        for (String handle : webDriver.getWindowHandles()) {
            webDriver.switchTo().window(handle);
            windowInfos.add(getCurrentWindowInfo(webDriver));
        }
    } finally {
        if (startingHandle != null) {
            webDriver.switchTo().window(startingHandle);
        }
    }
    return windowInfos;
}
项目:robotframework-selenium2library-java    文件:WindowManager.java   
protected static void selectMatching(WebDriver webDriver, Matcher matcher, String error) {
    String startingHandle = null;
    try {
        startingHandle = webDriver.getWindowHandle();
    } catch (NoSuchWindowException e) {
        // Window of current WebDriver instance is already closed
    }

    for (String handle : webDriver.getWindowHandles()) {
        webDriver.switchTo().window(handle);
        if (matcher.match(getCurrentWindowInfo(webDriver))) {
            return;
        }
    }

    if (startingHandle != null) {
        webDriver.switchTo().window(startingHandle);
    }
    throw new Selenium2LibraryNonFatalException(error);
}
项目:robotframework-selenium2library-java    文件:WindowManager.java   
public static List<List<String>> getWindowInfos(WebDriver webDriver) {
    String startingHandle = null;
    try {
        startingHandle = webDriver.getWindowHandle();
    } catch (NoSuchWindowException e) {
        // Window of current WebDriver instance is already closed
    }

    List<List<String>> windowInfos = new ArrayList<List<String>>();
    try {
        for (String handle : webDriver.getWindowHandles()) {
            webDriver.switchTo().window(handle);
            windowInfos.add(getCurrentWindowInfo(webDriver));
        }
    } finally {
        if (startingHandle != null) {
            webDriver.switchTo().window(startingHandle);
        }
    }
    return windowInfos;
}
项目:marathonv5    文件:JavaDriverTest.java   
public void windowThrowsExceptionWhenNotExisting() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setVisible(true);
        }
    });
    try {
        driver.switchTo().window("My Dialog1");
        throw new MissingException(NoSuchWindowException.class);
    } catch (NoSuchWindowException e) {
    }
}
项目:webtester2-core    文件:FocusSetterTest.java   
@Test
void switchingToWindowByUnknownNameOrHandleThrowsException() {
    NoSuchWindowException exception = mock(NoSuchWindowException.class);
    when(webDriver.switchTo().window("fooBar")).thenThrow(exception);
    assertThrows(NoSuchWindowException.class, () -> {
        cut.onWindow("fooBar");
    });
    verify(events).fireExceptionEvent(exception);
    verifyNoMoreInteractions(events);
}
项目:webtester-core    文件:WebDriverBrowserTest.java   
@Test(expected = NoSuchWindowException.class)
public void testExceptionHandlingInCaseAWindowIsNotFoundForTheGivenNameOrHandle() {

    TargetLocator locator = mockTargetLocator();
    NoSuchWindowException exception = createSeleniumExceptionOfClass(NoSuchWindowException.class);
    doThrow(exception).when(locator).window(NAME_OR_HANDLE);

    try {
        cut.setFocusOnWindow(NAME_OR_HANDLE);
    } finally {
        verifyLastEventFiredWasExceptionEventOf(exception);
    }

}
项目:hsac-fitnesse-fixtures    文件:SeleniumHelper.java   
public int getCurrentTabIndex(List<String> tabHandles) {
    try {
        String currentHandle = driver().getWindowHandle();
        return tabHandles.indexOf(currentHandle);
    } catch (NoSuchWindowException e) {
        return -1;
    }
}
项目:cinnamon    文件:SwitchToWindowImpl.java   
private WebDriver nth(final int zeroBasedIndex) {
    try {
        final List<String> windowHandles = webDriver.getWindowHandles().stream().collect(Collectors.toList());
        return webDriver.switchTo().window(windowHandles.get(zeroBasedIndex));
    } catch (IndexOutOfBoundsException e) {
        throw new NoSuchWindowException(e.getMessage(), e);
    }
}
项目:cinnamon    文件:SwitchToWindowImpl.java   
@Override
public WebDriver byTitle(final String title) {
    try {
        final FluentWait<WebDriver> wait = new WebDriverWait(webDriver, defaultTimeout().getSeconds());
        return wait.until(windowToBeAvailableAndSwitchToIt(title));
    } catch (TimeoutException e) {
        throw new NoSuchWindowException(String.format("Cannot find the window with title %s.", title));
    }
}
项目:cinnamon    文件:SwitchToWindowImpl.java   
@Override
public WebDriver byPartialTitle(final String partialTitle) {
    try {
        final FluentWait<WebDriver> wait = new WebDriverWait(webDriver, defaultTimeout().getSeconds());
        return wait.until(windowToBeAvailableAndSwitchToIt(partialTitle, true));
    } catch (TimeoutException e) {
        throw new NoSuchWindowException(String.format("Cannot find the window with partial title %s.", partialTitle));
    }
}
项目:automation-test-engine    文件:AbstractLockProtectedMultiWindowsHandler.java   
private void removeClosedWindows() {

        boolean winRemoved = false;// NOPMD
        String currentWinHandle = "";
        try {
            currentWinHandle = this.getDriver().getWindowHandle();
        } catch (NoSuchWindowException noWinEx) {
            winRemoved = true;
        }
//      for (int i = 0; i < windows.size(); i++) {
//          if (windows.get(i).isClosed()) {
//              windows.remove(i);
//              winRemoved = true;// NOPMD
//          }
//      }
        for (Iterator<BrowserWindow> winItr=windows.iterator(); winItr.hasNext();) {
            BrowserWindow bw = winItr.next();
            if (bw.isClosed()) {
                winItr.remove();
                winRemoved = true;
            } else {
                try {
                    this.getDriver().switchTo().window(bw.getWindowHandle());
                } catch (NoSuchWindowException noWinE) {
                    winItr.remove();
                    winRemoved = true;
                }
            }
        }
        if (winRemoved) {
            this.getDriver().switchTo()
                    .window(windows.get(windows.size() - 1).getWindowHandle());
        } else {
            this.getDriver().switchTo().window(currentWinHandle);
        }
    }
项目:automation-test-engine    文件:BrowserWindow.java   
/**
 * Close.
 */
public void close() {
    try {
        obtainWindowFocus();
        myWd.getWebDriverInstance().close();
        this.setClosed(true);
    } catch (NoSuchWindowException noWinE) {
        this.setClosed(true);
    }
}
项目:darcy-webdriver    文件:WebDriverTargets.java   
private String findWindow(TargetLocator targetLocator) {
    for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
        Browser forWindowHandle = By.id(windowHandle).find(Browser.class, parentContext);

        view.setContext(forWindowHandle);

        if (view.isLoaded()) {
            return windowHandle;
        }
    }

    throw new NoSuchWindowException("No window in driver found which has " + view + " "
            + "currently loaded.");
}
项目:darcy-webdriver    文件:WebDriverTargets.java   
private String findWindow(TargetLocator targetLocator) {
    for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
        if (targetLocator.window(windowHandle).getTitle().equals(title)) {
            return windowHandle;
        }
    }

    throw new NoSuchWindowException("No window in driver found which has title: " + title);
}
项目:darcy-webdriver    文件:WebDriverTargets.java   
private String findWindow(TargetLocator targetLocator) {
    for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
        if (urlMatcher.matches(targetLocator.window(windowHandle).getCurrentUrl())) {
            return windowHandle;
        }
    }

    throw new NoSuchWindowException("No window in driver found which has url matching: " + urlMatcher);
}
项目:darcy-webdriver    文件:WebDriverBrowser.java   
/**
 * Wrapper for interacting with a targeted driver that may or may not actually be present.
 */
private void attempt(Runnable action) {
    try {
        action.run();
    } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) {
        throw new FindableNotPresentException(this, e);
    }
}
项目:darcy-webdriver    文件:WebDriverBrowser.java   
/**
 * Wrapper for interacting with a targeted driver that may or may not actually be present.
 * Returns a result.
 */
private <T> T attemptAndGet(Supplier<T> action) {
    try {
        return action.get();
    } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) {
        throw new FindableNotPresentException(this, e);
    }
}
项目:darcy-webdriver    文件:ViewWebDriverTargetTest.java   
@Test(expected = NoSuchWindowException.class)
public void shouldThrowNoSuchWindowExceptionIfViewIsNotLoadedInAnyWindow() {
    View view = new NeverLoadedView();

    WebDriverTarget target = WebDriverTargets.withViewLoaded(view, context);

    target.switchTo(locator);
}
项目:carina    文件:DriverHelper.java   
public void switchWindow() throws NoSuchWindowException {
    WebDriver drv = getDriver();
    Set<String> handles = drv.getWindowHandles();
    String current = drv.getWindowHandle();
    if (handles.size() > 1) {
        handles.remove(current);
    }
    String newTab = handles.iterator().next();
    drv.switchTo().window(newTab);
}
项目:SilkAppDriver    文件:MultiWindowTests.java   
@Test(expected = NoSuchWindowException.class)
public void testSwitchToInvalidWindow() {
    assertEquals(1, driver.getWindowHandles().size());

    driver.switchTo().window("42");
}
项目:darcy-webdriver    文件:WindowUrlWebDriverTargetTest.java   
@Test(expected = NoSuchWindowException.class)
public void shouldThrowNoSuchWindowExceptionIfNoWindowsCanBeFoundMatchingTheUrlMatcher() {
    WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("awesome window"));

    target.switchTo(locator);
}
项目:darcy-webdriver    文件:WindowTitleWebDriverTargetTest.java   
@Test(expected = NoSuchWindowException.class)
public void shouldThrowNoSuchWindowExceptionIfNoWindowsCanBeFoundWithTitle() {
    WebDriverTarget target = WebDriverTargets.windowByTitle("awesome window");

    target.switchTo(locator);
}
项目:selendroid    文件:MultipleWebviewHandlingTests.java   
@Test(expected = NoSuchWindowException.class)
public void shouldThrowExceptionIfContextNotFound() {
  openMultipleWebViewActivity();
  SelendroidDriver driver = driver();
  driver.context("BANANA");
}
项目:webtester2-core    文件:FocusSetter.java   
/**
 * Sets the browser's focus to the window with the given name or handle.
 * <p>
 * <b>Tip:</b> A handle for the current window can be got by using the {@link CurrentWindow#getHandle()} method.
 *
 * @param nameOrHandle the name or handle of the window to focus on
 * @throws NoSuchWindowException in case there is no window with the given name or handle
 * @see Browser#currentWindow()
 * @see CurrentWindow#getHandle()
 * @see WebDriver.TargetLocator#window(String)
 * @since 2.0
 */
public void onWindow(String nameOrHandle) throws NoSuchWindowException {
    ActionTemplate.browser(browser())
        .execute(browser -> doOnWindow(browser, nameOrHandle))
        .fireEvent(browser -> new SwitchedToWindowEvent(nameOrHandle));
    log.debug("focused on window with name or handle: {}", nameOrHandle);
}