@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");
   }
 }
Esempio n. 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();
  }
Esempio n. 5
0
  /**
   * Creates a new {@link RemoteWebDriver} instance to be used to run WebDriver tests using Sauce.
   *
   * @param username the Sauce username
   * @param key the Sauce access key
   * @param os the operating system to be used
   * @param browser the name of the browser to be used
   * @param browserVersion the version of the browser to be used
   * @param method the test method being executed
   * @throws Exception thrown if any errors occur in the creation of the WebDriver instance
   */
  @Parameters({"username", "key", "os", "browser", "browserVersion"})
  @BeforeMethod
  public void setUp(
      @Optional("ivolf") String username,
      @Optional("90e3bb89-c21d-4885-85cf-f25494db06ff") String key,
      @Optional("Windows 8.1") String os,
      @Optional("internet explorer") String browser,
      @Optional("11") String browserVersion,
      Method method)
      throws Exception {

    if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(key)) {
      authentication = new SauceOnDemandAuthentication(username, key);
    } else {
      authentication =
          new SauceOnDemandAuthentication("ivolf", "90e3bb89-c21d-4885-85cf-f25494db06ff");
    }

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName(browser);
    capabilities.setCapability("version", browserVersion);
    capabilities.setCapability("platform", os);
    capabilities.setCapability("name", method.getName());
    this.driver =
        new RemoteWebDriver(
            new URL(
                "http://"
                    + authentication.getUsername()
                    + ":"
                    + authentication.getAccessKey()
                    + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);
  }
 protected WebDriver createRemoteDriver(String remote, String browser) {
   try {
     DesiredCapabilities capabilities = createCommonCapabilities();
     capabilities.setBrowserName(browser);
     return new RemoteWebDriver(new URL(remote), capabilities);
   } catch (MalformedURLException e) {
     throw new IllegalArgumentException("Invalid 'remote' parameter: " + remote, e);
   }
 }
Esempio n. 7
0
 // get cloud Driver
 public WebDriver getSauceLabDriver(
     String userName, String key, String os, String browserName, String browserVersion)
     throws IOException {
   DesiredCapabilities cap = new DesiredCapabilities();
   cap.setCapability("platform", os);
   cap.setBrowserName(browserName);
   cap.setCapability("version", browserVersion);
   driver =
       new RemoteWebDriver(
           new URL("http://" + userName + ":" + key + "@ondemand.saucelabs.com:80/wd/hub"), cap);
   return driver;
 }
  /** @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);
  }
 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;
 }
  /**
   * @author: Downey Tung
   * @date: Created on 09/03/2015
   * @description: This is test suite for the Daily automation of SMT Daily Automation
   */
  @Before
  public void setUp() throws Exception {
    System.setProperty("phantomjs.binary.path", "/usr/local/Cellar/phantomjs/2.0.0/bin/phantomjs");
    // System.setProperty("phantomjs.binary.path", "/usr/local/bin/phantomjs");
    dCaps = new DesiredCapabilities();
    dCaps.setBrowserName("firefox");
    dCaps.setVersion("39");
    dCaps.setJavascriptEnabled(true);
    dCaps.setCapability("takesScreenshot", true);
    driver = new PhantomJSDriver(dCaps);
    driver.get("https://radioedit.iheart.com");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.switchTo().defaultContent();

    // input on username
    driver.findElement(By.name("username")).sendKeys("svc-resmtrw");
    // input on password
    driver.findElement(By.name("password")).sendKeys("Digital2014");
    // click on Authorize
    driver.findElement(By.xpath("//*[@id='loginForm']/fieldset/div/input")).click();
    Thread.sleep(5000);

    String winHandleBefore = driver.getWindowHandle();
    for (String windhandle : driver.getWindowHandles()) {
      driver.switchTo().window(windhandle);
    }

    // Click on Stream Manager
    driver
        .findElement(By.xpath("//*[@ng-href='http://stream-manager.radioedit.iheart.com']"))
        .click();

    for (String windhandle2 : driver.getWindowHandles()) {
      driver.switchTo().window(windhandle2);
    }
  }
Esempio n. 12
0
  public static void main(String[] args) {

    // make sure to install in Firefox the plugin from
    // https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.htmlUnit();
    desiredCapabilities.setBrowserName("firefox");
    desiredCapabilities.setJavascriptEnabled(true);

    WebDriver driver = new FirefoxDriver(desiredCapabilities);

    int start = 1;
    if (args.length == 1) {
      start = Integer.parseInt(args[0]);
    }

    try {
      crawl(driver, start);
    } catch (Exception e) {
      System.out.println("ERROR: " + e.getMessage());
      e.printStackTrace();
    }

    driver.close();
  }
 public void setBrowserName(String browserName) {
   if (!StringUtils.equalsIgnoreCase(browserName, "none")) {
     capabilities.setBrowserName(browserName);
   }
 }
Esempio n. 14
0
  @Parameters("browser")
  @BeforeTest
  public void launchapp(String browser) throws MalformedURLException {
    String URL = "http://social.ravabe.com/";

    if (browser.equalsIgnoreCase("firefox")) {
      System.out.println(" Executing on FireFox");
      String Node = "http://localhost:5555/wd/hub";
      // String Node1="http://192.168.137.172:5556/wd/hub";
      DesiredCapabilities cap = DesiredCapabilities.firefox();

      cap.setBrowserName("firefox");

      driver = new RemoteWebDriver(new URL(Node), cap);
      // driver1=new RemoteWebDriver(new URL(Node1), cap);
      // Puts an Implicit wait, Will wait for 10 seconds before throwing exception
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // Launch website
      driver.navigate().to(URL);
      // driver1.navigate().to(URL);
      driver.manage().window().maximize();
      // driver1.manage().window().maximize();

    }
    /*
    else if(browser.equalsIgnoreCase("firefox1"))
    {
     System.out.println(" Executing on FireFox");
     String Node1 = "http://localhost:5556/wd/hub";
     DesiredCapabilities cap1 = DesiredCapabilities.firefox();
     cap1.setBrowserName("firefox");
     driver1 = new RemoteWebDriver(new URL(Node1), cap1);
     driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     driver1.navigate().to(URL);
     driver1.manage().window().maximize();
    }*/
    else if (browser.equalsIgnoreCase("chrome")) {
      System.out.println(" Executing on CHROME");
      DesiredCapabilities cap = DesiredCapabilities.chrome();
      cap.setBrowserName("chrome");
      String Node = "http://localhost:5557/wd/hub";
      // String Node1="http://192.168.137.172:5560/wd/hub";
      driver = new RemoteWebDriver(new URL(Node), cap);
      // driver1 = new RemoteWebDriver(new URL(Node1), cap);
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // Launch website
      driver.navigate().to(URL);
      // driver1.navigate().to(URL);
      driver.manage().window().maximize();
      // driver1.manage().window().maximize();
    }
    /*
    else if (browser.equalsIgnoreCase("ie"))
    {
       System.out.println(" Executing on IE");
       DesiredCapabilities cap = DesiredCapabilities.chrome();
       cap.setBrowserName("ie");
       String Node = "http://localhost:5558/wd/hub";
       driver = new RemoteWebDriver(new URL(Node), cap);
       driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

       // Launch website
       driver.navigate().to(URL);
       driver.manage().window().maximize();
    }*/
    else {
      throw new IllegalArgumentException("The Browser Type is Undefined");
    }
  }
Esempio n. 15
0
  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 {
        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);
      } 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);
      } 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.BROWSER_HEADLESS)) {
      log.info(" LAUNCHING HTMLUNIT ");
      capabilities = new DesiredCapabilities();
      capabilities.setBrowserName("htmlunit");

    } else if (selectedBrowser.equalsIgnoreCase(Constants.IPHONE_WEBDRIVER)) {
      try {
        log.info(" LAUNCHING IPHONE DRIVER");
        capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("iPhone");
        capabilities.setJavascriptEnabled(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      throw new ScreenException(
          " Only FireFox,InternetExplore Chrome ,Htmlunit and iPhoneWebdriver works");
    }

    /** These 3 steps common for all the browsers */
    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.navigate().to(applicationURL + applicationContext);
  }