List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:com.seleniumtests.ut.driver.TestCustomEventFiringWebDriver.java
License:Apache License
/** * Check that even if error is raised when driver is quit, killing process is done *//*from w ww. j a v a2s. co m*/ @Test(groups = { "ut" }) public void testQuitInError() { when(browserInfo.getAllBrowserSubprocessPids(new ArrayList<>())).thenReturn(Arrays.asList(1000L)); doThrow(new WebDriverException("some error")).when(driver).quit(); try { ((CustomEventFiringWebDriver) eventDriver).quit(); } catch (WebDriverException e) { } verify(osUtility).killProcess(eq("1000"), eq(true)); }
From source file:com.seleniumtests.ut.reporter.TestSeleniumTestsReporter.java
License:Apache License
@Test(groups = { "ut" }) public void testChangeTestResultWithOneKo() { Throwable ex = new WebDriverException("test exception"); SeleniumTestsContextManager.getThreadContext().addVerificationFailures(Reporter.getCurrentTestResult(), ex); init();/*w w w .jav a2 s .co m*/ SeleniumRobotTestListener listener = new SeleniumRobotTestListener(); listener.changeTestResult(testResult); // check setStatus has not been called as no verification failure has been provided Mockito.verify(testResult).setStatus(2); Mockito.verify(testResult).setThrowable(ex); }
From source file:com.seleniumtests.ut.reporter.TestSeleniumTestsReporter.java
License:Apache License
@Test(groups = { "ut" }) public void testChangeTestResultWithSeveralKo() { List<Throwable> throwables = new ArrayList<>(); throwables.add(new WebDriverException("test exception")); throwables.add(new WebDriverException("test exception 2")); // make this test successful, it will be changed to failed List<ITestNGMethod> methods = new ArrayList<>(); methods.add(testMethod);/* w w w . j ava2 s . co m*/ Mockito.when(passedTests.getAllMethods()).thenReturn(methods); SeleniumTestsContextManager.getThreadContext().addVerificationFailures(Reporter.getCurrentTestResult(), throwables); init(); SeleniumRobotTestListener listener = new SeleniumRobotTestListener(); listener.changeTestResult(testResult); // check that the throwable associated to result is not the first declared one Mockito.verify(testResult).setStatus(2); Mockito.verify(testResult, Mockito.never()).setThrowable(throwables.get(0)); // check that test result has been changed Mockito.verify(passedTests).removeResult(testResult); Mockito.verify(failedTests).addResult(testResult, testMethod); }
From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java
License:Apache License
/** * Test replay in fallback mode when error occurs in any part of the action (except search) *///from ww w . j a va 2 s. c o m @Test(groups = { "ut" }) public void testReplayOnPerform() { when(element.getCoordinates()).thenReturn(coordinates); // force fallback to old behaviour: used by chrome as of version 62 doThrow(new UnsupportedCommandException("not supported")).when(eventDriver).perform(anyCollection()); doThrow(new WebDriverException("error clicking")).doNothing().when(mouse).click(coordinates); new Actions(eventDriver).click(element).perform(); verify(mouse, times(2)).click(coordinates); }
From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java
License:Apache License
/** * Test replay when error occurs in any part of the action * This mode is used by firefox/*w w w .j ava2 s . c o m*/ */ @Test(groups = { "ut" }) public void testReplayOnPerformWithNewActions() { doThrow(new WebDriverException("error clicking")).doNothing().when(eventDriver).perform(anyCollection()); new Actions(eventDriver).click(element).perform(); verify(eventDriver, times(2)).perform(anyCollection()); }
From source file:com.seleniumtests.ut.uipage.htmlelements.TestFrameElement.java
License:Apache License
@Test(groups = { "ut" }) public void testUseElementInsideFrameRetryOnError() throws Exception { FrameElement frame = new FrameElement("", By.id("frameId")); HtmlElement el = new HtmlElement("", By.id("el"), frame); Mockito.doThrow(new WebDriverException("fake exception")).doNothing().when(element).click(); el.click();//from w w w. java 2 s .c o m // 2 invocations because first call to click raises an error verify(locator, times(2)).frame(any(WebElement.class)); verify(locator, times(2)).defaultContent(); }
From source file:com.seleniumtests.ut.uipage.htmlelements.TestHtmlElement.java
License:Apache License
/** * Check exception handling and action replay * @throws Exception/* ww w .j a v a2 s . c o m*/ */ @Test(groups = { "ut" }) public void testIsDisplayedException() throws Exception { SeleniumTestsContextManager.getThreadContext().setReplayTimeout(1); when(element.isDisplayed()).thenThrow(new WebDriverException("error")); Assert.assertFalse(el.isDisplayed()); // updateDriver is called on every replay, so if we have 2 invocations, it means that replay has been done PowerMockito.verifyPrivate(el, atLeast(2)).invoke("updateDriver"); verify(el, times(1)).isDisplayedRetry(); }
From source file:com.seleniumtests.ut.uipage.htmlelements.TestHtmlElement.java
License:Apache License
/** * check correction of issue #10': step should be failed for all other actions but waitForPresent * @throws Exception/*from w w w .ja va2 s . c o m*/ */ @Test(groups = { "ut" }) public void testIsDisplayedExceptionSetStepFailed() throws Exception { TestStep step = new TestStep("step 1", null, new ArrayList<>()); TestLogging.setParentTestStep(step); SeleniumTestsContextManager.getThreadContext().setReplayTimeout(1); when(element.isDisplayed()).thenThrow(new WebDriverException("error")); Assert.assertFalse(el.isDisplayed()); Assert.assertTrue(step.getFailed()); }
From source file:com.seleniumtests.webelements.PageObject.java
License:Apache License
private void populateAndCapturePageSnapshot() { try {//from w w w . ja va 2s .c o m setTitle(driver.getTitle()); htmlSource = driver.getPageSource(); try { bodyText = driver.findElement(By.tagName("body")).getText(); } catch (StaleElementReferenceException ignore) { logger.warn("StaleElementReferenceException got in populateAndCapturePageSnapshot"); bodyText = driver.findElement(By.tagName("body")).getText(); } } catch (UnreachableBrowserException e) { // throw // UnreachableBrowserException throw new WebDriverException(e); } catch (WebDriverException e) { throw e; } capturePageSnapshot(); }
From source file:com.softwareonpurpose.uinavigator.UiElement.java
License:Apache License
private void reportException(WebDriverException e, String errorMessage) { getLogger().error(errorMessage);//from ww w. ja va2 s . c o m e.printStackTrace(); throw new WebDriverException(errorMessage); }