List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:com.qwazr.crawler.web.driver.BrowserDriver.java
License:Apache License
@Override public String getContentType() { if (driver instanceof AdditionalCapabilities.ResponseHeader) return ((AdditionalCapabilities.ResponseHeader) driver).getContentType(); throw new WebDriverException("GetContentType is not implemented in " + driver.getClass()); }
From source file:com.qwazr.crawler.web.driver.BrowserDriver.java
License:Apache License
@Override public String getContentDisposition() { if (driver instanceof AdditionalCapabilities.ResponseHeader) return ((AdditionalCapabilities.ResponseHeader) driver).getContentDisposition(); throw new WebDriverException("GetContentDisposition is not implemented in " + driver.getClass()); }
From source file:com.qwazr.crawler.web.driver.BrowserDriver.java
License:Apache License
@Override public String getContentDispositionFilename() { if (driver instanceof AdditionalCapabilities.ResponseHeader) return ((AdditionalCapabilities.ResponseHeader) driver).getContentDispositionFilename(); throw new WebDriverException("GetContentDispositionFilename is not implemented in " + driver.getClass()); }
From source file:com.seleniumtests.core.SeleniumTestsContext.java
License:Apache License
/** * From platform name, in case of Desktop platform, do nothing and in case of mobile, extract OS version from name * as platformName will be 'Android 5.0' for example * * @throws ConfigurationException in mobile, if version is not present */// w w w .j a va 2 s.c o m private void updatePlatformVersion() { try { Platform currentPlatform = Platform.fromString(getPlatform()); if (currentPlatform.is(Platform.WINDOWS) || currentPlatform.is(Platform.MAC) || currentPlatform.is(Platform.UNIX) || currentPlatform.is(Platform.ANY) && getRunMode() == DriverMode.GRID) { return; } else { throw new WebDriverException(""); } } catch (WebDriverException e) { if (getPlatform().toLowerCase().startsWith("android") || getPlatform().toLowerCase().startsWith("ios")) { String[] pfVersion = getPlatform().split(" ", 2); try { setPlatform(pfVersion[0]); setMobilePlatformVersion(pfVersion[1]); return; } catch (IndexOutOfBoundsException x) { setMobilePlatformVersion(null); logger.warn( "For mobile platform, platform name should contain version. Ex: 'Android 5.0' or 'iOS 9.1'. Else, first found device is used"); } } else { throw new ConfigurationException( String.format("Platform %s has not been recognized as a valid platform", getPlatform())); } } }
From source file:com.seleniumtests.it.stubclasses.StubCucumberClass.java
License:Apache License
@When("write_error (\\w+)") public void writeTextWithError(String text) { throw new WebDriverException("no element found"); }
From source file:com.seleniumtests.it.stubclasses.StubTestClass.java
License:Apache License
@Test(groups = "stub", description = "a test with steps") public void testAndSubActions() throws IOException { TestStep step1 = new TestStep("step 1", TestLogging.getCurrentTestResult(), new ArrayList<>()); step1.addAction(new TestAction("click button", false, new ArrayList<>())); step1.addAction(new TestAction("sendKeys to text field", true, new ArrayList<>())); ScreenShot screenshot = new ScreenShot(); File tmpImg = File.createTempFile("img_with_very_very_very_long_name_to_be_shortened", ".png"); File tmpHtml = File.createTempFile("html_with_very_very_very_long_name_to_be_shortened", ".html"); screenshot.setImagePath("screenshot/" + tmpImg.getName()); screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName()); FileUtils.moveFile(tmpImg, new File(screenshot.getFullImagePath())); FileUtils.moveFile(tmpHtml, new File(screenshot.getFullHtmlPath())); step1.addSnapshot(new Snapshot(screenshot), 1, null); step1.setActionException(new WebDriverException("driver exception")); TestStep subStep1 = new TestStep("step 1.3: open page", TestLogging.getCurrentTestResult(), new ArrayList<>()); subStep1.addAction(new TestAction("click link", false, new ArrayList<>())); subStep1.addMessage(new TestMessage("a message", MessageType.LOG)); subStep1.addAction(new TestAction("sendKeys to password field", false, new ArrayList<>())); step1.addAction(subStep1);//from w ww.ja v a2 s .c om WaitHelper.waitForSeconds(3); step1.setDuration(1230L); TestStep step2 = new TestStep("step 2", TestLogging.getCurrentTestResult(), new ArrayList<>()); step2.setDuration(14030L); TestLogging.logTestStep(step1); TestLogging.logTestStep(step2); }
From source file:com.seleniumtests.uipage.aspects.ReplayAction.java
License:Apache License
/** * Replay all HtmlElement actions annotated by ReplayOnError. * Classes which are not subclass of HtmlElement won't go there * See javadoc of the annotation for details * @param joinPoint// ww w .j av a 2s . c o m * @throws Throwable */ @Around("execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)") public Object replayHtmlElement(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable { Instant end = systemClock.instant() .plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout()); Object reply = null; // update driver reference of the element // corrects bug of waitElementPresent which threw a SessionNotFoundError because driver reference were not // updated before searching element (it used the driver reference of an old test session) HtmlElement element = (HtmlElement) joinPoint.getTarget(); element.setDriver(WebUIDriver.getWebDriver()); String targetName = joinPoint.getTarget().toString(); TestAction currentAction = null; String methodName = joinPoint.getSignature().getName(); if (methodName != "getCoordinates") { List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>())); currentAction = new TestAction(actionName, false, pwdToReplace); } // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } boolean actionFailed = false; boolean ignoreFailure = false; try { while (end.isAfter(systemClock.instant())) { // in case we have switched to an iframe for using previous webElement, go to default content if (element.getDriver() != null && SeleniumTestsContextManager.isWebTest()) { element.getDriver().switchTo().defaultContent(); // TODO: error when clic is done, closing current window } try { reply = joinPoint.proceed(joinPoint.getArgs()); WaitHelper.waitForMilliSeconds(200); break; } catch (UnhandledAlertException e) { throw e; } catch (WebDriverException e) { // don't prevent TimeoutException to be thrown when coming from waitForPresent // only check that cause is the not found element and not an other error (NoSucheSessionError for example) if ((e instanceof TimeoutException && joinPoint.getSignature().getName().equals("waitForPresent") && e.getCause() instanceof NoSuchElementException) // issue #104: do not log error when waitForPresent raises TimeoutException || (e instanceof NoSuchElementException && isFromExpectedConditions(Thread.currentThread().getStackTrace())) // issue #194: return immediately if the action has been performed from ExpectedConditions class // This way, we let the FluentWait process to retry or re-raise the exception ) { ignoreFailure = true; throw e; } if (end.minusMillis(200).isAfter(systemClock.instant())) { WaitHelper.waitForMilliSeconds(replay.replayDelayMs()); continue; } else { if (e instanceof NoSuchElementException) { throw new NoSuchElementException("Searched element could not be found"); } else if (e instanceof UnreachableBrowserException) { throw new WebDriverException("Browser did not reply, it may have frozen"); } throw e; } } } return reply; } catch (Throwable e) { if (e instanceof NoSuchElementException && joinPoint.getTarget() instanceof HtmlElement && (joinPoint.getSignature().getName().equals("findElements") || joinPoint.getSignature().getName().equals("findHtmlElements"))) { return new ArrayList<WebElement>(); } else { actionFailed = true && !ignoreFailure; throw e; } } finally { if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); } } }
From source file:com.seleniumtests.uipage.htmlelements.GenericPictureElement.java
License:Apache License
/** * Search the picture in the screenshot taken by Robot or WebDriver * Robot is used in Desktop mode/*from w ww .j a v a 2s .c om*/ * WebDriver is used in mobile, because Robot is not available for mobile platforms * */ public void findElement() { LocalDateTime start = LocalDateTime.now(); File screenshotFile = getScreenshotFile(); if (screenshotFile == null) { throw new WebDriverException("Screenshot does not exist"); } // for desktop search, without reference image, do not search if (detector != null) { detector.setSceneImage(screenshotFile); detector.detectExactZoneWithScale(); detectedObjectRectangle = detector.getDetectedRectangle(); pictureSizeRatio = detector.getSizeRatio(); } else { detectedObjectRectangle = new Rectangle(0, 0, 0, 0); pictureSizeRatio = 1.0; } actionDuration = Duration.between(start, LocalDateTime.now()).toMillis(); doAfterPictureSearch(); }
From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java
License:Apache License
/** * returns an element depending on configured index * @param allElements//from ww w. ja v a 2 s . c o m */ private WebElement getElementByIndex(List<WebElement> allElements) { if (elementIndex == FIRST_VISIBLE) { for (WebElement el : allElements) { if (el.isDisplayed()) { return el; } } throw new WebDriverException("no visible element has been found for " + by.toString()); } else if (elementIndex < 0) { return allElements.get(allElements.size() + elementIndex); } else { if (elementIndex == null) { elementIndex = 0; } return allElements.get(elementIndex); } }
From source file:com.seleniumtests.ut.driver.TestCustomEventFiringWebDriver.java
License:Apache License
/** * Test the case where driver cannot return page source (case for mobile browsers or old edge versions for example) *//*from ww w. j av a2 s . com*/ @Test(groups = { "ut" }) public void testGetPageSourceWithIncopmatibleDriver() { doThrow(new WebDriverException("some error")).when(driver).getPageSource(); Assert.assertNull(((CustomEventFiringWebDriver) eventDriver).getPageSource()); }