Example usage for org.openqa.selenium.remote CapabilityType PLATFORM

List of usage examples for org.openqa.selenium.remote CapabilityType PLATFORM

Introduction

In this page you can find the example usage for org.openqa.selenium.remote CapabilityType PLATFORM.

Prototype

String PLATFORM

To view the source code for org.openqa.selenium.remote CapabilityType PLATFORM.

Click Source Link

Usage

From source file:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java

public static void main(String[] args) {
    try {/*  w  w  w. j  a v a  2 s  .co m*/

        Integer pozSpam = 0;
        Integer pozTrash = 0;
        Integer pozHelp = 0;
        Integer pozCompose = 0;
        Integer pozNewFolder = 0;

        System.setProperty("webdriver.chrome.driver",
                "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe");
        System.setProperty("webdriver.chrome.logfile",
                "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("test-type");
        options.addArguments("--start-maximized");
        options.addArguments("--disable-web-security");
        options.addArguments("--no-proxy-server");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-notifications");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("--disable-plug-in");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("credentials_enable_service", false);
        prefs.put("profile.password_manager_enabled", false);

        options.setExperimentalOption("prefs", prefs);

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
        capabilities.setCapability(CapabilityType.PLATFORM, "WIN10");

        driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://mail.yahoo.com");
        driver.manage().window().maximize();
        WebElement usernameElem = driver.findElement(By.id("login-username"));
        usernameElem.sendKeys("andadeacu@yahoo.com");

        WebElement Next = driver.findElement(By.name("signin"));
        Next.click();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']"));
        boolean selected = passwordElem.isSelected();

        CharSequence password = "";
        passwordElem.sendKeys(password);

        WebElement login = driver.findElement(By.id("login-signin"));

        login.click();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']"));

        List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li"));

        for (int j = 0; j < childs.size(); j++) {

            WebElement spamElem = childs.get(j);
            /*
            * System.out.println("ancorele " + j + " " + " tag " +
            * childs.get(j).getTagName() + " " + childs.get(j).getText() +
            * " " + childs.get(j).getAttribute("innerHTML"));
             */
            if (spamElem.getText().startsWith(("Spam"))) {

                pozSpam = j;

            }
            if (spamElem.getText().startsWith(("Help"))) {

                pozHelp = j;

            }
            if (spamElem.getText().startsWith(("Compose"))) {

                pozCompose = j;

            }
            if (spamElem.getText().startsWith(("New"))) {

                pozNewFolder = j;

            }

            if (spamElem.getText().startsWith(("Trash"))) {
                System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText());
                pozTrash = j;
                break;
            }

        }
        System.out.println(pozTrash);

        WebElement trashElem = childs.get(pozTrash);

        /*
        * System.out.println("trashElem " + trashElem.getTagName() +
        * " text " + trashElem.getText() + " class_atribute " +
        * trashElem.getAttribute("class") + " data_action " +
        * trashElem.getAttribute("data_action"));
         */
        WebElement trashFolderEmpty = trashElem.findElement(
                By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon  icon-delete']"));

        /*
        * System.out.println("spamEmptyFolder " +
        * spamFolderEmpty.getTagName() + " text " +
        * spamFolderEmpty.getText() + " location " +
        * spamFolderEmpty.isEnabled());
         */
        trashFolderEmpty.click();

        int timeOut = 5;

        WebDriverWait wait = new WebDriverWait(driver, timeOut);

        driver.switchTo().alert();

        /* for Chrome is not working 
        WebElement modalPopUp = driver.findElement(By
            .className("modal-hd yui3-widget-hd"));
                
        */

        WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default"));

        /*
        * <button id="okayModalOverlay" class="btn left right default"
        * title="OK" role="button" data-action="ok">OK</button>
         */
        btnDeleteSpamEmails.click();

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        // verify msg after you delete spam emails
        System.out.println(driver.getCurrentUrl());

        driver.quit();
    } catch (Exception ex) {

        ex.printStackTrace();
        driver.quit();
    }

}

From source file:com.ecofactor.qa.automation.platform.ops.impl.AbstractDriverOperations.java

License:Open Source License

/**
 * Sets the hub capabilities./*w w w  . j  a  va2  s  .c o  m*/
 * @param capabilities the new hub capabilities
 */
protected void setHubCapabilities(final DesiredCapabilities capabilities) {

    capabilities.setCapability(CapabilityType.BROWSER_NAME, getDeviceName());
    if (hasPlatformParam()) {
        capabilities.setCapability(CapabilityType.PLATFORM, getPlatformName());
    }
    if (hasVersionParam()) {
        capabilities.setCapability(CapabilityType.VERSION, getVersion());
    }
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.IOSOperations.java

License:Open Source License

/**
 * Creates the device driver.//w  w w.ja va  2s.  co m
 * @return the web driver
 * @throws DeviceException the device exception
 * @see com.ecofactor.qa.automation.mobile.ops.impl.AbstractMobileOperations#createDeviceDriver()
 */
@Override
protected WebDriver createDeviceDriver() throws DeviceException {

    WebDriver driver = null;
    if (!hasErrors) {
        try {
            final File classpathRoot = new File(System.getProperty("user.dir"));
            final File app = new File(classpathRoot, "/EcoFactor_iOS/EcoFactorNew.zip");
            setLogString("Application Path: " + app.getPath(), true);
            final DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "iphone");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, JenkinsParamUtil.getDeviceName());
            capabilities.setCapability(CapabilityType.VERSION, "7.0");
            capabilities.setCapability(CapabilityType.PLATFORM, SystemUtil.getOSType());
            capabilities.setCapability("cleanSession", true);
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
            driver = new SwipeableWebDriver(new URL(getAppiumHostUrl()), capabilities);
        } catch (Exception ex) {
            if (ex.getCause() instanceof HttpHostConnectException) {
                setErrorMsg("Appium not started");
                setLogString(errorMsg, true);
                hasErrors = true;
                throw new DeviceException("\033[41;1m" + getErrorMsg());
            }
            setLogString("\033[41;1mERROR in initialze (" + ex.getMessage() + ")", true);
            throw new DeviceException("ERROR in initialze (" + ex.getMessage() + ")");
        }
    }
    return driver;
}

From source file:com.ecofactor.qa.automation.platform.util.SeleniumDriverUtil.java

License:Open Source License

/**
 * Sets the hub capabilities.//from  w w w.j a  v  a  2 s  .  co  m
 * @param capabilities the new hub capabilities
 */
private static void setHubCapabilities(final DesiredCapabilities capabilities) {

    if (hasPlatformParam()) {
        capabilities.setCapability(CapabilityType.PLATFORM, getPlatformName());
    }
    if (hasVersionParam()) {
        capabilities.setCapability(CapabilityType.VERSION, getVersion());
    }
}

From source file:com.photon.phresco.Screens.BaseScreen.java

License:Apache License

public void instantiateBrowser(String selectedBrowser, String selectedPlatform, String applicationURL,
        String applicationContext) throws ScreenException, MalformedURLException {

    URL server = new URL("http://localhost:4444/wd/hub/");
    if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_CHROME)) {
        log.info("-------------***LAUNCHING GOOGLECHROME***--------------");
        try {//  w  w  w  .j a  v  a2  s .  co  m

            capabilities = new DesiredCapabilities();
            capabilities.setBrowserName("chrome");

        } catch (Exception e) {
            e.printStackTrace();
        }

    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_IE)) {
        log.info("---------------***LAUNCHING INTERNET EXPLORE***-----------");
        try {
            capabilities = new DesiredCapabilities();
            capabilities.setJavascriptEnabled(true);
            capabilities.setBrowserName("iexplorer");
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_OPERA)) {
        log.info("-------------***LAUNCHING OPERA***--------------");
        try {

            capabilities = new DesiredCapabilities();
            capabilities.setBrowserName("opera");
            capabilities.setCapability("opera.autostart ", true);

            System.out.println("-----------checking the OPERA-------");
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_SAFARI)) {
        log.info("-------------***LAUNCHING SAFARI***--------------");
        try {
            capabilities = new DesiredCapabilities();
            capabilities.setBrowserName("safari");
            /*   capabilities.setCapability("safari.autostart ", true);*/
            System.out.println("-----------checking the SAFARI-------");
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_FIREFOX)) {
        log.info("-------------***LAUNCHING FIREFOX***--------------");
        capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("firefox");
    } else if (selectedBrowser.equalsIgnoreCase(Constants.HTML_UNIT_DRIVER)) {
        log.info("-------------***HTML_UNIT_DRIVER***--------------");
        capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("htmlunit");
        /*URL server = new URL("http://testVM:4444/wd/hub");
        new RemoteWebDriver(new Url("http://testVM:4444/wd/hub");*/

        System.out.println("-----------checking the HTML_UNIT_DRIVER-------");
        // break;
        // driver = new RemoteWebDriver(server, capabilities);

    } else {
        throw new ScreenException("------Only FireFox,InternetExplore and Chrome works-----------");
    }
    if (selectedPlatform.equalsIgnoreCase("WINDOWS")) {
        capabilities.setCapability(CapabilityType.PLATFORM, Platform.WINDOWS);

    } else if (selectedPlatform.equalsIgnoreCase("LINUX")) {
        capabilities.setCapability(CapabilityType.PLATFORM, Platform.LINUX);

    } else if (selectedPlatform.equalsIgnoreCase("MAC")) {
        capabilities.setCapability(CapabilityType.PLATFORM, Platform.MAC);

    }
    driver = new RemoteWebDriver(server, capabilities);
    driver.get(applicationURL + applicationContext);

}

From source file:com.rmn.qa.AutomationRequestMatcherTest.java

License:Open Source License

@Test
// Tests that OS matching on a node works correctly
public void testRequestMatchingOs() throws IOException, ServletException {
    String browser = "firefox";
    Platform os = Platform.LINUX;//from  w  w w. j  a  va  2  s . c  o  m
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid", nodeId, null, null, new Date(), 50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String, Object> config = Maps.newHashMap();
    config.put(AutomationConstants.INSTANCE_ID, nodeId);
    proxy.setConfig(config);
    Map<String, Object> capabilities = Maps.newHashMap();
    capabilities.put(CapabilityType.BROWSER_NAME, "firefox");
    capabilities.put(CapabilityType.PLATFORM, os);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,
            new AutomationRunRequest(null, null, browser, null, os));

    Assert.assertEquals("Thread count should be correct due to matching OS", 10, freeThreads);
}

From source file:com.rmn.qa.AutomationRequestMatcherTest.java

License:Open Source License

@Test
// Tests that OS NOT matching on a node works correctly
public void testRequestNonMatchingOs() throws IOException, ServletException {
    String browser = "firefox";
    Platform os = Platform.LINUX;/* ww  w  .j ava 2s  . com*/
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid", nodeId, null, null, new Date(), 50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String, Object> config = Maps.newHashMap();
    config.put(AutomationConstants.INSTANCE_ID, nodeId);
    proxy.setConfig(config);
    Map<String, Object> capabilities = Maps.newHashMap();
    capabilities.put(CapabilityType.BROWSER_NAME, "firefox");
    capabilities.put(CapabilityType.PLATFORM, Platform.WINDOWS);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,
            new AutomationRunRequest(null, null, browser, null, os));

    Assert.assertEquals("Thread count should be 0 due to non-matching OS", 0, freeThreads);
}

From source file:com.rmn.qa.AutomationRunContextTest.java

License:Open Source License

@Test
// Tests that the correct node count is returned when tests don't have a UUID
public void testNodesFreeNoUuid() {
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);// ww w .  j ava2 s.  c om
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String, Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM, "linux");
    capabilities.put(CapabilityType.BROWSER_NAME, "chrome");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot, 5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(5, freeThreads);
}

From source file:com.rmn.qa.AutomationRunContextTest.java

License:Open Source License

@Test
// Tests that the correct node count is returned when tests don't have a UUID
public void testNodesFreeWithUuid() {
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);/*  w w w . j a  v a  2 s. c o m*/
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String, Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM, "linux");
    capabilities.put(CapabilityType.BROWSER_NAME, "chrome");
    capabilities.put(AutomationConstants.UUID, "testUuid");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot, 5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(5, freeThreads);
}

From source file:com.rmn.qa.AutomationRunContextTest.java

License:Open Source License

@Test
// Tests that a new run is counted instead of tests in progress
public void testNewRunIsCounted() {
    String uuid = "testUuid";
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);//  www.j  a va 2  s .co  m
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String, Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM, "linux");
    capabilities.put(CapabilityType.BROWSER_NAME, "chrome");
    capabilities.put(AutomationConstants.UUID, uuid);
    AutomationRunRequest request = new AutomationRunRequest(uuid, 10, "chrome");
    runContext.addRun(request);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot, 5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(0, freeThreads);
}