Example usage for org.openqa.selenium Platform WINDOWS

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

Introduction

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

Prototype

Platform WINDOWS

To view the source code for org.openqa.selenium Platform WINDOWS.

Click Source Link

Document

Never returned, but can be used to request a browser running on any version of Windows.

Usage

From source file:com.seleniumtests.ut.browserfactory.TestIECapabilityFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateDefaultCapabilitiesWithPlatform() {

    Mockito.when(config.isEnableJavascript()).thenReturn(true);
    Mockito.when(config.getProxy()).thenReturn(proxyConfig);
    Mockito.when(config.getWebPlatform()).thenReturn(Platform.WINDOWS);

    MutableCapabilities capa = new IECapabilitiesFactory(config).createCapabilities();

    Assert.assertEquals(capa.getPlatform(), Platform.WINDOWS);

}

From source file:com.seleniumtests.ut.browserfactory.TestPhantomJSCapabilityFactory.java

License:Apache License

@BeforeMethod(groups = { "ut" })
public void init() {
    PowerMockito.mockStatic(System.class);
    PowerMockito.when(System.getProperty(anyString())).thenCallRealMethod();
    PowerMockito.when(System.setProperty(anyString(), anyString())).thenCallRealMethod();
    PowerMockito.when(System.clearProperty(anyString())).thenCallRealMethod();
    PowerMockito.when(System.getProperty("os.name")).thenReturn("Linux");
    Mockito.when(config.getDebug()).thenReturn(Arrays.asList(DebugMode.NONE));

    Map<BrowserType, List<BrowserInfo>> browserInfos = new HashMap<>();
    browserInfos.put(BrowserType.PHANTOMJS,
            Arrays.asList(new BrowserInfo(BrowserType.PHANTOMJS, "1", "", false)));

    PowerMockito.mockStatic(OSUtility.class);
    PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion()).thenReturn(browserInfos);
    PowerMockito.when(OSUtility.getCurrentPlatorm()).thenReturn(Platform.WINDOWS);
}

From source file:com.seleniumtests.ut.browserfactory.TestPhantomJSCapabilityFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateDefaultCapabilitiesWithPlatform() {

    Mockito.when(config.isEnableJavascript()).thenReturn(true);
    Mockito.when(config.getProxy()).thenReturn(proxyConfig);
    Mockito.when(config.getWebPlatform()).thenReturn(Platform.WINDOWS);

    MutableCapabilities capa = new PhantomJSCapabilitiesFactory(config).createCapabilities();

    Assert.assertEquals(capa.getPlatform(), Platform.WINDOWS);

}

From source file:com.seleniumtests.ut.connectors.extools.TestSoapUi.java

License:Apache License

@Test(groups = { "ut" })
public void testRunWithProjectFile() throws IOException {
    File tmp = Files.createTempDir();
    File runner;/*from ww  w  .  j ava2 s . c  o  m*/
    if (OSUtility.getCurrentPlatorm() == Platform.WINDOWS) {
        runner = Paths.get(tmp.getAbsolutePath(), "bin", "testrunner.bat").toFile();
    } else {
        runner = Paths.get(tmp.getAbsolutePath(), "bin", "testrunner.sh").toFile();
    }
    FileUtils.write(runner, "rem");
    File project = Paths.get(tmp.getAbsolutePath(), "project.xml").toFile();
    FileUtils.write(project, "<xml></xml>");

    PowerMockito.mockStatic(System.class);
    PowerMockito.mockStatic(OSCommand.class);
    when(System.getenv("SOAPUI_HOME")).thenReturn(tmp.getAbsolutePath());
    SoapUi soapui = new SoapUi();
    when(OSCommand.executeCommandAndWait(new String[] { runner.getAbsolutePath(), project.getAbsolutePath() }))
            .thenReturn("ok");
    Assert.assertEquals(soapui.executeWithProjectFile(project), "ok");
}

From source file:com.seleniumtests.util.osutility.OSUtility.java

License:Apache License

/******************************************
 *********** OS information ***************
 ******************************************/

public static Platform getCurrentPlatorm() {
    if (isWindows()) {
        return Platform.WINDOWS;
    } else if (isLinux()) {
        return Platform.LINUX;
    } else if (isMac()) {
        return Platform.MAC;
    } else {// w  w w. j a  v  a 2  s .  com
        throw new ConfigurationException(getOSName() + " is not recognized as a valid platform");
    }
}

From source file:com.sios.stc.coseng.util.TestParam.java

License:Open Source License

public synchronized Boolean isValid(final LocalParam localParam) throws IOException {
    Boolean isValid = true;/*  w ww .  j  a  v  a  2s .  c  o m*/
    // Warning items that don't necessarily invalidate the config
    if ((baseUrl == null) || baseUrl.isEmpty()) {
        TestParam.log.log(Level.WARNING, logDetails("A baseUrl was not provided; some tests may fail"));
    }
    if (verbosity == null) {
        TestParam.log.log(Level.INFO, logDetails("A verbosity was not provided; assuming level (0)"));
        verbosity = 0;
    }
    if (spot == null) {
        TestParam.log.log(Level.INFO, logDetails("A spot was not provided; assuming LOCAL"));
        spot = Spot.LOCAL;
    }
    // True|False validation parameters
    if (platform == null) {
        TestParam.log.log(Level.SEVERE, logDetails(
                "No platform was provided; a platform of (" + getPlatformOptions() + ") is REQUIRED"));
        isValid = false;
    }
    if (browser == null) {
        TestParam.log.log(Level.SEVERE,
                logDetails("No browser was provided; a browser of (" + getBrowserOptions() + ") is REQUIRED"));
        isValid = false;
    }
    // Special; chromeDriver|ieDriver when Spot.LOCAL and !Browser.FIREFOX
    if ((browser != null) && (spot == Spot.LOCAL)) {
        if (browser == Browser.CHROME) {
            // If can't find chromeDriver; bail
            final File chromeDriver = localParam.getChromeDriver();
            if ((chromeDriver == null) || !chromeDriver.exists() || !chromeDriver.canExecute()) {
                TestParam.log.log(Level.SEVERE,
                        logDetails(
                                "Testing with browser (" + browser.toString() + ") at spot (" + spot.toString()
                                        + ") REQUIRES chromeDriver. Could not find executable chromeDriver ("
                                        + chromeDriver + ")"));
                isValid = false;
            }
        } else if (browser != Browser.FIREFOX) {
            // Must be IE*
            final File ieDriver = localParam.getIeDriver();
            // If can't find ieDriver; bail
            if ((ieDriver == null) || !ieDriver.exists() || !ieDriver.canExecute()) {
                TestParam.log.log(Level.SEVERE,
                        logDetails("Testing with browser (" + browser.toString() + ") at spot ("
                                + spot.toString() + ") REQUIRES ieDriver. Could not find executable ieDriver ("
                                + ieDriver + ")"));
                isValid = false;
            }
        }
    }
    // If !windows but browser is IE*; bail
    if ((browser != null) && (platform != null)) {
        if (platform != Platform.WINDOWS) {
            if ((browser != Browser.FIREFOX) && (browser != Browser.CHROME)) {
                TestParam.log.log(Level.SEVERE,
                        logDetails("Internet Explorer IE*, any version; REQUIRES platform WINDOWS"));
                isValid = false;
            }
        }
    }
    if ((suite == null) || suite.isEmpty()) {
        TestParam.log.log(Level.SEVERE, logDetails("No suite provided; at least one suite XML REQUIRED"));
        isValid = false;
    } else {
        // jarSuiteTempDirectory is checked in findTestSuite
        if (!findTestSuite(localParam)) {
            TestParam.log.log(Level.SEVERE, logDetails("Could not find ALL suite (" + suite.toString() + ")"));
            isValid = false;
        }
    }
    if ((spot == Spot.GRID) && ((gridUrl == null) || gridUrl.isEmpty())) {
        TestParam.log.log(Level.SEVERE,
                logDetails("A gridUrl was not provided; spot (" + spot.toString() + ") REQUIRES gridUrl"));
        isValid = false;
    }
    if (!setTestReportDirectory(localParam)) {
        TestParam.log.log(Level.SEVERE, logDetails(
                "Could not create testReportDirectory (" + testReportDirectory.getCanonicalPath() + ")"));
        isValid = false;
    }
    if ((verbosity < 0) || (verbosity > 10)) {
        TestParam.log.log(Level.SEVERE, logDetails("Invalid verbosity; must be 0-10"));
        isValid = false;
    }
    setIsValid(isValid);
    return isValid;
}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

@Before
public synchronized void setUp() throws Exception {
    //set default driver

    if (this.isMultiThreaded) {
        this.libs = null;
        this.createLogFile();
        this.varmap = BaseHandler.threadData.get(threadIndex);
        if (this.libs == null || this.libs.isEmpty()) {
            this.libs = this.parseTagLib();
        }/*from w  ww . jav a 2 s. co m*/

    } else {
        this.libs = this.parseTagLib();
        this.varmap = BaseHandler.getVarMap();
        this.threadIndex = this.varmap.get("datasetIndex");
    }

    this.printMessage("####### SELENIUM TEST STARTED #################");

    this.printMessage("####### Dataset:" + this.varmap.values());

    this.timer = new PrintTime();
    File file = null;
    //driver = new FirefoxDriver();

    v_driver = getDeclaredVariable("driver");
    if (v_driver == null || v_driver.isEmpty()) {
        v_driver = ConfigLoader.getConfig("SELENIUM_DRIVER");
        if (v_driver == null || v_driver.isEmpty()) {
            v_driver = "firefox";
        }
    }
    String driver_path = getDeclaredVariable("driver_path");
    if (v_driver.equalsIgnoreCase("chrome")) {
        if (TestEngine.suite != null) {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
            if (!file.exists()) {
                String chrome_path = TestEngine.suite.getWorkspace() + TestEngine.suite.getJobname()
                        + "/lib/chromedriver.exe";
                file = new File(chrome_path);
                if (!file.exists()) {
                    file = new File(TestEngine.suite.getWorkspace() + "/lib/chromedriver.exe");
                }
            }
        } else {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
        }
        this.printMessage("Chrome Driver Path=" + file.getAbsolutePath());
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        //capability.setCapability("chrome.switches", Arrays.asList("--allow-running-insecure-content=true"));
        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            file = new File(ConfigLoader.getWmRoot() + "/lib/chromedriver_mac");
            System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/chrome"); //for linux "chrome.switches", "--verbose"
            capability.setCapability("chrome.switches", "--verbose");
            driver = new ChromeDriver(capability);

        } else {
            driver = new ChromeDriver(capability);
        }
    } else if (v_driver.equalsIgnoreCase("ie")) {
        if (is64bit()) {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : ie_driver_path64bit);
        } else {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : ie_driver_path32bit);
        }
        this.printMessage("##### IE DRIVER PATH=" + file.getAbsolutePath());
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability("platform", Platform.WINDOWS);
        capability.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        if (is64bit()) {
            capability.setCapability("iedriver-version", "x64_2.41.0");
        }
        //capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        driver = new InternetExplorerDriver(capability);
        maxTimeToWait = maxTimeToWait * 5;
        this.isIE = true;

    } else if (v_driver.equalsIgnoreCase("firefox")) {

        /*file = new File("firebug-1.8.1.xpi");
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("security.mixed_content.block_active_content", false);
        firefoxProfile.setPreference("security.mixed_content.block_display_content", true);
        firefoxProfile.setPreference("browser.cache.disk.enable", true);
        firefoxProfile.addExtension(file);
        firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
        driver = new FirefoxDriver(firefoxProfile);
        */
        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            DesiredCapabilities capability = DesiredCapabilities.firefox();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/firefox"); //for linux
            //capability.setCapability("binary", "/ms/dist/fsf/PROJ/firefox/16.0.0/bin/firefox"); //for linux

            //capability.setCapability("binary", "C:\\Program Files\\Mozilla  Firefox\\msfirefox.exe"); //for windows                
            driver = new FirefoxDriver(capability);

        } else {
            //
            driver = new FirefoxDriver();
        }
    } else if (v_driver.equalsIgnoreCase("safari")) {

        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            this.printMessage("#####STARTING Safri in Mac ####");
            DesiredCapabilities capability = DesiredCapabilities.safari();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/safari"); //for linux
            driver = new SafariDriver(capability);

        } else {
            // Read Instruction for Safari Extension
            //http://rationaleemotions.wordpress.com/2012/05/25/working-with-safari-driver/
            // Get certificate from https://docs.google.com/folder/d/0B5KGduKl6s6-ZGpPZlA0Rm03Nms/edit
            this.printMessage("#####STARTING Safri in Windows ####");
            String safari_install_path = "C:\\Program Files (x86)\\Safari\\";
            DesiredCapabilities capability = DesiredCapabilities.safari();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", safari_install_path + "Safari.exe"); //for windows 
            //capability.setCapability(SafariDriver.DATA_DIR_CAPABILITY, "C:\\Program Files (x86)\\Safari\\SafariData");
            //System.setProperty("webdriver.safari.driver", safari_install_path+"SafariDriver.safariextension\\");
            driver = new SafariDriver(capability);

        }
    } else if (v_driver.equalsIgnoreCase("htmlunit")) {
        DesiredCapabilities capability = DesiredCapabilities.htmlUnit();
        capability.setJavascriptEnabled(true);
        //capability.setCapability("browserName","chrome");
        //capability.setBrowserName(BrowserVersion.CHROME);
        driver = new HtmlUnitDriver(capability);

    } else {
        file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
        driver = new ChromeDriver();
    }

    baseUrl = ConfigLoader.getConfig("BASE_APPLICATION_URL");
    baseUrl = baseUrl.replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV"));
    for (Cookie cookie : driver.manage().getCookies()) {
        printMessage("name=" + cookie.getName());
        printMessage("domain=" + cookie.getDomain());
        printMessage("path=" + cookie.getPath());
        printMessage("value=" + cookie.getValue());
    }
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    if (this.varmap.get("browserwidth") != null) {
        try {
            browserwidth = new Integer(this.varmap.get("browserwidth"));
        } catch (Exception e) {
            browserwidth = 1020;
        }
    }
    driver.manage().window().setSize(new Dimension(browserwidth, (int) screenSize.getHeight()));
    String removecookie = getDeclaredVariable("removecookie");
    if (this.isEmptyValue(removecookie) || removecookie.equalsIgnoreCase("yes")) {
        driver.manage().deleteAllCookies();
    }
    driver.manage().timeouts().implicitlyWait(maxTimeToWait, TimeUnit.SECONDS);
    driverList.put(this.threadIndex, driver);
    this.resetTestResult();

}

From source file:com.tractionsoftware.reshoot.util.TractionWebdriverUtils.java

License:Apache License

public static RemoteWebDriver createIEDriver(String version) {
    DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
    try {//from   w w  w  .ja  v a  2s  .c o m
        capability.setVersion(version);
        capability.setPlatform(Platform.WINDOWS);
        capability.setBrowserName("internet explorer");
        return new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

From source file:com.vaadin.testbench.parallel.BrowserUtil.java

/**
 * Returns a human readable identifier of the platform described by the
 * given capabilities. Used mainly for screenshots
 *
 * @param capabilities//w w w .jav a  2s.c  o  m
 * @return a human readable string describing the platform
 */
public static String getPlatform(Capabilities capabilities) {
    if (capabilities == null) {
        return "Unknown";
    }
    try {
        Platform p = capabilities.getPlatform();
        if (p == Platform.WIN8 || p == Platform.WINDOWS || p == Platform.VISTA || p == Platform.XP) {
            return "Windows";
        } else if (p == Platform.MAC) {
            return "Mac";
        }

    } catch (Exception e) {
    }
    Object rawPlatform = capabilities.getCapability(CapabilityType.PLATFORM);
    if (rawPlatform == null) {
        return "Unknown";
    }
    return rawPlatform.toString();
}

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

License:Apache License

protected void maybeInitChromeDriverService() {
    try {//from   w w  w.  ja va2s  . com
        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);
    }
}