Search in sources :

Example 1 with SessionNotFoundException

use of org.openqa.selenium.remote.SessionNotFoundException in project jmeter-plugins by undera.

the class WebDriverConfigTest method shouldHandleScenarioWhenBrowserHasAlreadyQuit.

@Test
public void shouldHandleScenarioWhenBrowserHasAlreadyQuit() {
    doThrow(new SessionNotFoundException()).when(browser).quit();
    config.quitBrowser(browser);
    verify(browser, times(1)).quit();
}
Also used : SessionNotFoundException(org.openqa.selenium.remote.SessionNotFoundException) Test(org.junit.Test)

Example 2 with SessionNotFoundException

use of org.openqa.selenium.remote.SessionNotFoundException in project fess by codelibs.

the class WebDriverGenerator method generate.

@Override
public boolean generate(final String thumbnailId, final String url, final File outputFile) {
    if (logger.isDebugEnabled()) {
        logger.debug("Generate Thumbnail: " + url);
    }
    if (outputFile.exists()) {
        if (logger.isDebugEnabled()) {
            logger.debug("The thumbnail file exists: " + outputFile.getAbsolutePath());
        }
        return true;
    }
    final File parentFile = outputFile.getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();
    }
    if (!parentFile.isDirectory()) {
        logger.warn("Not found: " + parentFile.getAbsolutePath());
        return false;
    }
    if (webDriver instanceof TakesScreenshot) {
        final FessConfig fessConfig = ComponentUtil.getFessConfig();
        synchronized (this) {
            try {
                webDriver.get(url);
                if (webDriver instanceof JavascriptExecutor) {
                    final Dimension dim = webDriver.findElement(By.tagName("body")).getSize();
                    if (dim.height >= fessConfig.getThumbnailHtmlPhantomjsMaxHeightAsInteger()) {
                        if (logger.isInfoEnabled()) {
                            logger.info("Skpped Thumbnail generation " + dim + " for " + url);
                        }
                        return false;
                    }
                }
                final File thumbnail = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
                convert(thumbnail, outputFile);
                updateThumbnailField(thumbnailId, url, url);
                return true;
            } catch (final UnreachableBrowserException | SessionNotFoundException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("WebDriver is not available.", e);
                }
                previousCheckTime = 0;
            } finally {
                final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
                if (now - previousCheckTime > fessConfig.getThumbnailHtmlPhantomjsKeepAliveAsInteger().longValue()) {
                    destroy();
                    startWebDriver();
                }
            }
        }
    } else {
        logger.warn("WebDriver is not instance of TakesScreenshot: " + webDriver);
    }
    return false;
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) Dimension(org.openqa.selenium.Dimension) File(java.io.File) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) TakesScreenshot(org.openqa.selenium.TakesScreenshot) SessionNotFoundException(org.openqa.selenium.remote.SessionNotFoundException)

Aggregations

SessionNotFoundException (org.openqa.selenium.remote.SessionNotFoundException)2 File (java.io.File)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 Test (org.junit.Test)1 Dimension (org.openqa.selenium.Dimension)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 TakesScreenshot (org.openqa.selenium.TakesScreenshot)1 UnreachableBrowserException (org.openqa.selenium.remote.UnreachableBrowserException)1