List of usage examples for org.openqa.selenium WebDriverException getMessage
@Override
public String getMessage()
From source file:com.ariatemplates.seleniumjavarobot.executor.Executor.java
License:Apache License
private static final boolean handleException(WebDriverException exception) { String message = exception.getMessage(); for (Entry<String, String> entry : knownExceptions.entrySet()) { if (message.startsWith(entry.getKey())) { String replacementMessage = entry.getValue(); if (replacementMessage != null) { SeleniumJavaRobot.log(replacementMessage); }/*from www . j a v a 2 s. com*/ return true; } } return false; }
From source file:com.cognifide.aet.job.common.modifiers.replacetext.ReplaceTextModifier.java
License:Apache License
public CollectorStepResult replaceText() throws ProcessingException { CollectorStepResult result;/* ww w.j av a 2 s. co m*/ try { String script = "arguments[0]." + attributeName + "=arguments[1];"; By elementLocator = getLocator(); SeleniumWaitHelper.waitForElementToBePresent(webDriver, elementLocator, getTimeoutInSeconds()); List<WebElement> webElements = webDriver.findElements(elementLocator); for (WebElement element : webElements) { ((JavascriptExecutor) webDriver).executeScript(script, element, value); } result = CollectorStepResult.newModifierResult(); } catch (WebDriverException e) { final String message = String.format("Error while replacing text in element %s. %s", getLocator().toString(), e.getMessage()); result = CollectorStepResult.newProcessingErrorResult(message); LOG.warn("Error while trying to find element '{}'", getLocator().toString(), e); } catch (Exception e) { throw new ProcessingException( "Can't replace text in +" + attributeName + " attribute in element: " + getLocator().toString(), e); } return result; }
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.image.AemImageSetterHelper.java
License:Apache License
private void executeJavascript(String imagePlaceholderId) { frameSwitcher.switchTo("/"); JavascriptExecutor js = (JavascriptExecutor) webDriver; LOG.debug("executing javascript with argument: '{}'", imagePlaceholderId); bobcatWait.withTimeout(Timeouts.MEDIUM).until(driver -> { boolean executedSuccessfully = false; do {/* w w w . j a va 2s . c om*/ try { String javaScript = getJavascriptToExecute(); js.executeScript(javaScript, imagePlaceholderId); executedSuccessfully = true; } catch (WebDriverException wde) { LOG.warn("error while executing JavaScript: '{}'", wde.getMessage(), wde); } catch (IOException ioe) { String msg = "error while loading JavaScript from file: " + IMAGE_SETTER_JS_FILENAME; LOG.error(msg, ioe); throw new BobcatRuntimeException(msg); } } while (!executedSuccessfully); return executedSuccessfully; }, DELAY_BEFORE_RETRY_IN_SECONDS); frameSwitcher.switchBack(); }
From source file:com.cognifide.qa.bb.aem.touch.pageobjects.touchui.Parsys.java
License:Apache License
/** * it may happen that the window pops up just a moment before {@code dropArea.click(} happens, * which results in WebdriverException: 'Other element would receive the click' - thus it is * catched and validated/*from w w w . j a v a2 s . c o m*/ */ private void tryToOpenInsertWindow() { conditions.verify(ignored -> { try { boolean isInsertButtonPresent = driver.findElements(By.cssSelector(INSERT_BUTTON_SELECTOR)) .size() > 0; if (!isInsertButtonPresent) { // AEM 6.1 actions.doubleClick(dropArea).perform(); } else { // AEM 6.2 insertButton.click(); } } catch (WebDriverException e) { return e.getMessage().contains("Other element would receive the click"); } return insertComponentWindow.isDisplayedExpectingComponents(); }, Timeouts.MEDIUM); }
From source file:com.dhenton9000.selenium.generic.UtilMethods.java
/** * include full file name/path// w w w . ja va2 s . c o m * @param fileName * @param driver */ public static void takeScreenshot(String fileName, WebDriver driver) { try { String date = Long.toString(new Date().getTime()); File pngFile = new File(fileName + date + ".png"); File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, pngFile); } catch (WebDriverException e) { LOG.error("webdriver problem with screenshot: " + " " + e.getMessage()); } catch (IOException e) { LOG.error("io problem with screenshot: " + " " + e.getMessage()); } }
From source file:com.elastica.browserfactory.AbstractWebDriverFactory.java
License:Apache License
public void cleanUp() { try {/* w ww .j a v a2 s. c o m*/ if (driver != null) { try { TestLogging.log("quiting webdriver" + Thread.currentThread().getId()); driver.quit(); } catch (WebDriverException ex) { TestLogging.log("Exception encountered when quiting driver: " + WebUIDriver.getWebUXDriver().getConfig().getBrowser().name() + ":" + ex.getMessage()); } driver = null; } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.elastica.browserfactory.FirefoxDriverFactory.java
License:Apache License
/** * Create webDriver, capture socket customexception and retry with timeout. * * @return WebDriver//ww w.j a v a 2s .c o m */ protected WebDriver createWebDriverWithTimeout() { long time = 0; while (time < getTimeout()) { try { driver = createNativeDriver(); return driver; } catch (WebDriverException ex) { if (ex.getMessage().contains("SocketException") || ex.getMessage().contains("Failed to connect to binary FirefoxBinary") || ex.getMessage().contains("Unable to bind to locking port 7054 within 45000 ms")) { try { Thread.sleep(1000); } catch (InterruptedException e) { } time++; } else { throw new RuntimeException(ex); } } } throw new RuntimeException("Got customexception when creating webDriver with socket timeout 1 minute"); }
From source file:com.gargoylesoftware.htmlunit.libraries.PrototypeTestBase.java
License:Apache License
/** * Runs the specified test./*from ww w . j a v a 2 s. c o m*/ * @param filename the test file to run * @throws Exception if the test fails */ protected void test(final String filename) throws Exception { final WebDriver driver = getWebDriver(); if (!(driver instanceof HtmlUnitDriver)) { try { driver.manage().window().setSize(new Dimension(1272, 768)); } catch (final WebDriverException e) { // ChromeDriver version 0.5 (Mar 26, 2013) does not support the setSize command LOG.warn(e.getMessage(), e); } } driver.get(getBaseUrl() + filename); // wait final long runTime = 60 * DEFAULT_WAIT_TIME; final long endTime = System.currentTimeMillis() + runTime; while (!testFinished(driver)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { fail("Test '" + filename + "' runs too long (longer than " + runTime / 1000 + "s)"); } } String expected = getExpectations(getBrowserVersion(), filename); WebElement testlog = driver.findElement(By.id("testlog")); String actual = testlog.getText(); try { testlog = driver.findElement(By.id("testlog_2")); actual = actual + "\n" + testlog.getText(); } catch (final NoSuchElementException e) { // ignore } // ignore Info lines expected = expected.replaceAll("Info:.*", "Info: -- skipped for comparison --"); actual = actual.replaceAll("Info:.*", "Info: -- skipped for comparison --"); // normalize line break expected = expected.replaceAll("\r\n", "\n"); actual = actual.replaceAll("\r\n", "\n"); // dump the result page if not ok if (System.getProperty(PROPERTY_GENERATE_TESTPAGES) != null && !expected.equals(actual)) { final File tmpDir = new File(System.getProperty("java.io.tmpdir")); final File f = new File(tmpDir, "prototype" + getVersion() + "_result_" + filename); FileUtils.writeStringToFile(f, driver.getPageSource(), UTF_8); LOG.info("Test result for " + filename + " written to: " + f.getAbsolutePath()); } assertEquals(expected, actual); }
From source file:com.googlecode.ounit.selenium.SanitizeSeleniumExceptionsRule.java
License:Open Source License
@Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override/* w w w. j av a2s . c om*/ public void evaluate() throws Throwable { try { base.evaluate(); } catch (WebDriverException e) { String msg = e.getMessage(); int idx = msg.indexOf("For documentation on this error"); if (idx > 0) msg = msg.substring(0, idx); throw new AssertionError(msg); } } }; }
From source file:com.hotwire.test.steps.SetupTeardownSteps.java
License:Apache License
@After public void tearDown(Scenario scenario) { if (scenario.isFailed()) { try {/* ww w.j a v a 2 s . c om*/ logger.info("Test failed, taking screenshot"); byte[] screenshot = ((TakesScreenshot) new Augmenter().augment(getAppiumDriver())) .getScreenshotAs(OutputType.BYTES); scenario.embed(screenshot, "image/png"); } catch (WebDriverException wde) { System.err.println(wde.getMessage()); } catch (ClassCastException cce) { cce.printStackTrace(); } } application.tearDown(); }