@Override
  public void initialize() {
    String browser = System.getProperty("browser", "").toLowerCase();

    DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
    dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    dc.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

    // dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    // It's possible to avoid the post-processing cost of uploading videos for passing tests
    //        dc.setCapability("video-upload-on-pass", false);

    if ("ie8".equals(browser)) {
      dc.setVersion("8");
      dc.setCapability("platform", "Windows 2008");
    } else if ("ie9".equals(browser)) {
      dc.setVersion("9");
      dc.setCapability("platform", "Windows 2008");
    } else if ("ie10".equals(browser)) {
      dc.setVersion("10");
      dc.setCapability("platform", "Windows 2012");
    }

    // Set a 10 minute limit per test
    dc.setCapability("max-duration", 10 * 60);
    // Set a 30 second command timeout
    dc.setCapability("command-timeout", 30);
    // Set a 15 second idle timeout
    dc.setCapability("idle-timeout", 15);
  }
  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 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;
  }
  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);
  }
 protected WebDriver createHtmlUnitDriver() {
   DesiredCapabilities capabilities = DesiredCapabilities.htmlUnitWithJs();
   capabilities.merge(createCommonCapabilities());
   capabilities.setCapability(HtmlUnitDriver.INVALIDSELECTIONERROR, true);
   capabilities.setCapability(HtmlUnitDriver.INVALIDXPATHERROR, false);
   if (browser.indexOf(':') > -1) {
     // Use constants BrowserType.IE, BrowserType.FIREFOX, BrowserType.CHROME etc.
     String emulatedBrowser = browser.replaceFirst("htmlunit:(.*)", "$1");
     capabilities.setVersion(emulatedBrowser);
   }
   return new HtmlUnitDriver(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);
  }
  @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);
  }
 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;
  }
  /**
   * @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);
    }
  }
 public void setVersion(String version) {
   if (!StringUtils.equalsIgnoreCase(version, "none")) {
     capabilities.setVersion(version);
   }
 }
  public static DesiredCapabilities of(Browser browser) {
    if (browser == null) {
      return null;
    }

    DesiredCapabilities caps;

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

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

      case ff:
        caps = DesiredCapabilities.firefox();
        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 opera:
        OperaProfile profile = new OperaProfile();
        profile.preferences().set("Geolocation", "Enable geolocation", true);
        // This pref allows all sites to access geolocation without prompting.
        // A 0 value would deny all sites and -1 would prompt for all sites.
        profile.preferences().set("User Prefs", "Geolocation site state", 1);

        caps = DesiredCapabilities.opera();
        caps.setCapability("opera.profile", profile);
        break;

      case opera_mobile:
        caps = DesiredCapabilities.opera();
        caps.setCapability(OperaSettings.Capability.PRODUCT.getCapability(), OperaProduct.MOBILE);
        break;

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

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

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

      case iphone:
        caps = DesiredCapabilities.iphone();
        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;
  }