@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");
   }
 }
  @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");
      }
    }
  }
  private WebDriver setRemoteServer(Map<String, String> getsessionConfig) {
    DesiredCapabilities cap = null;
    browser = System.getProperty("browser");

    if (browser == null) browser = getsessionConfig.get("browser").toString();
    if (browser.equalsIgnoreCase("firefox")) {
      cap = DesiredCapabilities.firefox();
    } else if (browser.equalsIgnoreCase("chrome")) {
      cap = DesiredCapabilities.chrome();
    } else if (browser.equalsIgnoreCase("ie")
        || browser.equalsIgnoreCase("internetexplorer")
        || browser.equalsIgnoreCase("InternetExplorer")) {
      cap = DesiredCapabilities.internetExplorer();
    }

    String seleniumhubAddress = System.getProperty("hub");
    if (seleniumhubAddress == null) {
      seleniumhubAddress = getsessionConfig.get("seleniumserverhost1");
    }
    URL serverhost = null;

    try {
      serverhost = new URL(seleniumhubAddress);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    cap.setJavascriptEnabled(true);
    return new RemoteWebDriver(serverhost, cap);
  }
 private void doSomething() {
   WebDriver driver = WebDriverFactory.getDriver(DesiredCapabilities.firefox());
   driver.get("http://seleniumhq.org/");
   driver.findElement(By.name("q")).sendKeys("selenium");
   driver.findElement(By.id("submit")).click();
   new WebDriverWait(driver, 30).until(ExpectedConditions.titleContains("Google Custom Search"));
 }
 // mark the grid 100% busy = having 1 firefox test running.
 @Test
 public void test() throws MalformedURLException, InterruptedException {
   DesiredCapabilities ff = DesiredCapabilities.firefox();
   runningOne = new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
   runningOne.get(hubURL + "/grid/console");
   Assert.assertEquals(runningOne.getTitle(), "Grid overview");
 }
Example #6
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);
  }
  @BeforeClass
  public static void prepare() throws Exception {

    hub = GridTestHelper.getHub();
    registry = hub.getRegistry();
    registry.setThrowOnCapabilityNotPresent(false);

    remote = GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
    remote.setMaxConcurrent(100);

    DesiredCapabilities caps = null;

    // firefox

    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, locationFF7);
    caps.setVersion("7");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, locationFF3);
    caps.setVersion("3");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, "should be overwritten");
    caps.setVersion("20");
    remote.addBrowser(caps, 1);

    // chrome

    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", locationChrome27);
    caps.setVersion("27");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", locationChrome29);
    caps.setVersion("29");
    remote.addBrowser(caps, 2);
    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", "should be overwritten");
    caps.setVersion("30");
    remote.addBrowser(caps, 1);

    remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
    remote.startRemoteServer();
    remote.sendRegistrationRequest();
    RegistryTestHelper.waitForNode(registry, 1);
  }
Example #8
0
  protected void setUp() throws Exception {
    if (!isConfigured()) {
      DOMConfigurator.configure("log4j.xml");
      iConfigured = true;
    }
    configProperties = new Properties();
    try {
      configProperties.load(
          TestBase.class.getClassLoader().getResourceAsStream("config.properties"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    useRemote = Boolean.parseBoolean(configProperties.getProperty("use_remote"));

    bro = configProperties.getProperty("browser");
    chromeDriver = configProperties.getProperty("chromedriver");
    ieDriver = configProperties.getProperty("iedriver");

    if (useRemote) {
      File profileDir = new File(getClass().getResource("/seleniumProfile").getFile());
      FirefoxProfile profile = new FirefoxProfile(profileDir);
      DesiredCapabilities capabilities = DesiredCapabilities.firefox();
      capabilities.setCapability(FirefoxDriver.PROFILE, profile);
      capabilities.setCapability("binary", "/usr/bin/firefox");
      String remoteUrl = configProperties.getProperty("selenium_remote_url");
      driver = new RemoteWebDriver(new URL(remoteUrl), capabilities);
      ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
    } else {
      if (bro.toLowerCase().equals("firefox")) {

        File profileDir = null;
        profileDir = new File(getClass().getResource("/seleniumProfile").getFile());
        FirefoxProfile profile = new FirefoxProfile(profileDir);
        driver = new FirefoxDriver(profile);
      }
      if (bro.toLowerCase().equals("chrome")) {
        System.setProperty("webdriver.chrome.driver", chromeDriver);
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("download.default_directory", "target");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);
        caps.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(caps);
      }
      if (bro.toLowerCase().equals("ie")) {
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(
            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        System.setProperty("webdriver.ie.driver", ieDriver);
        capabilities.setCapability("ignoreZoomSetting", true);
        capabilities.setCapability("nativeEvents", false);
        driver = new InternetExplorerDriver(capabilities);
      }
    }
    int timeout = Integer.parseInt(configProperties.getProperty("driver_timeout"));
    driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
  }
Example #9
0
 private void InitializeFirefoxDriver() {
   FirefoxCapabilities =
       FirefoxCapabilities == null ? DesiredCapabilities.firefox() : FirefoxCapabilities;
   FirefoxDriverProfile =
       FirefoxDriverProfile == null ? new FirefoxProfile() : FirefoxDriverProfile;
   FirefoxDriverBinary = FirefoxDriverBinary == null ? new FirefoxBinary() : FirefoxDriverBinary;
   Driver = new FirefoxDriver(FirefoxDriverBinary, FirefoxDriverProfile, FirefoxCapabilities);
 }
  public static DesiredCapabilities of(Browser browser) {
    if (browser == null) {
      return null;
    }

    DesiredCapabilities caps;

    switch (browser) {
      case chrome:
        caps = DesiredCapabilities.chrome();
        break;

      case ff:
        caps = DesiredCapabilities.firefox();
        //        caps.setCapability(FirefoxDriver.MARIONETTE,
        //
        // Boolean.getBoolean(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE));
        break;

      case htmlunit:
        caps = DesiredCapabilities.htmlUnit();
        caps.setJavascriptEnabled(false);
        break;

      case htmlunit_js:
        caps = DesiredCapabilities.htmlUnit();
        caps.setJavascriptEnabled(true);
        break;

      case ie:
        caps = DesiredCapabilities.internetExplorer();
        break;

      case operablink:
        caps = DesiredCapabilities.operaBlink();
        break;

      case phantomjs:
        caps = DesiredCapabilities.phantomjs();
        break;

      case safari:
        caps = DesiredCapabilities.safari();
        break;

      default:
        throw new RuntimeException("Cannot determine browser config to use");
    }

    String version = System.getProperty("selenium.browser.version");
    if (version != null) {
      caps.setVersion(version);
    }

    caps.setCapability(HAS_NATIVE_EVENTS, Boolean.getBoolean("selenium.browser.native_events"));

    return caps;
  }
 @Before
 public void setUp() throws Exception {
   //	    driver = new FirefoxDriver();
   DesiredCapabilities capability = DesiredCapabilities.firefox();
   driver = new RemoteWebDriver(new URL("http://10.2.1.3:4444/wd/hub"), capability);
   baseUrl = "http://localhost/citsmart";
   driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
   login = new LoginSelenium(driver, baseUrl, acceptNextAlert, verificationErrors);
 }
  private static Capabilities getCapabilities(String driverType) {
    DesiredCapabilities result = new DesiredCapabilities();

    switch (driverType) {
      case BrowserType.FIREFOX:
        result = DesiredCapabilities.firefox();
        FirefoxProfile profile =
            (FirefoxProfile) ConfigLoader.config().getProperty("firefox.profile");
        if (profile == null) {
          profile = new FirefoxProfile();
          if (ConfigLoader.config().getBoolean("webdriver.accept.java", true)) {
            profile.setPreference("plugin.state.java", 2);
          }
          if (ConfigLoader.config().getBoolean("webdriver.accept.ssl", true)) {
            profile.setAcceptUntrustedCertificates(true);
            profile.setAssumeUntrustedCertificateIssuer(true);
          }
          if (ConfigLoader.config().getBoolean("webdriver.autodownload", true)) {
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadFiles());
          }
        }
        result.setCapability(FirefoxDriver.PROFILE, profile);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      case BrowserType.IE:
        result = DesiredCapabilities.internetExplorer();
        result.setCapability("ignoreProtectedModeSettings", true);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      case BrowserType.CHROME:
        result = DesiredCapabilities.chrome();
        ChromeOptions chromOptions = new ChromeOptions();
        //
        //	chromOptions.setExperimentalOption("excludeSwitches",Lists.newArrayList("ignore-certificate-errors"));
        chromOptions.addArguments("chrome.switches", "--disable-extensions");
        result.setCapability(ChromeOptions.CAPABILITY, chromOptions);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      default:
        result = new DesiredCapabilities(driverType, "", Platform.ANY);
        break;
    }
    String proxy = ConfigLoader.config().getString("webdriver.proxy");
    if (!Strings.isNullOrEmpty(proxy)) {
      Proxy p = new Proxy();
      p.setHttpProxy(proxy).setSslProxy(proxy);
      result.setCapability(CapabilityType.PROXY, p);
      log.info("Using proxy {}", proxy);
    }
    return concatenate(result, capabilities);
  }
  @Test
  public void whenGetCapabilitiesFromRunningSessionThenItShouldBeSerializable() {
    RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox());

    Capabilities initializedCapabilities = driver.getCapabilities();

    assertTrue(
        "Capabilities obtained from running session should be serializable",
        initializedCapabilities instanceof Serializable);

    driver.quit();
  }
Example #14
0
  public static DesiredCapabilities getCapabilities() {
    // ---------- PROXY Capabilities --------------
    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
    proxy.setSslProxy(proxyUrl + ":" + proxyPort);
    proxy.setFtpProxy(proxyUrl + ":" + proxyPort);
    proxy.setSocksUsername("");
    proxy.setSocksPassword("");

    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(CapabilityType.PROXY, proxy);
    return dc;
  }
  private static void initDriver(String browser) {
    String browserName = System.getProperty("browser", browser);
    String browserRemoteName = System.getProperty("remote", "local");

    if (browserRemoteName.equals("local")) {
      switch (browserName) {
        case "chrome":
        default:
          driver = new ChromeDriver();
          break;
        case "firefox":
          driver = new FirefoxDriver();
          break;
        case "ie":
          driver = new InternetExplorerDriver();
          break;
        case "html":
          driver = new HtmlUnitDriver();
          break;
        case "phantomjs":
          driver = new PhantomJSDriver();
          break;
      }
    } else {
      DesiredCapabilities caps;
      switch (browserName) {
        case "chrome":
        default:
          caps = DesiredCapabilities.chrome();
          break;
        case "firefox":
          caps = DesiredCapabilities.firefox();
          break;
        case "ie":
          caps = DesiredCapabilities.internetExplorer();
          break;
        case "html":
          caps = DesiredCapabilities.htmlUnitWithJs();
          break;
        case "phantomjs":
          caps = DesiredCapabilities.phantomjs();
          break;
      }
      try {
        driver = new RemoteWebDriver(new URL(browserRemoteName), caps);
      } catch (Exception ex) {
        System.out.println(ex.getMessage());
      }
    }

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
  }
 {
   put(DesiredCapabilities.chrome(), "org.openqa.selenium.chrome.ChromeDriver");
   put(DesiredCapabilities.firefox(), "org.openqa.selenium.firefox.FirefoxDriver");
   put(DesiredCapabilities.htmlUnit(), "org.openqa.selenium.htmlunit.HtmlUnitDriver");
   put(
       DesiredCapabilities.internetExplorer(),
       "org.openqa.selenium.ie.InternetExplorerDriver");
   put(DesiredCapabilities.opera(), "com.opera.core.systems.OperaDriver");
   put(DesiredCapabilities.safari(), "org.openqa.selenium.safari.SafariDriver");
   put(DesiredCapabilities.iphone(), "org.openqa.selenium.iphone.IPhoneDriver");
   put(DesiredCapabilities.ipad(), "org.openqa.selenium.iphone.IPhoneDriver");
   put(DesiredCapabilities.phantomjs(), "org.openqa.selenium.phantomjs.PhantomJSDriver");
 }
  @BeforeClass
  public static void setupSauce() {
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("platform", Platform.MAC);

    try {
      // add url to environment variables to avoid releasing with source
      String sauceURL = System.getenv("SAUCELABS_URL");
      driver = new RemoteWebDriver(new URL(sauceURL), capabilities);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
  }
Example #18
0
  @BeforeClass(alwaysRun = true)
  public void prepare() throws Exception {
    hub = GridTestHelper.getHub();

    // register a webdriver
    SelfRegisteringRemote webdriver =
        GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
    webdriver.addBrowser(DesiredCapabilities.firefox(), 1);
    webdriver.startRemoteServer();
    webdriver.sendRegistrationRequest();

    RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
  }
Example #19
0
 @Override
 public WebDriver getWebDriver() {
   if (null != remote_url) {
     try {
       DesiredCapabilities capability = DesiredCapabilities.firefox();
       return new WebAppDriver(
           new RemoteWebDriver(
               new URL("http://localhost:4444/wd/hub"), (Capabilities) capability));
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return new FirefoxDriver();
 }
Example #20
0
 public static DriverConstruct getDriver() {
   DriverConstruct driver;
   if ((driver = webDriverLocal.get()) == null) {
     try {
       driver =
           new DriverConstruct(
               new URL(Proper.GetProperty("sServerGrid")), DesiredCapabilities.firefox());
     } catch (MalformedURLException exc) {
       exc.printStackTrace();
     }
     webDriverLocal.set(driver);
     return driver;
   } else return driver;
 }
  /**
   * private method to load the Firefox Driver
   *
   * @param loadRemote
   */
  private static RemoteWebDriver loadFireFoxDriver(boolean loadRemote) throws Exception {

    log.info("Entering BrowserFactory class loadFireFoxDriver...");
    String loadffProfile = CommonUtils.readFromConfig("loadffProfile");

    RemoteWebDriver remoteDriver = null;

    FirefoxProfile profile = null;

    if ("true".equalsIgnoreCase(loadffProfile)) {
      String profilePath = CommonUtils.readFromConfig("FIREFOXPROFILEDIR");
      File profileDir = new File(profilePath);
      profile = new FirefoxProfile(profileDir);
      profile.setAcceptUntrustedCertificates(false);
    }

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    if (loadRemote) {

      log.info("loading firefox driver in remote");
      log.info("Loading  Remote Run URL " + CommonUtils.readFromConfig("RemoteWebAppUrl"));
      URL url = new URL(CommonUtils.readFromConfig("RemoteWebAppUrl"));

      if ("true".equalsIgnoreCase(loadffProfile)) {
        log.info("loading firefox profile in remote");
        capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        log.info("loading firefox profile in remote sucessful");
      }
      remoteDriver = new RemoteWebDriver(url, capabilities);
      log.info("loading firefox driver in remote successful");

    } else {
      if ("true".equalsIgnoreCase(loadffProfile)) {
        log.info("loading firefox driver with profile");

        remoteDriver = new FirefoxDriver(profile);
        log.info("loading firefox driver loadffProfile profile successfully");
      } else {
        log.info("loading firefox driver without profile");
        remoteDriver = new FirefoxDriver();

        log.info("loading firefox driver without profile successfully");
      }
    }

    log.info("Exiting BrowserFactory class loadFireFoxDriver...");

    return remoteDriver;
  }
  private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null) browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);

    switch (browser) {
      case "firefox":
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference(LANGUAGE_SELECTOR, "en");

        return new FirefoxDriver(profile);
      case "ie":
      case "iexplore":
      case "iexplorer":
        return new InternetExplorerDriver();
      case "chrome":
        Map<String, String> prefs = new HashMap<String, String>();
        prefs.put(LANGUAGE_SELECTOR, "en");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);

        return new ChromeDriver(options);
      case "safari":
        return new SafariDriver();
      case "htmlunit":
        return new HtmlUnitDriver(true);
      case "saucelabs":
      case "saucelabs-firefox":
        DesiredCapabilities caps = DesiredCapabilities.firefox();
        caps.setCapability("version", "29");
        caps.setCapability("platform", "Windows 7");
        caps.setCapability("name", testName.get());

        // if running inside Jenkins, expose build ID
        String tag = System.getenv("BUILD_TAG");
        if (tag != null) caps.setCapability("build", tag);

        return new SauceLabsConnection().createWebDriver(caps);
      case "phantomjs":
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability(LANGUAGE_SELECTOR, "en");
        capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
        return new PhantomJSDriver(capabilities);

      default:
        throw new Error("Unrecognized browser type: " + browser);
    }
  }
Example #23
0
  public void setUp() throws Exception {
    String target = System.getProperty("zap.targetApp");
    if (target != null && target.length() > 0) {
      // Theres an override
      setSite(target);
    }

    Proxy proxy = new Proxy();
    proxy.setHttpProxy(System.getProperty("zap.proxy"));

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.PROXY, proxy);

    WebDriver driver = new FirefoxDriver(capabilities);
    this.setDriver(driver);
  }
 @Before
 public void setUp() throws Exception {
   DesiredCapabilities capabillities = DesiredCapabilities.firefox();
   capabillities.setCapability(CapabilityType.BROWSER_NAME, browser);
   capabillities.setCapability(CapabilityType.VERSION, version);
   capabillities.setCapability(CapabilityType.PLATFORM, Platform.valueOf(os));
   this.driver =
       new RemoteWebDriver(
           new URL(
               "http://"
                   + authentication.getUsername()
                   + ":"
                   + authentication.getAccessKey()
                   + "@ondemand.saucelabs.com:80/wd/hub"),
           capabillities);
   this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
 }
 @Before
 public void setUp() throws Exception {
   DesiredCapabilities capabilities = DesiredCapabilities.firefox();
   capabilities.setCapability("version", "5");
   capabilities.setCapability("platform", Platform.XP);
   this.driver =
       new RemoteWebDriver(
           new URL(
               "http://"
                   + authentication.getUsername()
                   + ":"
                   + authentication.getAccessKey()
                   + "@ondemand.saucelabs.com:80/wd/hub"),
           capabilities);
   driver.get("http://tutorialapp.saucelabs.com");
   this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
 }
Example #26
0
  public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
      driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
      driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
      driver = new ChromeDriver();
    } else if (BrowserType.htmlunit.name().equals(driverName)) {
      driver = new HtmlUnitDriver(true);
    } else if (driverName.startsWith(BrowserType.remote.name())) {
      String[] params = driverName.split(":");
      Assert.isTrue(
          params.length == 4,
          "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
              + driverName
              + "\"");

      String remoteHost = params[1];
      String remotePort = params[2];
      String driverType = params[3];

      String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub";

      DesiredCapabilities cap = null;
      if (BrowserType.firefox.name().equals(driverType)) {
        cap = DesiredCapabilities.firefox();
      } else if (BrowserType.ie.name().equals(driverType)) {
        cap = DesiredCapabilities.internetExplorer();
      } else if (BrowserType.chrome.name().equals(driverType)) {
        cap = DesiredCapabilities.chrome();
      }

      try {
        driver = new RemoteWebDriver(new URL(remoteUrl), cap);
      } catch (MalformedURLException e) {
        throw new RuntimeException(e);
      }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
  }
Example #27
0
  @Before
  public void setUp() throws Exception {
    prop = new Properties();

    try {
      prop.load(new FileInputStream(new java.io.File("").getAbsolutePath() + "/era.properties"));
      gridHost = prop.getProperty("grid.host");
      gridPort = prop.getProperty("grid.port");

    } catch (Exception e) {
      gridHost = "http://localhost";
      gridPort = "4444";
    }

    DesiredCapabilities capability = DesiredCapabilities.firefox();
    driver = new RemoteWebDriver(new URL(gridHost + ":" + gridPort + "//wd/hub"), capability);
    baseUrl = "http://weather.gc.ca/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }
Example #28
0
  public static void main(String[] args) throws Exception {

    DesiredCapabilities capabillities = DesiredCapabilities.firefox();
    capabillities.setCapability("version", "8");
    capabillities.setCapability("platform", Platform.WINDOWS);

    WebDriver driver =
        new RemoteWebDriver(
            new URL(
                "http://*****:*****@hub.testingbot.com:4444/wd/hub"),
            capabillities);

    driver.get("http://www.google.com");
    WebElement search = driver.findElement(By.name("q"));
    search.sendKeys("Hello, WebDriver");
    search.submit();
    System.out.println(driver.getTitle());
    driver.quit();
  }
  private static RemoteWebDriver setupDriver(boolean isMobileDriver) {

    URL url;
    DesiredCapabilities capabilities;

    try {
      if (isMobileDriver) {
        String browserName = "mobileOS";
        capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
        String host = "demo.perfectomobile.com";
        String user = URLEncoder.encode("*****@*****.**", "UTF-8");
        String password = URLEncoder.encode("SSSSS", "UTF-8");
        capabilities.setCapability("description", "ShirNate");
        capabilities.setCapability("platformName", "Android");

        // The below code shares the test execution with the Eclipse plug-in, thus enabling sharing
        // the devices.
        try {
          EclipseConnector connector = new EclipseConnector();
          String eclipseExecutionId = connector.getExecutionId();
          capabilities.setCapability("eclipseExecutionId", eclipseExecutionId);
        } catch (IOException ex) {
          ex.printStackTrace();
          return null;
        }

        url = new URL("https://" + user + ':' + password + '@' + host + "/nexperience/wd/hub");
        // create the driver:
        sleep(30000);

      } else {
        url = new URL("http://localhost:4444/wd/hub");
        capabilities = DesiredCapabilities.firefox();
      }
      return (new RemoteWebDriver(url, capabilities));

    } catch (IOException ex) {
      ex.printStackTrace();
      return null;
    }
  }
Example #30
0
 // extremely slow test, for issue1586. Excluding from regression.
 @Test(enabled = false)
 public void test() throws MalformedURLException {
   DesiredCapabilities ff = DesiredCapabilities.firefox();
   WebDriver driver = null;
   try {
     driver = new RemoteWebDriver(new URL(hub.getUrl() + "/grid/driver"), ff);
     for (int i = 0; i < 20; i++) {
       driver.get("http://code.google.com/p/selenium/");
       WebElement keywordInput = driver.findElement(By.name("q"));
       keywordInput.clear();
       keywordInput.sendKeys("test");
       WebElement submitButton = driver.findElement(By.name("projectsearch"));
       submitButton.click();
       driver.getCurrentUrl(); // fails here
     }
   } finally {
     if (driver != null) {
       driver.quit();
     }
   }
 }