本文整理汇总了Java中org.openqa.selenium.NoSuchWindowException类的典型用法代码示例。如果您正苦于以下问题:Java NoSuchWindowException类的具体用法?Java NoSuchWindowException怎么用?Java NoSuchWindowException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoSuchWindowException类属于org.openqa.selenium包,在下文中一共展示了NoSuchWindowException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForHandleNotPresent
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
/**
* 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!
}
}
示例2: closeAndQuitWebDriver
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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?");
}
}
示例3: closeAndQuitWebDriver
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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());
}
}
示例4: closeAndQuitWebDriver
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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());
}
}
示例5: tearDown
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
/**
* 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();
}
}
示例6: checkCloseWindowAlert
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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);
}
}
示例7: shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
@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();
}
示例8: selectMatching
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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);
}
示例9: getWindowInfos
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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;
}
示例10: selectMatching
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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);
}
示例11: windowThrowsExceptionWhenNotExisting
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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) {
}
}
示例12: switchingToWindowByUnknownNameOrHandleThrowsException
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
@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);
}
示例13: testExceptionHandlingInCaseAWindowIsNotFoundForTheGivenNameOrHandle
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
@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);
}
}
示例14: getCurrentTabIndex
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
public int getCurrentTabIndex(List<String> tabHandles) {
try {
String currentHandle = driver().getWindowHandle();
return tabHandles.indexOf(currentHandle);
} catch (NoSuchWindowException e) {
return -1;
}
}
示例15: nth
import org.openqa.selenium.NoSuchWindowException; //导入依赖的package包/类
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);
}
}