Example usage for org.openqa.selenium WebDriverException WebDriverException

List of usage examples for org.openqa.selenium WebDriverException WebDriverException

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriverException WebDriverException.

Prototype

public WebDriverException(Throwable cause) 

Source Link

Usage

From source file:com.opera.core.systems.common.io.ProcessManager.java

License:Apache License

public static void killPID(int processID) {
    if (currentPlatform.is(WINDOWS)) {
        executeCommand("taskkill", "/pid", String.valueOf(processID));
    } else if (currentPlatform.is(UNIX) || currentPlatform.is(MAC)) {
        executeCommand("kill", "-SIGKILL", String.valueOf(processID));
    } else {//w w  w  .j  ava 2s.  c  om
        throw new WebDriverException("Unknown platform: " + currentPlatform);
    }
}

From source file:com.opera.core.systems.common.io.ProcessManager.java

License:Apache License

private static String executeCommand(String commandName, String... args) {
    CommandLine cmd = new CommandLine(commandName, args);
    logger.fine(cmd.toString());//from   www  .jav a2s  .  com

    cmd.execute();
    String output = cmd.getStdOut();

    if (!cmd.isSuccessful()) {
        throw new WebDriverException(String.format("exec return code %d: %s", cmd.getExitCode(), output));
    }

    return output;
}

From source file:com.opera.core.systems.internal.CallbackWait.java

License:Apache License

/**
 * Repeatedly applies this instance's input value to the given callable until one of the following
 * occurs:/*from  w w w .j  a  va2 s .co  m*/
 *
 * <ol> <li>the function returns neither null nor false.</li> <li>the function throws an unignored
 * exception.</li> <li>the timeout expires.</li> <li>the current thread is interrupted.</li>
 * </ol>
 *
 * @param condition the {@link Callable} to evaluate
 * @return the callable's return value
 */
public <X> X until(Callable<X> condition) {
    long end = clock.laterBy(timeout.in(MILLISECONDS));
    Exception lastException = null;

    while (true) {
        try {
            X toReturn = condition.call();

            if (toReturn != null && Boolean.class.equals(toReturn.getClass())) {
                if (Boolean.TRUE.equals(toReturn)) {
                    return toReturn;
                }
            } else if (toReturn != null) {
                return toReturn;
            }
        } catch (Exception e) {
            lastException = propagateIfNotIgnored(e);
        }

        if (!clock.isNowBefore(end)) {
            String toAppend = (message == null) ? " waiting for " + condition.toString() : ": " + message;

            String timeoutMessage = String.format("Timed out after %d milliseconds%s", timeout.in(MILLISECONDS),
                    toAppend);
            throw timeoutException(timeoutMessage, lastException);
        }

        try {
            sleeper.sleep(interval);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new WebDriverException(e);
        }
    }
}

From source file:com.opera.core.systems.OperaBinary.java

License:Apache License

public OperaBinary(OperaProduct product) {
    this(find(product));

    if (binary == null) {
        throw new WebDriverException("Cannot find Opera binary in your PATH or in OPERA_PATH");
    }// ww w .  j a v a2s .  c  o  m
}

From source file:com.opera.core.systems.OperaDriver.java

License:Apache License

/**
 * Starts Opera with the given set of desired capabilities.
 *
 * @param c a {@link DesiredCapabilities} object containing various settings for the driver and
 *          the browser//from  w w w  .  j ava 2s. c  o m
 */
public OperaDriver(Capabilities c) {
    capabilities = (DesiredCapabilities) getDefaultCapabilities();

    if (c != null) {
        capabilities.merge(CapabilitiesSanitizer.sanitize(c));
    }

    // Set the logging level for main logger instance
    Level logLevel;
    Object typelessLevel = capabilities.getCapability(LOGGING_LEVEL);
    if (typelessLevel instanceof String) {
        logLevel = Level.parse(((String) typelessLevel).toUpperCase());
    } else if (typelessLevel instanceof Level) {
        logLevel = (Level) typelessLevel;
    } else {
        throw new WebDriverException("Unknown logging level: " + typelessLevel.toString());
    }
    Logger root = Logger.getLogger("");
    root.setLevel(logLevel);

    // Write log to file?
    if (capabilities.getCapability(LOGGING_FILE) != null) {
        try {
            logFile = new FileHandler((String) capabilities.getCapability(LOGGING_FILE),
                    OperaFlags.APPEND_TO_LOGFILE);
            logFile.setFormatter(new SimpleFormatter());
        } catch (IOException e) {
            throw new WebDriverException("Unable to write to file: " + e);
        }
    }

    if (logFile != null) {
        root.addHandler(logFile);
    }

    // Set logging levels on all handlers
    for (Handler h : root.getHandlers()) {
        h.setLevel(logLevel);
    }

    if ((Boolean) capabilities.getCapability(AUTOSTART)) {
        if (((Boolean) capabilities.getCapability(GUESS_BINARY_PATH))
                && capabilities.getCapability(BINARY) == null) {
            capabilities.setCapability(BINARY, OperaPaths.operaPath());
        } else if (capabilities.getCapability(BINARY) == null) {
            // Don't guess, only check environment variable
            String path = System.getenv("OPERA_PATH");
            if (path != null && !path.isEmpty()) {
                capabilities.setCapability(BINARY, path);
            }
        }

        OperaRunnerSettings settings = new OperaLauncherRunnerSettings();
        settings.setBinary((String) capabilities.getCapability(BINARY));
        settings.setPort((Integer) capabilities.getCapability(PORT));

        OperaArguments arguments = new OperaCoreArguments();
        OperaArguments parsed = OperaArguments.parse((String) capabilities.getCapability(ARGUMENTS));
        arguments.merge(parsed);
        settings.setArguments(arguments);

        if (capabilities.getCapability(PROFILE) instanceof String) {
            settings.setProfile((String) capabilities.getCapability(PROFILE));
        } else if (capabilities.getCapability(PROFILE) instanceof OperaProfile) {
            settings.setProfile((OperaProfile) capabilities.getCapability(PROFILE));
        }

        // Synchronize settings for runner and capabilities
        capabilities.setCapability(ARGUMENTS, settings.getArguments().toString());
        capabilities.setCapability(PORT, settings.getPort());
        capabilities.setCapability(PROFILE, settings.getProfile());

        if (capabilities.getCapability(BINARY) != null) {
            runner = new OperaLauncherRunner((OperaLauncherRunnerSettings) settings);
        }
    } else {
        // If we're not autostarting then we don't want to randomise the port.
        capabilities.setCapability(PORT, (int) OperaIntervals.SERVER_PORT.getValue());
    }

    logger.config(capabilities.toString());
    start();
}

From source file:com.opera.core.systems.OperaDriver.java

License:Apache License

/**
 * Start Opera, and handle any exceptions that might occur.
 *//* ww w .  j a v a2s .  c o m*/
private void start() {
    try {
        this.init();
    } catch (Exception e) {
        // Will make sure to kill any eventual launcher process that was started
        this.quit();
        throw new WebDriverException(e);
    }

    logger.finer("Initialization done");
}

From source file:com.opera.core.systems.OperaDriver.java

License:Apache License

/**
 * Set up the Scope connection and thread.
 *///from w w w . j a  v  a2  s . c  o  m
private void createScopeServices() {
    try {
        Map<String, String> versions = getServicesList();
        boolean manualStart = true;

        if (capabilities.getCapability(BINARY) != null) {
            manualStart = false;
        }

        services = new ScopeServices(versions, (Integer) capabilities.getCapability(PORT), manualStart);
        // for profile-specific workarounds inside ScopeServices, WaitState ...
        services.setProduct((String) capabilities.getCapability(PRODUCT));
        services.startStpThread();
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
}

From source file:com.opera.core.systems.OperaExtensions.java

License:Apache License

/**
 * Create a new manager for custom Opera extensions.
 *
 * @param profileDirectory An Opera profile directory. This directory must exist.
 *//*from   w  ww  .  java  2  s . c om*/
OperaExtensions(File profileDirectory) {
    // Extensions will be installed here.
    directory = new File(profileDirectory, "widgets");
    widgetsDat = new File(directory, "widgets.dat");
    if (widgetsDat.exists()) {
        try {
            backupWidgetDat = File.createTempFile("operadriver-", "-widgets.dat");
            Files.copy(widgetsDat, backupWidgetDat);
        } catch (IOException e) {
            throw new WebDriverException("Unable to create a back-up of " + widgetsDat.getPath());
        }
    }
}

From source file:com.opera.core.systems.OperaExtensions.java

License:Apache License

/**
 * Remove all custom extensions/*  w w w  .  ja  v  a 2  s  .c  o  m*/
 */
public void cleanUp() {
    // Removing the entries from widgets.dat suffices. Opera will remove the other files.
    // These other files are:
    // widgets/xxx.oex
    // widgets/OEX_PATH_PREFIX/
    if (backupWidgetDat != null) {
        try {
            Files.move(backupWidgetDat, widgetsDat);
        } catch (IOException e) {
            throw new WebDriverException("Unable to restore widgets.dat");
        }
    } else {
        widgetsDat.delete();
    }
}

From source file:com.opera.core.systems.OperaExtensions.java

License:Apache License

/**
 * Create initial widgets directory and extension configuration file (widgets.dat) if needed.
 *
 * @throws IOException If//from   ww  w.j  a v  a  2  s. c  om
 */
private void createInitialDirectoryIfNecessary() throws IOException {
    if (!directory.exists()) {
        if (!directory.mkdirs()) {
            throw new WebDriverException("Unable to create directory path: " + directory.getPath());
        }
    }
    if (!widgetsDat.exists()) {
        Files.write(WIDGET_DAT_CONTENT, widgetsDat, Charsets.UTF_8);
    }
}