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 shouldAllowUserToSuccessfullyOverrideTheHomePage() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.page", "1");
    profile.setPreference("browser.startup.homepage", pages.javascriptPage);

    final WebDriver driver2 = newFirefoxDriver(profile);

    try {
      new WebDriverWait(driver2, 30).until(urlToBe(pages.javascriptPage));
    } finally {
      driver2.quit();
    }
  }
  /*
   * Factory method to return a WebDriver instance given the browser to hit
   *
   * @param browser : String representing the local 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 WebDriver instance
   */
  public static WebDriver getInstance(String browser, String username, String password) {

    if (webDriver != null) {
      return webDriver;
    }

    if (CHROME.equals(browser)) {
      webDriver = new ChromeDriver();

    } else if (FIREFOX.equals(browser)) {

      FirefoxProfile ffProfile = new FirefoxProfile();

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

      webDriver = new FirefoxDriver(ffProfile);

    } else if (INTERNET_EXPLORER.equals(browser)) {
      webDriver = new InternetExplorerDriver();

    } else {

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

    return webDriver;
  }
 static {
   _firefoxProfile.setPreference("browser.download.dir", TestPropsValues.OUTPUT_DIR);
   _firefoxProfile.setPreference("browser.download.folderList", 2);
   _firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
   _firefoxProfile.setPreference("browser.download.useDownloadDir", true);
   _firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
   _firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
   _firefoxProfile.setPreference("dom.max_chrome_script_run_time", 300);
   _firefoxProfile.setPreference("dom.max_script_run_time", 300);
 }
  @Before
  public void setUp() {
    File file = new File("e:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary binary = new FirefoxBinary(file);
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.homepage", "");

    driver = new FirefoxDriver(binary, profile);
  }
  @Test
  public void userPrefsArePreservedWhenConvertingToAndFromJson() throws IOException {
    profile.setPreference("browser.startup.homepage", "http://www.example.com");

    String json = profile.toJson();
    FirefoxProfile rebuilt = FirefoxProfile.fromJson(json);
    Preferences parsedPrefs = parseUserPrefs(rebuilt);

    assertEquals("http://www.example.com", parsedPrefs.getPreference("browser.startup.homepage"));
  }
  @Test
  public void backslashedCharsArePreservedWhenConvertingToAndFromJson() throws IOException {
    String dir =
        "c:\\aaa\\bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh\\iii\\jjj\\kkk\\lll\\mmm\\nnn\\ooo\\ppp\\qqq\\rrr\\sss\\ttt\\uuu\\vvv\\www\\xxx\\yyy\\zzz";
    profile.setPreference("browser.download.dir", dir);

    String json = profile.toJson();
    FirefoxProfile rebuilt = FirefoxProfile.fromJson(json);
    Preferences parsedPrefs = parseUserPrefs(rebuilt);

    assertEquals(dir, parsedPrefs.getPreference("browser.download.dir"));
  }
  private FirefoxDriver getNegotiatingFirefox(KerberosContainer kdc, String tokenCache) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAlwaysLoadNoFocusLib(true);
    // Allow auth negotiation for jenkins under test
    profile.setPreference("network.negotiate-auth.trusted-uris", jenkins.url.toExternalForm());
    profile.setPreference("network.negotiate-auth.delegation-uris", jenkins.url.toExternalForm());
    FirefoxBinary binary = new FirefoxBinary();
    // Inject config and TGT
    binary.setEnvironmentProperty("KRB5CCNAME", tokenCache);
    binary.setEnvironmentProperty("KRB5_CONFIG", kdc.getKrb5ConfPath());
    // Turn debug on
    binary.setEnvironmentProperty("KRB5_TRACE", diag.touch("tracelog").getAbsolutePath());
    binary.setEnvironmentProperty("NSPR_LOG_MODULES", "negotiateauth:5");
    binary.setEnvironmentProperty(
        "NSPR_LOG_FILE", diag.touch("firefox.nego.log").getAbsolutePath());

    String display = FallbackConfig.getBrowserDisplay();
    if (display != null) {
      binary.setEnvironmentProperty("DISPLAY", display);
    }
    final FirefoxDriver driver = new FirefoxDriver(binary, profile);
    cleaner.addTask(
        new Statement() {
          @Override
          public void evaluate() throws Throwable {
            try {
              driver.quit();
            } catch (UnreachableBrowserException ex) {
              System.err.println("Browser died already");
              ex.printStackTrace();
            }
          }

          @Override
          public String toString() {
            return "Close Kerberos WebDriver after test";
          }
        });
    return driver;
  }
 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;
 }
  @Test
  public void shouldSetIntegerPreferences() throws Exception {
    profile.setPreference("cheese", 1234);

    List<String> props = readGeneratedProperties(profile);
    boolean seenCheese = false;
    for (String line : props) {
      if (line.contains("cheese") && line.contains(", 1234)")) {
        seenCheese = true;
      }
    }

    assertTrue("Did not see integer value being set correctly", seenCheese);
  }
  @Test
  public void shouldBeAbleToStartFromProfileWithLogFileSetToStdout() throws IOException {
    FirefoxProfile profile = new FirefoxProfile();

    profile.setPreference("webdriver.log.file", "/dev/stdout");

    try {
      WebDriver secondDriver = newFirefoxDriver(profile);
      secondDriver.quit();
    } catch (Exception e) {
      e.printStackTrace();
      fail("Expected driver to be created successfully");
    }
  }
  @Test
  public void shouldQuoteStringsWhenSettingStringProperties() throws Exception {
    profile.setPreference("cheese", "brie");

    List<String> props = readGeneratedProperties(profile);
    boolean seenCheese = false;
    for (String line : props) {
      if (line.contains("cheese") && line.contains("\"brie\"")) {
        seenCheese = true;
      }
    }

    assertTrue(seenCheese);
  }
  static void populateProfile(FirefoxProfile profile, Capabilities capabilities) {
    if (capabilities == null) {
      return;
    }
    if (capabilities.getCapability(SUPPORTS_WEB_STORAGE) != null) {
      Boolean supportsWebStorage = (Boolean) capabilities.getCapability(SUPPORTS_WEB_STORAGE);
      profile.setPreference("dom.storage.enabled", supportsWebStorage);
    }
    if (capabilities.getCapability(ACCEPT_SSL_CERTS) != null) {
      Boolean acceptCerts = (Boolean) capabilities.getCapability(ACCEPT_SSL_CERTS);
      profile.setAcceptUntrustedCertificates(acceptCerts);
    }
    if (capabilities.getCapability(LOGGING_PREFS) != null) {
      LoggingPreferences logsPrefs = (LoggingPreferences) capabilities.getCapability(LOGGING_PREFS);
      for (String logtype : logsPrefs.getEnabledLogTypes()) {
        profile.setPreference("webdriver.log." + logtype, logsPrefs.getLevel(logtype).intValue());
      }
    }

    if (capabilities.getCapability(HAS_NATIVE_EVENTS) != null) {
      Boolean nativeEventsEnabled = (Boolean) capabilities.getCapability(HAS_NATIVE_EVENTS);
      profile.setEnableNativeEvents(nativeEventsEnabled);
    }
  }
  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);
    }
  }
  @Ignore(FIREFOX)
  public void testANewProfileShouldAllowSettingAdditionalParameters() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.homepage", formPage);

    try {
      WebDriver secondDriver = new FirefoxDriver(profile);
      String title = secondDriver.getTitle();
      secondDriver.quit();

      assertThat(title, is("We Leave From Here"));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Expected driver to be created succesfully");
    }
  }
  @Test
  public void shouldConvertItselfIntoAMeaningfulRepresentation() throws IOException {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("i.like.cheese", true);

    String json = profile.toJson();

    assertNotNull(json);

    File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("webdriver", "duplicated");
    new Zip().unzip(json, dir);

    File prefs = new File(dir, "user.js");
    assertTrue(prefs.exists());

    assertTrue(FileHandler.readAsString(prefs).contains("i.like.cheese"));
  }
  @Test
  public void shouldBeAbleToStartFromProfileWithLogFileSet() throws IOException {
    FirefoxProfile profile = new FirefoxProfile();
    File logFile = File.createTempFile("test", "firefox.log");
    logFile.deleteOnExit();

    profile.setPreference("webdriver.log.file", logFile.getAbsolutePath());

    try {
      WebDriver secondDriver = newFirefoxDriver(profile);
      assertTrue("log file should exist", logFile.exists());
      secondDriver.quit();
    } catch (Exception e) {
      e.printStackTrace();
      fail("Expected driver to be created successfully");
    }
  }
  // public static WebDriver getInstance(Browser browser, String username, String password) {
  public static WebDriver getDriver() {

    if (webDriver != null) {
      return webDriver;
    }

    Browser browser = new Browser();
    browser.setName(get(BROWSER_NAME_KEY));

    if (CHROME.equals(browser.getName())) {
      webDriver = new ChromeDriver();
      logger.info("ChromeDriver has created");
    } else if (FIREFOX.equals(browser.getName())) {
      FirefoxProfile ffProfile = new FirefoxProfile();

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

      try {
        webDriver = new FirefoxDriver();
      } catch (WebDriverException wdex) {
        // TODO ������� ���� � ���������
        FirefoxBinary binary =
            new FirefoxBinary(new File("D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"));
        webDriver = new FirefoxDriver(binary, new FirefoxProfile());

        // driver = new InternetExplorerDriver();
      } catch (Throwable th) {
        th.printStackTrace();
      }

      logger.info("FirefoxDriver has created");
    } else if (INTERNET_EXPLORER.equals(browser.getName())) {
      webDriver = new InternetExplorerDriver();
      logger.info("InternetExplorerDriver has created");
    } else {
      webDriver = new ChromeDriver();
      logger.info("ChromeDriver has created");
    }

    return webDriver;
  }
  // selenium Webdriver open a browser if its not opened
  public static void openBrowser() {
    if (!isBrowserOpened) {
      FirefoxProfile profile = new FirefoxProfile();
      DesiredCapabilities dc = new DesiredCapabilities();
      dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
      dc.setCapability(FirefoxDriver.PROFILE, profile);

      profile.setEnableNativeEvents(true);

      profile.setPreference("browser.download.folderList", 2);
      profile.setPreference("browser.download.manager.showWhenStarting", false);
      profile.setPreference(
          "browser.download.dir", System.getProperty("user.dir") + "\\src\\Download");
      profile.setPreference(
          "browser.download.downloadDir", System.getProperty("user.dir") + "\\src\\Download");
      profile.setPreference(
          "browser.download.defaultFolder", System.getProperty("user.dir") + "\\src\\Download");
      profile.setPreference("browser.download.manager.closeWhenDone", true);
      profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");

      if (CONFIG.getProperty("browserType").equalsIgnoreCase("Firefox")
          || CONFIG.getProperty("browserType").equalsIgnoreCase("FF")) {
        driver = new FirefoxDriver(profile);
      } else if (CONFIG.getProperty("browserType").equals("InternetExplorer")
          || CONFIG.getProperty("browserType").equalsIgnoreCase("IE")) {
        System.setProperty(
            "webdriver.ie.driver",
            System.getProperty("user.dir") + "\\src\\drivers\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
      } else if (CONFIG.getProperty("browserType").equals("GoogleChrome")
          || CONFIG.getProperty("browserType").equalsIgnoreCase("CHROME")) {
        System.setProperty(
            "webdriver.chrome.driver",
            System.getProperty("user.dir") + "\\src\\drivers\\chromedriver.exe");
        driver = new ChromeDriver();
      }
      driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
      wait = new WebDriverWait(driver, 2);
      driver.manage().window().maximize();
      driver.manage().deleteAllCookies();
      isBrowserOpened = true;
      driver.get(CONFIG.getProperty("baseUrl"));
      APP_LOGS.debug("Selecting the Browser");
    }
  }
  @Test
  public void shouldBeAbleToUseTheSameProfileMoreThanOnce() {
    FirefoxProfile profile = new FirefoxProfile();

    profile.setPreference("browser.startup.homepage", pages.formPage);

    WebDriver one = null;
    WebDriver two = null;

    try {
      one = newFirefoxDriver(profile);
      two = newFirefoxDriver(profile);

      // If we get this far, then both firefoxes have started. If this test
      // two browsers will start, but the second won't have a valid port and an
      // exception will be thrown. Hurrah! Test passes.
    } finally {
      if (one != null) one.quit();
      if (two != null) two.quit();
    }
  }
  /*
   * 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;
  }
 @Test
 public void layoutOnDiskSetsUserPreferences() throws IOException {
   profile.setPreference("browser.startup.homepage", "http://www.example.com");
   Preferences parsedPrefs = parseUserPrefs(profile);
   assertEquals("http://www.example.com", parsedPrefs.getPreference("browser.startup.homepage"));
 }
  @Test
  public void shouldSetBooleanPreferences() throws Exception {
    profile.setPreference("cheese", false);

    assertPreferenceValueEquals("cheese", false);
  }
  private static EventFiringWebDriver getFFInstance() {
    // Windows 8 requires to set webdriver.firefox.bin system variable
    // to path where executive file of FF is placed
    if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
      System.setProperty(
          "webdriver.firefox.bin",
          "c:"
              + File.separator
              + "Program Files (x86)"
              + File.separator
              + "Mozilla Firefox"
              + File.separator
              + "Firefox.exe");
    }

    // Check if user who is running tests have write access in ~/.mozilla dir and home dir
    if ("LINUX".equals(System.getProperty("os.name").toUpperCase())) {
      File homePath = new File(System.getenv("HOME") + File.separator);
      File mozillaPath = new File(homePath + File.separator + ".mozilla");
      File tmpFile;
      if (mozillaPath.exists()) {
        try {
          tmpFile = File.createTempFile("webdriver", null, mozillaPath);
        } catch (IOException ex) {
          PageObjectLogging.log("Can't create file", ex, false);
          throw new WebDriverException(
              "Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
        }
      } else {
        try {
          tmpFile = File.createTempFile("webdriver", null, homePath);
        } catch (IOException ex) {
          PageObjectLogging.log("Can't create file", ex, false);
          throw new WebDriverException(
              "Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
        }
      }
      tmpFile.delete();
    }

    firefoxProfile =
        new FirefoxProfile(
            new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));

    if (unstablePageLoadStrategy) {
      firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
    }

    if ("true".equals(Configuration.getDisableFlash())) {
      firefoxProfile.setPreference("plugin.state.flash", 0);
    }

    caps.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

    // Adding console logging for FF browser
    setBrowserLogging(Level.SEVERE);

    ExtHelper.addExtensions(Configuration.getExtensions());

    return new EventFiringWebDriver(new FirefoxDriver(caps));
  }
 private static void setFFUserAgent(String userAgent) {
   firefoxProfile.setPreference(
       "general.useragent.override", userAgentRegistry.getUserAgent(userAgent));
 }
  public DesiredCapabilities getFirefoxCapabilities() throws IOException {

    TryFunction<String, String> path =
        location -> Paths.get(ClassLoader.getSystemResource(location).toURI()).toString();

    String firebugPath = path.apply("firebug_plugin/firebug-2.0.11-fx.xpi");
    String firePathPath = path.apply("firebug_plugin/firepath-0.9.7.1-fx.xpi");
    String netExportPath = path.apply("firebug_plugin/netExport-0.9b6.xpi");

    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.addExtension(new File(firebugPath));
    firefoxProfile.addExtension(new File(firePathPath));
    firefoxProfile.addExtension(new File(netExportPath));
    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("extensions.firebug.currentVersion", "2.0.11");
    firefoxProfile.setPreference("extensions.firebug.onByDefault", true);
    firefoxProfile.setPreference("extensions.firebug.previousPlacement", 2);
    firefoxProfile.setPreference("extensions.firebug.netFilterCategories", "xhr");
    firefoxProfile.setPreference("extensions.firebug.defaultPanelName", "net");
    firefoxProfile.setPreference("extensions.firebug.net.enableSites", true);
    firefoxProfile.setPreference("extensions.firebug.net.persistent", true);
    firefoxProfile.setPreference("extensions.firebug.netexport.autoExportToServer", false);
    firefoxProfile.setPreference(
        "extensions.firebug.netexport.defaultLogDir", System.getProperty("user.dir"));
    firefoxProfile.setPreference("extensions.firebug.netexport.showPreview", false);
    firefoxProfile.setPreference("extensions.firebug.netexport.sendToConfirmation", false);
    firefoxProfile.setPreference("extensions.firebug.netexport.pageLoadedTimeout", 360000);
    firefoxProfile.setPreference("extensions.firebug.netexport.timeout", 360000);
    firefoxProfile.setPreference("extensions.firebug.netexport.Automation", true);
    firefoxProfile.setPreference("extensions.firebug.netexport.compress", false);
    firefoxProfile.setPreference("extensions.firebug.netexport.includeResponseBodies", true);
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
    return addProxySettings(capabilities, proxy());
  }
  public static void main(String[] args) throws Exception {

    FirefoxProfile ffProfile = new FirefoxProfile();
    ffProfile.setPreference("network.http.phishy-userpass-length", 255);
    WebDriver driver = new FirefoxDriver(ffProfile);
    driver.get(Configuration.baseurl);
    Thread.sleep(3000);

    WebElement ExpandMobileTree = driver.findElement(By.xpath(Configuration.ExpandMobile));
    ExpandMobileTree.click();
    Thread.sleep(3000);

    WebElement ExpandSegmentTree = driver.findElement(By.xpath(Configuration.ExpandSegment));
    ExpandSegmentTree.click();
    Thread.sleep(6000);

    WebElement Segment1 = driver.findElement(By.xpath(Configuration.MobileSegment));
    Segment1.click();
    Thread.sleep(6000);

    WebElement Header = driver.findElement(By.xpath(Configuration.Header));
    Header.click();
    Thread.sleep(6000);

    WebElement Menu = driver.findElement(By.xpath(Configuration.Menu));
    Menu.click();
    Thread.sleep(6000);

    WebElement ContentTypeHint_1 = driver.findElement(By.xpath(Configuration.ContentTypeHint));

    Select selectBoxControlledSearch = new Select(ContentTypeHint_1);

    selectBoxControlledSearch.selectByValue(Configuration.Menu_hint);
    Thread.sleep(6000);

    WebElement saveHeader = driver.findElement(By.xpath(Configuration.Save));
    saveHeader.click();
    Thread.sleep(3000);

    WebElement insert = driver.findElement(By.xpath(Configuration.InsertPackage));
    insert.click();
    Thread.sleep(8000);

    WebElement CreateNewPackage = driver.findElement(By.xpath(Configuration.CreateNewPackage));
    CreateNewPackage.click();
    Thread.sleep(6000);

    WebElement EditPackage = driver.findElement(By.xpath(Configuration.NewPackage));
    EditPackage.click();
    Thread.sleep(6000);

    WebElement renamePane6 =
        driver.findElement(By.xpath("//div[@id='contents']/form/ul/li[2]/input"));
    renamePane6.clear();
    renamePane6.sendKeys("Touch header - Menu - sport section");
    Thread.sleep(100);

    WebElement renamePaneTitle6 =
        driver.findElement(By.xpath("//div[@id='contents']/form/ul/li[3]/input"));
    renamePaneTitle6.sendKeys("sport");
    Thread.sleep(100);

    WebElement save = driver.findElement(By.xpath(Configuration.Save));
    save.click();
    Thread.sleep(1000);

    WebElement Link1 = driver.findElement(By.id(Configuration.InsertMedia));

    Select selectList1 = new Select(Link1);
    // select link
    selectList1.selectByValue(Configuration.Link);

    WebElement AddLink = driver.findElement(By.xpath(Configuration.Add));
    AddLink.click();
    Thread.sleep(6000);

    WebElement urlText1 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText1.sendKeys("http://orangeworld.co.uk/p/cricket/home");
    WebElement LinkText1 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText1.sendKeys("cricket");
    WebElement reportingEnable1 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable1.click();
    WebElement reportingCampaign1 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign1.sendKeys("menu");
    WebElement reportingID1 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID1.sendKeys("header");
    WebElement AddLink1 = driver.findElement(By.xpath(Configuration.Add));
    AddLink1.click();
    Thread.sleep(3000);

    WebElement urlText2 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText2.sendKeys("http://orangeworld.co.uk/p/sportheadlines/home");
    WebElement LinkText2 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText2.sendKeys("sport headlines");
    WebElement reportingEnable2 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable2.click();
    WebElement reportingCampaign2 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign2.sendKeys("menu");
    WebElement reportingID2 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID2.sendKeys("header");
    WebElement AddLink2 = driver.findElement(By.xpath(Configuration.Add));
    AddLink2.click();
    Thread.sleep(3000);

    WebElement urlText3 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText3.sendKeys("http://orangeworld.co.uk/p/sport/livescores");
    WebElement LinkText3 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText3.sendKeys("live scores");
    WebElement reportingEnable3 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable3.click();
    WebElement reportingCampaign3 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign3.sendKeys("menu");
    WebElement reportingID3 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID3.sendKeys("header");
    WebElement AddLink3 = driver.findElement(By.xpath(Configuration.Add));
    AddLink3.click();
    Thread.sleep(3000);

    WebElement urlText4 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText4.sendKeys("http://orangeworld.co.uk/p/football/home");
    WebElement LinkText4 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText4.sendKeys("football homepage");
    WebElement reportingEnable4 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable4.click();
    WebElement reportingCampaign4 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign4.sendKeys("menu");
    WebElement reportingID4 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID4.sendKeys("header");
    WebElement AddLink4 = driver.findElement(By.xpath(Configuration.Add));
    AddLink4.click();
    Thread.sleep(3000);

    WebElement urlText5 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText5.sendKeys("http://orangeworld.co.uk/p/sport/home");
    WebElement LinkText5 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText5.sendKeys("sports homepage");
    WebElement reportingEnable5 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable5.click();
    WebElement reportingCampaign5 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign5.sendKeys("menu");
    WebElement reportingID5 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID5.sendKeys("header");
    WebElement AddLink5 = driver.findElement(By.xpath(Configuration.Add));
    AddLink5.click();
    Thread.sleep(3000);

    WebElement saveSportsLinks = driver.findElement(By.xpath(Configuration.Save));
    saveSportsLinks.click();
    Thread.sleep(1000);

    WebElement BackToMenu = driver.findElement(By.xpath(Configuration.HL_Favourites_LV));
    BackToMenu.click();
    Thread.sleep(3000);

    WebElement Menu1 = driver.findElement(By.xpath(Configuration.Menu));
    Menu1.click();
    Thread.sleep(6000);

    WebElement insert1 = driver.findElement(By.xpath(Configuration.InsertPackage));
    insert1.click();
    Thread.sleep(8000);

    WebElement CreateNewPackage1 = driver.findElement(By.xpath(Configuration.CreateNewPackage));
    CreateNewPackage1.click();
    Thread.sleep(6000);

    WebElement EditPackage1 = driver.findElement(By.xpath(Configuration.NewPackage));
    EditPackage1.click();
    Thread.sleep(6000);

    WebElement renamePane1 =
        driver.findElement(By.xpath("//div[@id='contents']/form/ul/li[2]/input"));
    renamePane1.clear();
    renamePane1.sendKeys("Touch header - Menu - news and weather section");
    Thread.sleep(100);

    WebElement renamePaneTitle1 =
        driver.findElement(By.xpath("//div[@id='contents']/form/ul/li[3]/input"));
    renamePaneTitle1.sendKeys("news & weather");
    Thread.sleep(100);

    WebElement saveNews = driver.findElement(By.xpath(Configuration.Save));
    saveNews.click();
    Thread.sleep(1000);

    WebElement urlText6 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText6.sendKeys("http://orangeworld.co.uk/p/gambling/lotto_cashgames");
    WebElement LinkText6 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText6.sendKeys("lottery results");
    WebElement reportingEnable6 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable6.click();
    WebElement reportingCampaign6 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign6.sendKeys("menu");
    WebElement reportingID6 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID6.sendKeys("header");
    WebElement AddLink6 = driver.findElement(By.xpath(Configuration.Add));
    AddLink6.click();
    Thread.sleep(3000);

    WebElement urlText7 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText7.sendKeys("http://orangeworld.co.uk/p/newsandweather/weather");
    WebElement LinkText7 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText7.sendKeys("weather forecast");
    WebElement reportingEnable7 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable7.click();
    WebElement reportingCampaign7 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign7.sendKeys("menu");
    WebElement reportingID7 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID7.sendKeys("header");
    WebElement AddLink7 = driver.findElement(By.xpath(Configuration.Add));
    AddLink7.click();
    Thread.sleep(3000);

    WebElement urlText8 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText8.sendKeys(
        "http://orangeworld.co.uk/articleindex/0/?package=general headline&provider=Sky News");
    WebElement LinkText8 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText8.sendKeys("Sky News headlines");
    WebElement reportingEnable8 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable8.click();
    WebElement reportingCampaign8 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign8.sendKeys("menu");
    WebElement reportingID8 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID8.sendKeys("header");
    WebElement AddLink8 = driver.findElement(By.xpath(Configuration.Add));
    AddLink8.click();
    Thread.sleep(3000);

    WebElement urlText9 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[3]/input"));
    urlText9.sendKeys("http://orangeworld.co.uk/p/newsandweather/home");
    WebElement LinkText9 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[4]/input"));
    LinkText9.sendKeys("news & weather homepage");
    WebElement reportingEnable9 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[8]/input"));
    reportingEnable9.click();
    WebElement reportingCampaign9 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[9]/input"));
    reportingCampaign9.sendKeys("menu");
    WebElement reportingID9 =
        driver.findElement(By.xpath("//div[@class='editFormContainer']//li[10]/input"));
    reportingID9.sendKeys("header");
    WebElement AddLink9 = driver.findElement(By.xpath(Configuration.Add));
    AddLink9.click();
    Thread.sleep(3000);

    WebElement save2 = driver.findElement(By.xpath(Configuration.Save));
    save2.click();
    Thread.sleep(1000);
  }