Example usage for org.openqa.selenium Platform getCurrent

List of usage examples for org.openqa.selenium Platform getCurrent

Introduction

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

Prototype

public static Platform getCurrent() 

Source Link

Document

Get current platform (not necessarily the same as operating system).

Usage

From source file:com.opera.core.systems.runner.AbstractOperaRunner.java

License:Apache License

public AbstractOperaRunner(OperaSettings s) {
    settings = s;//  ww w  . j a va 2s .c o m

    // Find a suitable Opera executable based on requested product if no binary has already been
    // specified
    if (settings.getBinary() == null) {
        // Do check for null here since OperaBinary's sanitization throws a cryptic null pointer
        File binary = OperaBinary.find(settings.getProduct());
        if (binary == null) {
            throw new OperaRunnerException(
                    String.format("Unable to find executable for product %s", settings.getProduct()));
        }

        // Calls new OperaBinary(b) which will check that the binary is executable and that it's not a
        // directory
        settings.setBinary(binary);
    }

    // This can't be last, otherwise it might get interpreted as the page to open, and the file
    // listing page doesn't have a JS context to inject into.

    // Only append -pd if compatibility mode is enabled (for Opera < 11.60)
    if (settings.supportsPd()) {
        settings.arguments().add("-pd", settings.profile().getDirectory().getAbsolutePath());
    }

    // If port is set to -1 it means we're in compatibility mode as Opera < 11.60 does not support
    // the -debugproxy command-line argument.  It will instead use the default port 7001.
    if (settings.supportsDebugProxy()) {
        settings.arguments().add("debugproxy", settings.getHost() + ":" + settings.getPort());
    }

    settings.arguments().add("autotestmode");

    // Hack - if we are testing desktop mac the fullscreen argument must be after -pd
    // otherwise the pd setting does not have any effect. So putting it last.
    if (settings.getProduct().is(DESKTOP) && Platform.getCurrent().is(Platform.MAC)) {
        OperaArgument fullscreen = new OperaArgument("fullscreen");
        settings.arguments().remove(fullscreen);
        settings.arguments().add(fullscreen);
    }

    logger.config("Opera arguments: " + settings.arguments().getArgumentsAsStringList());
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherBinary.java

License:Apache License

public void init() throws IOException {
    ProcessBuilder builder = new ProcessBuilder(commands);
    builder.redirectErrorStream(true);/*from  ww  w .j  a  v a 2 s.c o  m*/

    try {
        process = builder.start();
        watcher = new OutputWatcher(process);
        outputWatcherThread = new Thread(getThreadGroup(), watcher, "output-watcher");
        outputWatcherThread.setDaemon(true);
        running.set(true);
        outputWatcherThread.start();
    } catch (IOException e) {
        if (Platform.getCurrent().is(Platform.WINDOWS)) {
            throw new IOException(
                    "Could not start the launcher process, make sure you have the Microsoft Visual C++ "
                            + "2008 Redistributable Package installed on your system: " + e.getMessage());
        } else {
            throw new IOException(e);
        }
    }

    try {
        waitFor(OperaIntervals.PROCESS_START_SLEEP.getValue());
        if (process.exitValue() > 0) {
            throw new IOException("exited immediately; possibly incorrect command-line arguments?  "
                    + "Commands: " + commands);
        }
    } catch (IllegalThreadStateException e) {
        // process hasn't exited, soldier on!
    }
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java

License:Apache License

/**
 * Makes the launcher executable by chmod'ing the file at given path (GNU/Linux and Mac only).
 *
 * @param launcher the file to make executable
 */// ww  w .j  a  v a2  s.  c o m
private static void makeLauncherExecutable(File launcher) {
    Platform current = Platform.getCurrent();

    if (current.is(Platform.UNIX) || current.is(Platform.MAC)) {
        CommandLine line = new CommandLine("chmod", "u+x", launcher.getAbsolutePath());
        line.execute();
    }
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java

License:Apache License

/**
 * Get the launcher's binary file name based on what flavour of operating system and what kind of
 * architecture the user is using.//from  ww  w .  ja  v  a2s.  c o  m
 *
 * @return the launcher's binary file name
 */
protected static String getLauncherNameForOS() {
    boolean is64 = "64".equals(System.getProperty("sun.arch.data.model"));
    Platform currentPlatform = Platform.getCurrent();

    switch (currentPlatform) {
    case LINUX:
    case UNIX:
        return (is64 ? "launcher-linux-x86_64" : "launcher-linux-i686");
    case MAC:
        return "launcher-mac";
    case WINDOWS:
    case VISTA:
    case XP:
        return "launcher-win32-i86pc.exe";
    default:
        throw new WebDriverException(
                "Could not find a platform that supports bundled launchers, please set it manually");
    }
}

From source file:com.opera.core.systems.runner.OperaRunnerSettings.java

License:Apache License

public void setDisplay(Integer display) throws UnsupportedOperationException {
    if (!Platform.getCurrent().is(Platform.LINUX)) {
        throw new UnsupportedOperationException("Unsupported operating system: " + Platform.getCurrent());
    }/*from   w  w w  .  j  a va 2 s  . co  m*/
    this.display = display;
}

From source file:com.opera.core.systems.testing.Resources.java

License:Apache License

public Resources() throws IOException {
    if (Platform.getCurrent().is(Platform.WINDOWS)) {
        executableBinary = new File("C:\\WINDOWS\\system32\\find.exe");
    } else {/*from w  w w. j  a  va  2  s  . c om*/
        executableBinary = new File("/bin/echo");
    }

    //temporaryFolder().newFolder();
    textFile = temporaryFolder().newFile();
}

From source file:com.opera.core.systems.testing.TestRunner.java

License:Apache License

/**
 * Creates a {@link BlockJUnit4ClassRunner} to run {@code testClass}.
 *
 * @param testClass the class under test
 * @throws InitializationError if the test class is malformed
 *///from w  w  w  . ja  v a 2s .  co  m
public TestRunner(Class<?> testClass) throws InitializationError {
    super(testClass);

    try {
        test = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        testException = e;
    }

    if (test instanceof TestCase) {
        TestCase base = (TestCase) test;
        TestDriver driver = base.getWrappedDriver();

        // If any driver is present we don't need a different supplier's driver to initialize
        // TestIgnorance.  This skips the supplies(klass) check in createDriverIfNecessary().
        if (driver == null || !driver.isRunning()) {
            base.createDriverIfNecessary();
            driver = base.getWrappedDriver();
        }

        ignorance = new TestIgnorance(driver.getServices().getAvailableServices(), driver.getRunner() != null,
                driver.getServices().isOperaIdleAvailable(), driver.utils().getPlatform(),
                driver.utils().getProduct());
    } else {
        ignorance = new TestIgnorance(new LinkedHashMap<ScopeService, String>(), false, false,
                Platform.getCurrent(), OperaProduct.ALL);
    }
}

From source file:com.vilt.minium.script.impl.ChromeDriverFactory.java

License:Apache License

protected void maybeInitChromeDriverService() {
    try {/*from w  ww  .  j  a  v  a 2s . c o  m*/
        if (service == null) {
            String exe = Platform.getCurrent().is(Platform.WINDOWS) ? "chromedriver.exe" : "chromedriver";
            File baseWebDriver = new File(new File(preferences.getBaseDir(), "drivers"), exe);

            if (baseWebDriver.isFile() && baseWebDriver.canExecute()) {
                service = new ChromeDriverService.Builder().usingDriverExecutable(baseWebDriver)
                        .usingAnyFreePort().build();
            } else {
                service = ChromeDriverService.createDefaultService();
            }
            service.start();
            logger.debug("Chrome driver service initialized: {}", service.getUrl());
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.vilt.minium.script.impl.InternetExplorerDriverFactory.java

License:Apache License

@Override
public WebDriver create(DesiredCapabilities capabilities) {
    Preconditions.checkArgument(Objects.equal(BrowserType.IE, capabilities.getBrowserName()));
    Preconditions.checkState(Platform.getCurrent().is(Platform.WINDOWS), "IE driver only supported in Windows");
    maybeInitInternetExplorerDriverService();
    WebDriver driver = new RemoteWebDriver(service.getUrl(), capabilities);
    return new Augmenter().augment(driver);
}

From source file:com.vilt.minium.script.impl.PhantomJsDriverFactory.java

License:Apache License

protected void maybeInitPhantomJsDriverService() {
    try {/*from w  w w . j a v  a 2  s  .  co m*/
        if (service == null) {
            String exe = Platform.getCurrent().is(Platform.WINDOWS) ? "phantomjs.exe" : "phantomjs";
            File phantomJsBin = new File(new File(preferences.getBaseDir(), "drivers"), exe);

            if (phantomJsBin.isFile() && phantomJsBin.canExecute()) {
                service = new PhantomJSDriverService.Builder().usingPhantomJSExecutable(phantomJsBin)
                        .usingAnyFreePort().build();
            } else {
                service = PhantomJSDriverService.createDefaultService();
            }
            service.start();
            logger.debug("PhantomJS driver service initialized: {}", service.getUrl());
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}