Example usage for org.openqa.selenium.remote RemoteWebDriver close

List of usage examples for org.openqa.selenium.remote RemoteWebDriver close

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver close.

Prototype

@Override
    public void close() 

Source Link

Usage

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

public static void cleanUpNewWindows(RemoteWebDriver driver, String handleToKeep) throws ActionFailed {
    try {//from  w  w w  . j  a va 2s.c o m
        Set<String> handles = new HashSet<String>(driver.getWindowHandles());
        for (String handle : handles) {
            try {
                if (!handleToKeep.equals(handle)) {
                    driver.switchTo().window(handle);
                    driver.close();
                }
            } catch (Throwable t) {
                Log.exception(t);
            }
        }
        driver.switchTo().window(handleToKeep);
        driver.switchTo().defaultContent();
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:com.watchrabbit.scanner.supervisor.service.OrderServiceImpl.java

License:Apache License

@Override
public void inspectSite(String addressId, String address) {
    RemoteWebDriver driver = firefoxFactory.produceDriver();
    loadPage(address, driver);/*from  w ww .j a v  a2  s  .  c om*/
    try {
        supervisorService.inspectSite(addressId, address, driver);
        firefoxFactory.returnWebDriver(driver);
    } catch (RuntimeException ex) {
        LOGGER.error("Catched error, closing browser", ex);
        driver.close();
    }
}

From source file:edu.uga.cs.clickminer.ClickminerCLI.java

License:Open Source License

private static void run(String[] args) {
    GnuParser parser = new GnuParser();
    Options opts = ClickminerCLI.initializeOptions();
    CommandLine cli;/*from   w w  w .j  a  v  a 2  s  .c om*/
    RemoteWebDriver wdriver = null;
    try {
        cli = parser.parse(opts, args);

        if (cli.hasOption('?')) {
            throw new ParseException(null);
        }

        if (log.isInfoEnabled()) {
            StringBuffer arginfo = new StringBuffer("\n");
            arginfo.append("firefox-binary: " + cli.getOptionValue('b') + "\n");
            arginfo.append("firefox-profile: " + cli.getOptionValue('P') + "\n");
            arginfo.append("host: " + cli.getOptionValue('h') + "\n");
            arginfo.append("proxy-port: " + cli.getOptionValue('p') + "\n");
            arginfo.append("inst-server-port: " + cli.getOptionValue('q') + "\n");
            arginfo.append("clicklog: " + cli.getOptionValue('o') + "\n");
            arginfo.append("check-limit: " + cli.getOptionValue('l') + "\n");

            String[] mimes = cli.getOptionValues('f');
            String mimesstr = null;
            if (mimes != null) {
                mimesstr = new String();
                for (int i = 0; i < mimes.length; i++) {
                    if (i < mimes.length - 1) {
                        mimesstr += mimes[i] + ",";
                    } else {
                        mimesstr += mimes[i];
                    }
                }
            }

            arginfo.append("filter-mime: " + mimesstr + "\n");
            arginfo.append("javascript-execution: " + cli.hasOption('j') + "\n");
            arginfo.append("flash: " + cli.hasOption('F') + "\n");
            arginfo.append("unstable-loading: " + cli.hasOption('u') + "\n");
            arginfo.append("firefox-stdio-log: " + cli.getOptionValue("Lo") + "\n");
            arginfo.append("firefox-webdriver-log: " + cli.getOptionValue("Ld") + "\n");

            log.info(arginfo.toString());
        }

        String binarypath = cli.getOptionValue('b');
        FirefoxBinary binary = null;
        if (binarypath != null) {
            binary = new FirefoxBinary(new File(binarypath));
        }

        Pair<DesiredCapabilities, FirefoxProfile> config = createBrowserConfig(cli);
        wdriver = new FirefoxDriver(binary, config.getRight(), config.getLeft());
        if (cli.hasOption("u")) {
            wdriver.manage().timeouts().pageLoadTimeout(1000, TimeUnit.MILLISECONDS);
            wdriver.manage().timeouts().implicitlyWait(1000, TimeUnit.MILLISECONDS);
        }

        ProxyClient pc = new ProxyClient(cli.getOptionValue('h'),
                ((Number) cli.getParsedOptionValue("q")).intValue());

        if (cli.hasOption('l')) {
            pc.setRequestCheckLimit(((Number) cli.getParsedOptionValue("l")).intValue());
        }
        if (cli.hasOption('f')) {
            List<String> types = Arrays.asList(cli.getOptionValues('f'));
            pc.setFilteredResponseType(types);
        }

        BrowserEngine bengine = new BrowserEngine(pc, wdriver, cli.hasOption('j'), cli.hasOption('F'));
        try {
            bengine.run();
        } catch (Exception e) {
            if (log.isFatalEnabled()) {
                log.fatal("", e);
            }
        }
        List<InteractionRecord> ilog = bengine.getInteractionLog();
        JSONWriter<InteractionRecord> writer = new JSONWriter<InteractionRecord>();
        try {
            writer.write(new File(cli.getOptionValue('o')), ilog);
        } catch (Exception e) {
            if (log.isErrorEnabled()) {
                log.error("", e);
            }
        }
        bengine.close();
    } catch (ParseException e1) {
        PrintWriter writer = new PrintWriter(System.out);
        HelpFormatter usageFormatter = new HelpFormatter();
        usageFormatter.printHelp(writer, 80, "clickminer", "", opts, 0, 2, "");
        writer.close();
    } catch (ProxyErrorException e2) {
        String message = "Error communicating with proxy server. Aborting";
        if (log.isFatalEnabled()) {
            log.fatal(message, e2);
        }
    } finally {
        if (wdriver != null) {
            try {
                wdriver.close();
            } catch (Exception e) {
                if (log.isDebugEnabled()) {
                    log.debug(e);
                }
                System.exit(-1);
            }
        }
    }
}

From source file:org.asqatasun.websnapshot.service.SnapshotCreatorImpl.java

License:Open Source License

/**
 *
 * @param driver
 */
private void closeDriver(RemoteWebDriver driver) {
    driver.close();
    driver.quit();
}