Ejemplo n.º 1
0
  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);
  }
  @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);
  }
Ejemplo n.º 3
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);
  }
 public DesiredCapabilities getIECapabilities() {
   DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
   capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
   capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);
   capabilities.setCapability("requireWindowFocus", true);
   return addProxySettings(capabilities, proxy());
 }
Ejemplo n.º 5
0
  /**
   * private method to load the InternetExplorer Driver
   *
   * @param loadRemote
   */
  private static RemoteWebDriver loadIEDriver(boolean loadRemote) throws Exception {

    log.info("Entering BrowserFactory class loadIEDriver...");

    RemoteWebDriver remoteDriver = null;
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(
        InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

    if (loadRemote) {
      log.info("loading IE driver in remote");
      log.info("Loading  Remote Run URL " + CommonUtils.readFromConfig("RemoteWebAppUrl"));
      URL url = new URL(CommonUtils.readFromConfig("RemoteWebAppUrl"));
      remoteDriver = new RemoteWebDriver(url, capabilities);
      log.info("loading IE driver in remote successful");
    } else {
      log.info("loading Generic IE driver");
      System.setProperty(
          "webdriver.ie.driver", "src/main/resources/browser_exe/ie/IEDriverServer.exe");
      remoteDriver = new InternetExplorerDriver(capabilities);
      log.info("loading Generic IE driver successful");
    }

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

    return remoteDriver;
  }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
0
 @BeforeTest(alwaysRun = true)
 public void setUp() throws MalformedURLException {
   File file = new File("C:\\Users\\Jim McFarlane\\Desktop\\Selenium\\IEDriverServer.exe");
   System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
   DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
   driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps);
   driver.manage().window().setSize(new Dimension(1200, 900));
 }
Ejemplo n.º 8
0
 private WebDriver startIEBrowser() {
   setIEDriverPath();
   DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
   ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
   ieCapabilities.setCapability(
       InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
   return new InternetExplorerDriver(ieCapabilities);
 }
  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;
  }
    @Override
    public void setSystemProperty(Configuration configInstance, Capabilities capabilities) {
      String brofserName = capabilities.getBrowserName();

      if (DesiredCapabilities.chrome().getBrowserName().equals(brofserName))
        CHROME.setSystemProperty(configInstance);
      if (DesiredCapabilities.internetExplorer().getBrowserName().equals(brofserName))
        INTERNETEXPLORER.setSystemProperty(configInstance);
      if (DesiredCapabilities.phantomjs().getBrowserName().equals(brofserName))
        PHANTOMJS.setSystemProperty(configInstance);
    }
Ejemplo n.º 11
0
  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);
  }
  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");
 }
Ejemplo n.º 14
0
 @BeforeTest(alwaysRun = true)
 public void setUp() throws MalformedURLException {
   try {
     Thread.sleep(90000);
   } catch (InterruptedException e) {
     System.err.println("Caught Exception: " + e.getMessage());
   }
   File file = new File("C:\\Selenium\\IEDriverServer.exe");
   System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
   DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
   driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps);
   driver.manage().window().setSize(new Dimension(1200, 900));
 }
Ejemplo n.º 15
0
 @BeforeMethod(alwaysRun = true)
 public void reportHeader(Method method) throws Throwable {
   // itc = ctx;
   Date date = new Date();
   SimpleDateFormat sdf = new SimpleDateFormat("dd_MMM_yyyy hh mm ss SSS");
   String formattedDate = sdf.format(date);
   ReportStampSupport.calculateTestCaseStartTime();
   if (browser.equalsIgnoreCase("firefox")) {
     ProfilesIni profile = new ProfilesIni();
     FirefoxProfile ffprofile = new FirefoxProfile();
     ffprofile.setEnableNativeEvents(true);
     webDriver = new FirefoxDriver(ffprofile);
   } else if (browser.equalsIgnoreCase("ie")) {
     File file = new File("Drivers\\IEDriverServer.exe");
     System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
     DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
     caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
     webDriver = new InternetExplorerDriver(caps);
     i = i + 1;
   } else if (browser.equalsIgnoreCase("chrome")) {
     System.setProperty("webdriver.chrome.driver", "Drivers\\chromedriver.exe");
     DesiredCapabilities capabilities = new DesiredCapabilities();
     ChromeOptions options = new ChromeOptions();
     options.addArguments("test-type");
     capabilities.setCapability(ChromeOptions.CAPABILITY, options);
     webDriver = new ChromeDriver(capabilities);
   } else if (browser.equalsIgnoreCase("iphone")) {
     Iosdriver.resetApp();
   } else if (browser.equalsIgnoreCase("android")) {
     AndroidDriver2.resetApp();
   }
   flag = false;
   if ((!(browser.equalsIgnoreCase("Android"))) & (!(browser.equalsIgnoreCase("iPhone")))) {
     driver = /*new EventFiringWebDriver*/ (webDriver);
     /*ActionEngineSupport myListener = new ActionEngineSupport();
     driver.register(myListener);*/
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);
     driver.get(url);
   }
   HtmlReportSupport.tc_name = method.getName().toString() + "-" + formattedDate;
   String[] ts_Name = this.getClass().getName().toString().split("\\.");
   HtmlReportSupport.packageName = ts_Name[0] + "." + ts_Name[1] + "." + ts_Name[2];
   HtmlReportSupport.testHeader(HtmlReportSupport.tc_name, browser);
   stepNum = 0;
   PassNum = 0;
   FailNum = 0;
   testName = method.getName();
   logger.info("Current Test : " + testName);
 }
Ejemplo n.º 16
0
  @BeforeMethod
  public void browserOpen(Method method) throws IOException {
    Browser = "FF";
    if (Browser.equalsIgnoreCase("ff")) {
      driver = new FirefoxDriver();
    } else if (Browser.equalsIgnoreCase("IE")) {
      System.setProperty(
          "webdriver.ie.driver",
          (System.getProperty("user.dir") + "\\CrossBrowserDriver\\IEDriverServer.exe"));
      DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
      dc.setCapability(
          InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
      driver = new InternetExplorerDriver(dc);
      driver.manage().deleteAllCookies();
    } else if (Browser.equalsIgnoreCase("ch")) {
      System.setProperty(
          "webdriver.chrome.driver",
          (System.getProperty("user.dir") + "\\CrossBrowserDriver\\chromedriver.exe"));
      driver = new ChromeDriver();
      System.err.println("Google Chrome is selected");
    } else if (Browser.equalsIgnoreCase("Safari")) {
      driver = new SafariDriver();
      System.err.println("Safari has been selected");
    } else if (Browser.equalsIgnoreCase("iOS")) {
      new RemoteWebDriver(new URL("http://localhost:3001/driver/hub"), DesiredCapabilities.ipad());
      System.err.println("iOS is selected To do the Cross Browser Test");
    } else {
      throw new IllegalArgumentException("The Browser Type is Undefined");
    }

    // mailBaseURL = "https://debugmail.io";
    // baseURL = "http://qa.corporaterewards.us";
    // baseURL = "http://devakrongeneralcelebrations.workstride.com";
    // //AKRON
    baseURL = "http://www.spafinder.com"; // SpaFinder
    driver.get(baseURL);

    iWait(10);
    maxPage();
    String testName = method.getName();
    String pageTitle = driver.getTitle();
    APPLICATION_LOG.debug(
        "==========================================================================================================");
    APPLICATION_LOG.debug("Test Page is: ==> " + pageTitle + " Just S-T-A-R-T-E-D");
    APPLICATION_LOG.debug("Test Method is: ==> " + testName + " Just S-T-A-R-T-E-D");
    APPLICATION_LOG.debug(
        "==========================================================================================================");
  }
Ejemplo n.º 17
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;
  }
Ejemplo n.º 18
0
  @Before
  public void SetUp() {
    System.out.print("Using " + Browser + SystemHelper.LineSeparator);

    switch (Browser) {
      case Chrome:
        {
          System.setProperty("webdriver.chrome.driver", Settings.ChromeDriverPath);
          ChromeCapabilities =
              ChromeCapabilities == null ? DesiredCapabilities.chrome() : ChromeCapabilities;
          ChromeService =
              ChromeService == null ? ChromeDriverService.createDefaultService() : ChromeService;
          Driver = new ChromeDriver(ChromeService, ChromeCapabilities);
        }
        break;
      case Firefox:
        {
          InitializeFirefoxDriver();
        }
        break;
      case IE:
        {
          System.setProperty("webdriver.ie.driver", Settings.IEDriverPath);
          IECapabilities =
              IECapabilities == null ? DesiredCapabilities.internetExplorer() : IECapabilities;
          IEService =
              IEService == null ? InternetExplorerDriverService.createDefaultService() : IEService;
          Driver = new InternetExplorerDriver(IEService, IECapabilities);
        }
        break;
      default:
        {
          InitializeFirefoxDriver();
        }
        break;
    }

    Driver.manage().window().maximize();
    SmallWait = new WebDriverWait(Driver, 3);
    Wait = new WebDriverWait(Driver, 10);
    LongWait = new WebDriverWait(Driver, 30);
  }
Ejemplo n.º 19
0
 /** Sign in successfully (keep me signed in off)* */
 @Test
 @Parameters({"xBrowser", "xUrl"})
 public void SignIn5(String xBrowser, String xUrl) throws InterruptedException {
   System.out.println("Open URL");
   driver.get(xUrl);
   sleep(2);
   clickElement(signIn.SIGN_IN_LINK);
   insertData(signIn.USERNAME, "cookietest");
   insertData(signIn.PASSWORD, "123456");
   sleep(2);
   System.out.println("Find Element REMEMBER_CHECKBOX");
   WebElement remember = findElement(signIn.REMEMBER_CHECKBOX);
   System.out.println("Click Element REMEMBER_CHECKBOX if is selected");
   if (remember.isSelected()) {
     remember.click();
   }
   System.out.println("Find Element SIGN_IN_BUTTON");
   clickElement(signIn.SIGN_IN_BUTTON);
   sleep(5);
   System.out.println("Assertion");
   assertEquals("cookietest", findElement(signIn.LOGGED_USERNAME).getText());
   System.out.println("Close browser");
   driver.quit();
   System.out.println("Open browser");
   if (xBrowser.contains("firefox")) {
     driver = new FirefoxDriver();
   } else if (xBrowser.contains("chrome")) {
     driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
   } else if (xBrowser.contains("ie")) {
     DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
     ieCapabilities.setCapability(
         InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
     ieCapabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
     driver = new InternetExplorerDriver(ieCapabilities);
   }
   System.out.println("Open URL");
   driver.get(xUrl);
   System.out.println("Sleep 10 sek");
   Thread.sleep(10000);
   System.out.println("Assertion");
   assertFalse(findElement(signIn.LOGGED_USERNAME).isDisplayed());
 }
Ejemplo n.º 20
0
 public WebDriver selectBrowser() {
   if ("firefox".equals(Config.browser)) {
     driver = new FirefoxDriver();
     return driver;
   } else if ("ie".equals(Config.browser)) {
     System.setProperty("webdriver.ie.driver", "file/IEDriverServer.exe");
     DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
     capabilities.setCapability(
         InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
     capabilities.setCapability("ignoreProtectedModeSettings", true);
     driver = new InternetExplorerDriver(capabilities);
     return driver;
   } else if ("chrome".equals(Config.browser)) {
     System.setProperty("webdriver.chrome.driver", "file/chromedriver.exe");
     ChromeOptions options = new ChromeOptions();
     options.addArguments("--test type", "--ignore-certificate-errors");
     options.addArguments("--test type", "--start-maximized");
     driver = new ChromeDriver(options);
     return driver;
   } else {
     System.out.println(Config.browser);
     return null;
   }
 }
Ejemplo n.º 21
0
public class DefaultDriverSessions implements DriverSessions {

  private static final Logger LOG = Logger.getLogger(DefaultDriverSessions.class.getName());

  private final DriverFactory factory;
  private final Clock clock;

  protected final Map<SessionId, Session> sessionIdToDriver = new ConcurrentHashMap<>();

  private static List<DriverProvider> defaultDriverProviders =
      new ImmutableList.Builder<DriverProvider>()
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.chrome(), "org.openqa.selenium.chrome.ChromeDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.firefox(), "org.openqa.selenium.firefox.FirefoxDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.internetExplorer(),
                  "org.openqa.selenium.ie.InternetExplorerDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.opera(), "com.opera.core.systems.OperaDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.operaBlink(), "org.openqa.selenium.opera.OperaDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.safari(), "org.openqa.selenium.safari.SafariDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.phantomjs(), "org.openqa.selenium.phantomjs.PhantomJSDriver"))
          .add(
              new DefaultDriverProvider(
                  DesiredCapabilities.htmlUnit(), "org.openqa.selenium.htmlunit.HtmlUnitDriver"))
          .build();

  public DefaultDriverSessions() {
    this(Platform.getCurrent(), new DefaultDriverFactory());
  }

  public DefaultDriverSessions(DriverFactory factory) {
    this(Platform.getCurrent(), factory);
  }

  protected DefaultDriverSessions(Platform runningOn, DriverFactory factory) {
    this(runningOn, factory, new SystemClock());
  }

  protected DefaultDriverSessions(Platform runningOn, DriverFactory factory, Clock clock) {
    this.factory = factory;
    this.clock = clock;
    registerDefaults(runningOn);
    registerServiceLoaders(runningOn);
  }

  private void registerDefaults(Platform current) {
    for (DriverProvider provider : defaultDriverProviders) {
      registerDriverProvider(current, provider);
    }
  }

  private void registerServiceLoaders(Platform current) {
    for (DriverProvider provider : ServiceLoader.load(DriverProvider.class)) {
      registerDriverProvider(current, provider);
    }
  }

  private void registerDriverProvider(Platform current, DriverProvider provider) {
    Capabilities caps = provider.getProvidedCapabilities();
    if (!platformMatches(current, caps)) {
      LOG.info(
          String.format(
              "Driver provider %s registration is skipped:%n"
                  + "registration capabilities %s does not match the current platform %s",
              provider, caps, current));
      return;
    }

    factory.registerDriverProvider(provider);
  }

  private boolean platformMatches(Platform current, Capabilities caps) {
    return caps.getPlatform() == null
        || caps.getPlatform() == Platform.ANY
        || current.is(caps.getPlatform());
  }

  public void registerDriver(Capabilities capabilities, Class<? extends WebDriver> driverClass) {
    factory.registerDriverProvider(new DefaultDriverProvider(capabilities, driverClass));
  }

  public SessionId newSession(Capabilities desiredCapabilities) throws Exception {
    SessionId sessionId = new SessionId(UUID.randomUUID().toString());
    Session session = DefaultSession.createSession(factory, clock, sessionId, desiredCapabilities);

    sessionIdToDriver.put(sessionId, session);

    return sessionId;
  }

  public Session get(SessionId sessionId) {
    return sessionIdToDriver.get(sessionId);
  }

  public void deleteSession(SessionId sessionId) {
    final Session removedSession = sessionIdToDriver.remove(sessionId);
    if (removedSession != null) {
      removedSession.close();
    }
  }

  public Set<SessionId> getSessions() {
    return Collections.unmodifiableSet(sessionIdToDriver.keySet());
  }
}
/**
 * There is information about supported {@link WebDriver} implementors <br>
 * - {@link FirefoxDriver}<br>
 * - {@link ChromeDriver}<br>
 * - {@link InternetExplorerDriver}<br>
 * - {@link SafariDriver}<br>
 * - {@link PhantomJSDriver}<br>
 * - {@link RemoteWebDriver}<br>
 * - {@link AndroidDriver}<br>
 * - {@link IOSDriver}<br>
 * <br>
 * - is browser only<br>
 * - is for mobile applications only<br>
 * Additional info:<br>
 * - default {@link Capabilities}<br>
 * - information about {@link DriverService}<br>
 * - can {@link WebDriver} be started remotely?<br>
 * - is {@link WebDriver} require URL of remotely or locally started<br>
 * server. ({@link SeleniumServer} or Appium Node.js server (see
 * http://appium.io/slate/en/master/?ruby#appium-design)<br>
 */
public enum ESupportedDrivers {
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link FirefoxDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#firefox()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: locally<br>
   * browser only
   */
  FIREFOX(
      DesiredCapabilities.firefox(), FirefoxDriver.class, true, false, null, null, false, false),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link ChromeDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#chrome()}<br>
   * <br>
   * <b>{@link DriverService}</b>: {@link ChromeDriverService}<br>
   * <br>
   * <b>Starts</b>: locally<br>
   * browser only
   */
  CHROME(
      DesiredCapabilities.chrome(),
      ChromeDriver.class,
      true,
      false,
      EServices.CHROMESERVICE,
      null,
      false,
      false),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link InternetExplorerDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#internetExplorer()}<br>
   * <br>
   * <b>{@link DriverService}</b>: {@link InternetExplorerDriverService}<br>
   * <br>
   * <b>Starts</b>: locally<br>
   * browser only<br>
   * <br>
   * <b>Additionally:</b> Windows only<br>
   */
  INTERNETEXPLORER(
      DesiredCapabilities.internetExplorer(),
      InternetExplorerDriver.class,
      true,
      false,
      EServices.IEXPLORERSERVICE,
      null,
      false,
      false),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link SafariDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#safari()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: locally<br>
   * browser only
   */
  SAFARI(DesiredCapabilities.safari(), SafariDriver.class, true, false, null, null, false, false),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link PhantomJSDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#phantomjs()}<br>
   * <br>
   * <b>{@link DriverService}</b>: {@link PhantomJSDriverService}<br>
   * <br>
   * <b>Starts</b>: locally<br>
   * browser only
   */
  PHANTOMJS(
      DesiredCapabilities.phantomjs(),
      PhantomJSDriver.class,
      true,
      false,
      EServices.PHANTOMJSSERVICE,
      null,
      false,
      false),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link AndroidDriver}<br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link ExtendedDesiredCapabilities#androidChrome()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * browser only
   */
  ANDROID_CHROME(
      ExtendedDesiredCapabilities.androidChrome(),
      AndroidDriver.class,
      true,
      false,
      null,
      null,
      true,
      true),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link AndroidDriver}<br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link ExtendedDesiredCapabilities#androidBrowser()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * browser only
   */
  ANDROID_BROWSER(
      ExtendedDesiredCapabilities.androidBrowser(),
      AndroidDriver.class,
      true,
      false,
      null,
      null,
      true,
      true),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link AndroidDriver}<br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link ExtendedDesiredCapabilities#androidChromium()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * browser only
   */
  ANDROID_CHROMIUM(
      ExtendedDesiredCapabilities.androidChromium(),
      AndroidDriver.class,
      true,
      false,
      null,
      null,
      true,
      true),
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link IOSDriver}<br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link ExtendedDesiredCapabilities#iosSafari()}<br>
   * <br>
   * <b>{@link DriverService}</b>: none<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * browser only
   */
  IOS_SAFARI(
      ExtendedDesiredCapabilities.iosSafari(),
      IOSDriver.class,
      true,
      false,
      null,
      null,
      true,
      true),

  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link RemoteWebDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: {@link DesiredCapabilities#firefox()()}<br>
   * <br>
   * <b>Starts</b>: locally and remotely. When it is started locally {@link SeleniumServer} is
   * started it the same time.<br>
   * browser only<br>
   * If it needs to be launched remotely it requires {@link URL} of the host where Appium node
   * server (if {@link ExtendedDesiredCapabilities#androidChrome()} or {@link
   * ExtendedDesiredCapabilities#iosSafari()} are used) or {@link SeleniumServer} are started, e.g.
   * http://127.0.0.1:4723/wd/hub (local host). Information about Appium node server please find
   * here:<br>
   * http://appium.io/getting-started.html<br>
   * Information about {@link SeleniumServer}: https://code.google.com/p/selenium/wiki/Grid2<br>
   * <br>
   * <b>{@link DriverService}</b>: optionally. If it is run locally with {@link
   * DesiredCapabilities#chrome()}, {@link DesiredCapabilities#internetExplorer()} or {@link
   * DesiredCapabilities#phantomjs()} then {@link ChromeDriverService}, {@link
   * InternetExplorerDriverService} or {@link PhantomJSDriverService} should be set up respectively
   * <br>
   */
  REMOTE(
      DesiredCapabilities.firefox(),
      RemoteWebDriver.class,
      true,
      false,
      null,
      new RemoteSeleniumServerLauncher(),
      true,
      false) {
    @Override
    public void setSystemProperty(Configuration configInstance, Capabilities capabilities) {
      String brofserName = capabilities.getBrowserName();

      if (DesiredCapabilities.chrome().getBrowserName().equals(brofserName))
        CHROME.setSystemProperty(configInstance);
      if (DesiredCapabilities.internetExplorer().getBrowserName().equals(brofserName))
        INTERNETEXPLORER.setSystemProperty(configInstance);
      if (DesiredCapabilities.phantomjs().getBrowserName().equals(brofserName))
        PHANTOMJS.setSystemProperty(configInstance);
    }
  },
  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link AndroidDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: empty. They should be defined explicitly. Here is an
   * example: <br>
   * &nbsp;&nbsp;"deviceName":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"desired device name e.g. Android Emulator, NEXUS and so on"
   * <br>
   * &nbsp;&nbsp;},<br>
   * &nbsp;&nbsp;"app":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"absolute path to desired *.apk file"<br>
   * &nbsp;&nbsp;}<br>
   * <br>
   * It is enough for the successful starting. Also see {@link MobileCapabilityType}<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * mobile apps only
   */
  ANDROID_APP(new DesiredCapabilities(), AndroidDriver.class, false, true, null, null, true, true),

  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link AndroidDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: empty. They should be defined explicitly. Here is an
   * example: <br>
   * &nbsp;&nbsp;"deviceName":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"desired device name e.g. Android Emulator, NEXUS and so on"
   * <br>
   * &nbsp;&nbsp;},<br>
   * &nbsp;&nbsp;"app":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"absolute path to desired *.apk file"<br>
   * &nbsp;&nbsp;}<br>
   * <br>
   * It is enough for the successful starting. Also see {@link MobileCapabilityType}<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * mobile apps only
   */
  SELENDROID_APP(
      ExtendedDesiredCapabilities.selendroid(),
      AndroidDriver.class,
      false,
      true,
      null,
      null,
      true,
      true),

  /**
   * <b>Required {@link WebDriver} implementor</b>: {@link IOSDriver} <br>
   * <br>
   * <b>Default {@link Capabilities}</b>: empty. They should be defined explicitly. Here is an
   * example: <br>
   * &nbsp;&nbsp;"platformVersion":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"7.1"<br>
   * &nbsp;&nbsp;},<br>
   * &nbsp;&nbsp;"deviceName":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"desired device name e.g. iPhone Simulator"<br>
   * &nbsp;&nbsp;},<br>
   * &nbsp;&nbsp;"app":{<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;"value":"absolute path to desired *.app"<br>
   * &nbsp;&nbsp;}<br>
   * <br>
   * It is enough for the successful starting. Also see {@link MobileCapabilityType}<br>
   * <br>
   * <b>Starts</b>: remotely. It requires {@link URL} of the host where Appium node server is
   * started, e.g. http://127.0.0.1:4723/wd/hub (local host). Please find information here:<br>
   * http://appium.io/getting-started.html<br>
   * mobile apps only
   */
  IOS_APP(new DesiredCapabilities(), IOSDriver.class, false, true, null, null, true, true);

  public static ESupportedDrivers parse(String original) {
    String parcingStr = original.toUpperCase().trim();

    ESupportedDrivers[] values = ESupportedDrivers.values();
    for (ESupportedDrivers enumElem : values)
      if (parcingStr.equals(enumElem.toString())) return enumElem;
    throw new IllegalArgumentException(
        "Webdriver with specified name " + original + " is not supported");
  }

  private DesiredCapabilities capabilities;
  private Class<? extends WebDriver> driverClazz;
  private EServices service;
  final ILocalServerLauncher serverLauncher;
  private final boolean startsRemotely;

  private final boolean requiresRemoteURL;
  private final boolean isForBrowser;
  private final boolean isForMobileApp;

  private ESupportedDrivers(
      DesiredCapabilities capabilities,
      Class<? extends WebDriver> driverClazz,
      boolean isForBrowser,
      boolean isForMobileApp,
      EServices sevice,
      ILocalServerLauncher serverLauncher,
      boolean startsRemotely,
      boolean requiresRemoteURL) {
    this.capabilities = capabilities;
    this.driverClazz = driverClazz;
    this.service = sevice;
    this.serverLauncher = serverLauncher;
    this.startsRemotely = startsRemotely;
    this.requiresRemoteURL = requiresRemoteURL;
    this.isForBrowser = isForBrowser;
    this.isForMobileApp = isForMobileApp;
  }

  /** @return {@link Capabilities} Default capabilities of given {@link WebDriver} implementor */
  public DesiredCapabilities getDefaultCapabilities() {
    return capabilities;
  }

  /** @return Class of supported {@link WebDriver} implementor */
  public Class<? extends WebDriver> getUsingWebDriverClass() {
    return driverClazz;
  }

  /**
   * Starts remote server locally It is possible to launch {@link SeleniumServer} locally for now
   */
  public synchronized void launchRemoteServerLocallyIfWasDefined() {
    if (serverLauncher == null) return;
    if (serverLauncher.isLaunched()) return;
    try {
      serverLauncher.launch();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  /** @return flag of necessity of URL (remote server) */
  public boolean requiresRemoteURL() {
    return requiresRemoteURL;
  }

  /**
   * @param configInstance . An instance of {@link Configuration} where path to chromedriver*,
   *     IEDriverServer.exe or phantomjs* are defined
   */
  private void setSystemProperty(Configuration configInstance) {
    if (service != null) this.service.setSystemProperty(configInstance);
  }

  /**
   * It is useful for {@link RemoteWebDriver} instantiation. Local services depend on capabilities
   */
  public void setSystemProperty(Configuration configInstance, Capabilities ignored) {
    setSystemProperty(configInstance);
  }

  /** @return flag of of possibility to start {@link WebDriver} implementor remotely */
  public boolean startsRemotely() {
    return startsRemotely;
  }

  public boolean isForBrowser() {
    return isForBrowser;
  }

  public boolean isForMobileApp() {
    return isForMobileApp;
  }
}
  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;
  }
 public RemoteWebDriver getInternetExplorerDriver() {
   return getRemoteDriver(DesiredCapabilities.internetExplorer());
 }
  /*
   * Factory method to return a RemoteWebDriver instance given the url of the
   * Grid hub and a Browser instance.
   *
   * @param gridHubUrl : grid hub URI
   *
   * @param browser : Browser object containing info around the browser to hit
   *
   * @param username : username for BASIC authentication on the page to test
   *
   * @param password : password for BASIC authentication on the page to test
   *
   * @return RemoteWebDriver
   */
  public static WebDriver getInstance(
      String gridHubUrl, Browser browser, String username, String password) {

    WebDriver webDriver = null;

    DesiredCapabilities capability = new DesiredCapabilities();
    String browserName = browser.getName();
    capability.setJavascriptEnabled(true);

    // In case there is no Hub
    if (gridHubUrl == null || gridHubUrl.length() == 0) {
      return getInstance(browserName, username, password);
    }

    if (CHROME.equals(browserName)) {
      capability = DesiredCapabilities.chrome();
    } else if (FIREFOX.equals(browserName)) {
      capability = DesiredCapabilities.firefox();

      FirefoxProfile ffProfile = new FirefoxProfile();

      // Authenication Hack for Firefox
      if (username != null && password != null) {
        ffProfile.setPreference("network.http.phishy-userpass-length", 255);
        capability.setCapability(FirefoxDriver.PROFILE, ffProfile);
      }

      capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    } else if (INTERNET_EXPLORER.equals(browserName)) {

      capability = DesiredCapabilities.internetExplorer();
      capability.setCapability(
          InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    } else if (SAFARI.equals(browserName)) {
      capability = DesiredCapabilities.safari();
    } else if (ANDROID.equals(browserName)) {
      capability = DesiredCapabilities.android();
    } else if (IPHONE.equals(browserName)) {
      capability = DesiredCapabilities.iphone();
    } else {

      capability = DesiredCapabilities.htmlUnit();
      // HTMLunit Check
      if (username != null && password != null) {
        webDriver = (HtmlUnitDriver) AuthenticatedHtmlUnitDriver.create(username, password);
      } else {
        webDriver = new HtmlUnitDriver(true);
      }

      return webDriver;
    }

    capability = setVersionAndPlatform(capability, browser.getVersion(), browser.getPlatform());

    // Create Remote WebDriver
    try {
      webDriver = new RemoteWebDriver(new URL(gridHubUrl), capability);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    return webDriver;
  }