@Parameters("browser")
 @Test
 public void dropdownTest(String b) throws MalformedURLException, Throwable {
   DesiredCapabilities cap = null;
   if (b.equals("firefox")) {
     cap = DesiredCapabilities.firefox();
     cap.setBrowserName("firefox");
     cap.setPlatform(Platform.ANY);
   } else if (b.equals("chrome")) {
     cap = DesiredCapabilities.chrome();
     cap.setBrowserName("chrome");
     cap.setPlatform(Platform.WINDOWS);
   }
   RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wb/hub"), cap);
   driver.get("http://newtours.demoaut.com"); // Dropdown prgm copy paste.
   driver.findElement(By.linkText("REGISTER")).click();
   Thread.sleep(3000);
   WebElement drop = driver.findElement(By.name("country"));
   List<WebElement> dropdown = drop.findElements(By.tagName("option"));
   int a = MyRandomNo(dropdown.size() - 1);
   dropdown.get(a).click();
   if (dropdown.get(a).isSelected()) {
     System.out.println(dropdown.get(a).getText() + "is active");
   } else {
     System.out.println(dropdown.get(a).getText() + "is not active");
   }
 }
Beispiel #2
0
  @Parameters("browser")
  @Test
  public void testLogin(String browser) throws MalformedURLException, InterruptedException {
    System.out.println(browser);

    DesiredCapabilities cap = null;

    if (browser.equals("firefox")) {
      cap = DesiredCapabilities.firefox();
      cap.setBrowserName("firefox");
      cap.setPlatform(Platform.ANY);
    } else if (browser.equals("chrome")) {
      cap = DesiredCapabilities.chrome();
      cap.setBrowserName("chrome");
      cap.setPlatform(Platform.ANY);
    } else if (browser.equals("iexplorer")) {
      cap = DesiredCapabilities.internetExplorer();
      cap.setBrowserName("iexplore");
      cap.setPlatform(Platform.WINDOWS);
    }
    driver = new RemoteWebDriver(new URL("http://192.168.1.133:5555/wd/hub"), cap);
    // driver.manage().window().maximize();
    driver.get("http://gmail.com");
    driver.findElement(By.id("Email")).sendKeys("Hello");
    Thread.sleep(10000L);
  }
  @Parameters("browser")
  @Test
  public void dropdownTest(String b) throws MalformedURLException {
    System.out.println(b);
    DesiredCapabilities cap = null;
    if (b.equals("firefox")) {
      cap = DesiredCapabilities.firefox();
      cap.setBrowserName("firefox");
      cap.setPlatform(Platform.ANY);
    } else if (b.equals("chrome")) {
      cap = DesiredCapabilities.chrome();
      cap.setBrowserName("chrome");
      cap.setPlatform(Platform.WINDOWS);
    }
    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
    driver.get("http://newtours.demoaut.com");
    driver.findElement(By.linkText("REGISTER")).click();
    WebElement drop = driver.findElement(By.name("country"));
    List<WebElement> dropdown = drop.findElements(By.tagName("option"));
    System.out.println(dropdown.size());
    for (int i = 0; i < dropdown.size(); i++) {
      dropdown.get(i).click();

      if (dropdown.get(i).isSelected()) {
        System.out.println(dropdown.get(i).getText() + " is active");
      } else {
        System.out.println(dropdown.get(i).getText() + " is inactive");
      }
    }
  }
  @Test
  public void testRemoteWebDriver() {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setPlatform(Platform.ANY);
    cap.setBrowserName("opera");
    RemoteWebDriver driver = null;
    try {
      driver = new RemoteWebDriver(new URL("http://192.168.1.176:4444/wd/hub"), cap);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    // Navigate to Google using firefox
    driver.get("http://www.google.com");
    driver
        .findElement(By.name("q"))
        .sendKeys("selenium automation using grid on windows 8.1 with firefox machine");
    driver = (RemoteWebDriver) new Augmenter().augment(driver);
    File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
      FileUtils.copyFile(srcFile, new File("remoteScreenshot.jpg"));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println(driver.getCurrentUrl());
    driver.quit();
  }
  public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) {
    DesiredCapabilities capability = null;
    capability = DesiredCapabilities.htmlUnit();

    if (webDriverConfig.isEnableJavascript()) {
      capability.setJavascriptEnabled(true);
    } else {
      capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (webDriverConfig.getBrowserVersion() != null) {
      capability.setVersion(webDriverConfig.getBrowserVersion());
    }

    if (webDriverConfig.getWebPlatform() != null) {
      capability.setPlatform(webDriverConfig.getWebPlatform());
    }

    if (webDriverConfig.getProxyHost() != null) {
      Proxy proxy = webDriverConfig.getProxy();
      capability.setCapability(CapabilityType.PROXY, proxy);
    }

    return capability;
  }
  public RemoteWebDriver getRemoteDriver(DesiredCapabilities d) {

    String browserVersion = configurator.getBrowserVersion();
    if (browserVersion != null) {
      d.setVersion(browserVersion);
    }

    d.setPlatform(configurator.getPlatform());
    return new RemoteWebDriver(configurator.getGridUrl(), d);
  }
  private void configureBrowserStackCapabilities(DesiredCapabilities capabilities) {
    List<String> browserStackProperties =
        filter(
            having(on(String.class), startsWith("browserstack.")), environmentVariables.getKeys());
    for (String propertyKey : browserStackProperties) {
      String preparedPropertyKey = getPreparedPropertyKey(propertyKey);
      String propertyValue = environmentVariables.getProperty(propertyKey);
      if (isNotEmpty(propertyValue)) {
        capabilities.setCapability(preparedPropertyKey, propertyValue);
        capabilities.setCapability(propertyKey, propertyValue);
      }
    }

    String remotePlatform = environmentVariables.getProperty("remote.platform");
    if (isNotEmpty(remotePlatform)) {
      capabilities.setPlatform(Platform.valueOf(remotePlatform));
    }
  }
  /** @param br purpose: set desiredCapanbilities */
  public DesiredCapabilities setDesiredCapabilites(String browserCapability) {
    capabilities = new DesiredCapabilities();

    switch (browserCapability) {
      case "firefox":
        capabilities.setBrowserName("firefox");
        capabilities.setPlatform(Platform.ANY);
        break;

      default:
        try {
          throw new Throwable("no capalities matched");
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          logger.error("no capabilites found", e);
        }
    }
    return capabilities;
  }
  @BeforeClass
  public void init() {
    baseUrl = PropertyLoader.loadProperty("site.url");
    gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName(PropertyLoader.loadProperty("browser.name"));
    capabilities.setVersion(PropertyLoader.loadProperty("browser.version"));
    String platform = PropertyLoader.loadProperty("browser.platform");
    if (!(null == platform || "".equals(platform))) {
      capabilities.setPlatform(Platform.valueOf(PropertyLoader.loadProperty("browser.platform")));
    }

    if (!(null == gridHubUrl || "".equals(gridHubUrl))) {
      driver = WebDriverFactory.getDriver(gridHubUrl, capabilities);
    } else {
      driver = WebDriverFactory.getDriver(capabilities);
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }
Beispiel #10
0
  @SuppressWarnings({"unchecked"})
  protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {

    ImmutableMap.Builder<String, Capabilities> paramBuilder =
        new ImmutableMap.Builder<String, Capabilities>();
    paramBuilder.put("desiredCapabilities", desiredCapabilities);
    if (requiredCapabilities != null) {
      paramBuilder.put("requiredCapabilities", requiredCapabilities);
    }
    Map<String, ?> parameters = paramBuilder.build();

    Response response = execute(DriverCommand.NEW_SESSION, parameters);

    Map<String, Object> rawCapabilities = (Map<String, Object>) response.getValue();
    DesiredCapabilities returnedCapabilities = new DesiredCapabilities();
    for (Map.Entry<String, Object> entry : rawCapabilities.entrySet()) {
      // Handle the platform later
      if (CapabilityType.PLATFORM.equals(entry.getKey())) {
        continue;
      }
      returnedCapabilities.setCapability(entry.getKey(), entry.getValue());
    }
    String platformString = (String) rawCapabilities.get(CapabilityType.PLATFORM);
    Platform platform;
    try {
      if (platformString == null || "".equals(platformString)) {
        platform = Platform.ANY;
      } else {
        platform = Platform.valueOf(platformString);
      }
    } catch (IllegalArgumentException e) {
      // The server probably responded with a name matching the os.name
      // system property. Try to recover and parse this.
      platform = Platform.extractFromSysProperty(platformString);
    }
    returnedCapabilities.setPlatform(platform);

    capabilities = returnedCapabilities;
    sessionId = new SessionId(response.getSessionId());
  }
 private DesiredCapabilities getBrowserCapabilities(Browser browser) {
   DesiredCapabilities capabilities = new DesiredCapabilities();
   if (browser.getName().equals("internet explorer")) {
     capabilities.setCapability(
         InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
   } else if (Browser.CHROME == browser) {
     ChromeOptions options = new ChromeOptions();
     options.addArguments(
         Arrays.asList("allow-running-insecure-content", "ignore-certificate-errors"));
     options.addArguments("--start-maximized");
     capabilities.setCapability(ChromeOptions.CAPABILITY, options);
   } else {
     FirefoxProfile profile = new FirefoxProfile();
     if (Browser.MOBILE == browser) {
       profile.setPreference(
           "general.useragent.override",
           "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");
       profile.setAcceptUntrustedCertificates(true);
     }
     if (Browser.NOCOOKIE == browser) {
       profile.setPreference("network.cookie.cookieBehavior", 2);
     }
     profile.setEnableNativeEvents(true);
     capabilities.setCapability(FirefoxDriver.PROFILE, profile);
   }
   if (Browser.NOJS == browser) {
     capabilities.setJavascriptEnabled(false);
   } else {
     capabilities.setJavascriptEnabled(true);
   }
   capabilities.setBrowserName(browser.getName());
   if (StringUtils.isNotEmpty(browser.getVersion())) {
     capabilities.setVersion(browser.getVersion());
   }
   capabilities.setPlatform(Platform.ANY);
   capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
   capabilities.setCapability("trustAllSSLCertificates", true);
   return capabilities;
 }
  /*
   * Helper method to set version and platform for a specific browser
   *
   * @param capability : DesiredCapabilities object coming from the selected
   * browser
   *
   * @param version : browser version
   *
   * @param platform : browser platform
   *
   * @return DesiredCapabilities
   */
  private static DesiredCapabilities setVersionAndPlatform(
      DesiredCapabilities capability, String version, String platform) {
    if (MAC.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.MAC);
    } else if (LINUX.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.LINUX);
    } else if (XP.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.XP);
    } else if (VISTA.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.VISTA);
    } else if (WINDOWS.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.WINDOWS);
    } else if (ANDROID.equalsIgnoreCase(platform)) {
      capability.setPlatform(Platform.ANDROID);
    } else {
      capability.setPlatform(Platform.ANY);
    }

    if (version != null) {
      capability.setVersion(version);
    }
    return capability;
  }
 public void setPlatform(String platform) {
   if (!StringUtils.equalsIgnoreCase(platform, "none")) {
     capabilities.setPlatform(Platform.valueOf(platform));
   }
 }