List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile
public FirefoxProfile(File profileDir)
From source file:com.elastica.browserfactory.FirefoxCapabilitiesFactory.java
License:Apache License
protected FirefoxProfile createFirefoxProfile(final String path) { if (path != null) { return new FirefoxProfile(new File(path)); } else {/* w w w. ja va2s .com*/ return new FirefoxProfile(); } }
From source file:com.galois.fiveui.drivers.Drivers.java
License:Apache License
/** * Return a new Firefox webdriver./*from ww w.j ava2 s . c o m*/ * @param ffProfile Directory path for the desired Firefox profile to use. If * null a temporary blank profile is used. * @return */ public static FirefoxDriver buildFFDriver(String ffProfile) { File profileDir; if (null == ffProfile) { profileDir = Files.createTempDir(); profileDir.deleteOnExit(); } else { profileDir = new File(ffProfile); } System.out.println("com.galois.fiveui.drivers: using directory for Firefox profile: " + profileDir); FirefoxProfile profile = new FirefoxProfile(profileDir); String ffBinaryPath = System.getProperty(FIREFOX_BIN_PATH); FirefoxDriver driver; if (null == ffBinaryPath) { System.err.println("WARNING: Running essentially random version of Firefox!"); System.err.println(" set a path to firefox with -D" + FIREFOX_BIN_PATH + "=<path to firefox>"); driver = new FirefoxDriver(profile); } else { FirefoxBinary binary = new FirefoxBinary(new File(ffBinaryPath)); driver = new FirefoxDriver(binary, profile); } return driver; }
From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java
License:Open Source License
/** * initialization FF with some profile//w ww . j av a 2s .c o m * Use it if you want to use your profile for FF. It doesn't work remotely. * Before running create your profile. Use cmd : firefox.exe -ProfileManager -no-remote * * @param path - profile path */ public static void initFFProfile(String path) { ReporterNGExt.logTechnical(String.format("Initialization Firefox Driver with Profile '%s'", path)); File profileDir = new File(path); FirefoxProfile ffprofile = new FirefoxProfile(profileDir); ffprofile.setEnableNativeEvents(true); setWebDriver(new FirefoxDriver(ffprofile)); getDriver().manage().window().maximize(); }
From source file:com.screenslicer.core.scrape.Scrape.java
License:Open Source License
private static void start(int pageLoadTimeout, Proxy proxy) { for (int i = 0; i < RETRIES; i++) { try {//from w ww. j av a2s. com FirefoxProfile profile = new FirefoxProfile(new File("./firefox-profile")); if (proxy != null) { if (!CommonUtil.isEmpty(proxy.username) || !CommonUtil.isEmpty(proxy.password)) { String user = proxy.username == null ? "" : proxy.username; String pass = proxy.password == null ? "" : proxy.password; profile.setPreference("extensions.closeproxyauth.authtoken", Base64.encodeBase64String((user + ":" + pass).getBytes("utf-8"))); } else { profile.setPreference("extensions.closeproxyauth.authtoken", ""); } if (Proxy.TYPE_SOCKS_5.equals(proxy.type) || Proxy.TYPE_SOCKS_4.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.socks", proxy.ip); profile.setPreference("network.proxy.socks_port", proxy.port); profile.setPreference("network.proxy.socks_remote_dns", true); profile.setPreference("network.proxy.socks_version", Proxy.TYPE_SOCKS_5.equals(proxy.type) ? 5 : 4); } else if (Proxy.TYPE_SSL.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.ssl", proxy.ip); profile.setPreference("network.proxy.ssl_port", proxy.port); } else if (Proxy.TYPE_HTTP.equals(proxy.type)) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxy.ip); profile.setPreference("network.proxy.http_port", proxy.port); } } driver = new FirefoxDriver(profile); driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(pageLoadTimeout, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); break; } catch (Throwable t1) { if (driver != null) { try { forceQuit(); driver = null; } catch (Throwable t2) { Log.exception(t2); } } Log.exception(t1); } } }
From source file:com.sebuilder.interpreter.webdriverfactory.Firefox.java
License:Apache License
/** * @param config Key/value pairs treated as required capabilities, with the exception of: * <ul>/*from ww w . j a v a 2 s. c o m*/ * <li>binary: path to Firefox binary to use</li> * <li>profile: path to Firefox profile to use</li> * </ul> * @return A FirefoxDriver. */ @Override public RemoteWebDriver make(HashMap<String, String> config) { FirefoxBinary fb = config.containsKey("binary") ? new FirefoxBinary(new File(config.get("binary"))) : new FirefoxBinary(); FirefoxProfile fp = config.containsKey("profile") ? new FirefoxProfile(new File(config.get("profile"))) : new FirefoxProfile(); HashMap<String, String> caps = new HashMap<String, String>(config); caps.remove("binary"); caps.remove("profile"); return new FirefoxDriver(fb, fp, new DesiredCapabilities(caps)); }
From source file:com.thoughtworks.selenium.SeleneseTestBaseVir.java
License:Apache License
/** * Sets the up./*from ww w.ja va2s . c om*/ * * @param instanceName * the instance name * @param browserName * the browser string * @param serverConfig * the server config */ public final void setUp(final String instanceName, final String browserName, final String serverConfig) { this.configWebDriver(browserName); seleniumInstanceName = instanceName; if (!serverConfig.isEmpty()) { String[] commandSet = serverConfig.split(","); int commandIndex = 0; int inputIndex = 1; for (String fullCommand : commandSet) { try { String command = fullCommand.split("=")[commandIndex].toLowerCase(Locale.getDefault()); String input = fullCommand.split("=")[inputIndex]; if ("firefoxprofile".equalsIgnoreCase(command)) { try { setDefaultProfile(new FirefoxProfile(new File(input))); } catch (Exception e) { log.error("Cannot find the firefox profile. Switching to the default.", e); e.printStackTrace(); } } } catch (Exception e) { log.error("Unexpected error occured.", e); throw new IllegalArgumentException( "Cannot configure selenium with given server configuration : " + serverConfig, e); } } } }
From source file:com.vaadin.testbench.parallel.setup.LocalDriver.java
/** * Creates a {@link WebDriver} instance used for running the test locally * for debug purposes./*from w ww. j a v a2 s.co m*/ */ static public WebDriver createDriver(DesiredCapabilities desiredCapabilities) { WebDriver driver; if (BrowserUtil.isFirefox(desiredCapabilities)) { String firefoxPath = System.getProperty("firefox.path"); String profilePath = System.getProperty("firefox.profile.path"); if (firefoxPath != null) { if (profilePath != null) { File profileDir = new File(profilePath); FirefoxProfile profile = new FirefoxProfile(profileDir); driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), profile); } else { driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), null); } } else { driver = new FirefoxDriver(); } } else if (BrowserUtil.isChrome(desiredCapabilities)) { // Tells chrome not to show warning // "You are using an unsupported command-line flag: --ignore-certifcate-errors". // #14319 ChromeOptions options = new ChromeOptions(); options.addArguments("--test-type "); driver = new ChromeDriver(options); } else if (BrowserUtil.isSafari(desiredCapabilities)) { driver = new SafariDriver(); } else if (BrowserUtil.isPhantomJS(desiredCapabilities)) { driver = new PhantomJSDriver(); } else { throw new RuntimeException( "Not implemented support for running locally on " + desiredCapabilities.getBrowserName()); } return TestBench.createDriver(driver); }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public FirefoxProfile getDefaultProfile() { String profileName = this.nameOfpro; File profileDir = profiles.get(profileName); if (profileDir == null) return null; // Make a copy of the profile to use File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("userprofile", "copy"); try {/*w w w. j av a 2s. c om*/ FileHandler.copy(profileDir, tempDir); // Delete the old compreg.dat file so that our new extension is registered File compreg = new File(tempDir, "compreg.dat"); if (compreg.exists()) { if (!compreg.delete()) { throw new WebDriverException("Cannot delete file from copy of profile " + profileName); } } } catch (IOException e) { throw new WebDriverException(e); } return new FirefoxProfile(tempDir); }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public FirefoxProfile getProfile(String profileName) { File profileDir = profiles.get(profileName); if (profileDir == null) return null; // Make a copy of the profile to use File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("userprofile", "copy"); try {//from ww w . j ava 2 s .c o m FileHandler.copy(profileDir, tempDir); // Delete the old compreg.dat file so that our new extension is registered File compreg = new File(tempDir, "compreg.dat"); if (compreg.exists()) { if (!compreg.delete()) { throw new WebDriverException("Cannot delete file from copy of profile " + profileName); } } } catch (IOException e) { throw new WebDriverException(e); } return new FirefoxProfile(tempDir); }
From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java
License:Apache License
@Override public WebDriver createWebDriver(Map<String, String> options, DesiredCapabilities capabilities) throws IOException { ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY)); WebDriver wd = null;/*from www .j av a 2 s .c o m*/ DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities); String browser = properties.getBrowser(); if (properties.isUseGrid()) { RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities); remoteWebDriver.setFileDetector(new LocalFileDetector()); wd = remoteWebDriver; } else { if (browser == null || browser.equals("")) { throw new RuntimeException( "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit."); } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore") || browser.equalsIgnoreCase("*iexplore")) { String webdriverIEDriver = properties.getWebDriverIEDriver(); if (webdriverIEDriver != null) { System.setProperty("webdriver.ie.driver", webdriverIEDriver); } String browserVersion = properties.getBrowserVersion(); if (browserVersion == null || browserVersion.equals("")) { throw new RuntimeException( "When using IE as the browser, please set 'browser.version' in client properties"); } else { if (browserVersion.startsWith("9")) { desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); desiredCapabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); wd = new InternetExplorerDriver(desiredCapabilities); } else { wd = new InternetExplorerDriver(desiredCapabilities); } } } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) { final String ffProfileFolder = properties.getFirefoxProfileFolder(); final String ffProfileFile = properties.getFirefoxProfileFile(); final String path = properties.getFfBinaryPath(); final FirefoxProfile ffp; if (ffProfileFolder != null) { ffp = new FirefoxProfile(new File(ffProfileFolder)); } else { ffp = new FirefoxProfile(); } if (ffProfileFile != null) { addPreferences(ffp, ffProfileFile); } addPreferences(ffp, properties); List<String> ffExtensions = properties.getFirefoxExtensions(); if (ffExtensions != null && ffExtensions.size() > 0) { addExtensionsToFirefoxProfile(ffp, ffExtensions); } if (path != null) { FirefoxBinary fireFox = getFFBinary(path); wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities); } else { wd = new FirefoxDriver(new FirefoxBinary(), ffp, desiredCapabilities); } } else if (browser.equalsIgnoreCase("chrome")) { final String webdriverChromeDriver = properties.getWebDriverChromeDriver(); if (webdriverChromeDriver != null) { System.setProperty("webdriver.chrome.driver", webdriverChromeDriver); } final ChromeOptions chromeOptions = new ChromeOptions(); final String chromeBinaryPath = properties.getChromeBinaryPath(); if (chromeBinaryPath != null) { chromeOptions.setBinary(chromeBinaryPath); } if (properties.getAcceptedLanguages() != null) { final Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("intl.accept_languages", properties.getAcceptedLanguages()); chromeOptions.setExperimentalOption("prefs", prefs); } desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); wd = new ChromeDriver(desiredCapabilities); } else if (browser.equalsIgnoreCase("safari")) { wd = new SafariDriver(desiredCapabilities); } else if (browser.equalsIgnoreCase("htmlunit")) { final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45; if (properties.getAcceptedLanguages() != null) { browserVersion.setBrowserLanguage(properties.getAcceptedLanguages().split(",")[0]); } wd = new HtmlUnitDriver(browserVersion); ((HtmlUnitDriver) wd).setJavascriptEnabled(true); } else if (browser.equalsIgnoreCase("phantomjs")) { final String webdriverPhantomJSDriver = properties.getWebDriverPhantomJSDriver(); if (properties.getAcceptedLanguages() != null) { desiredCapabilities.setCapability("phantomjs.page.customHeaders.Accept-Language", properties.getAcceptedLanguages()); } if (webdriverPhantomJSDriver != null) { desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, webdriverPhantomJSDriver); wd = new PhantomJSDriver(desiredCapabilities); } else { wd = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), desiredCapabilities); } } else { throw new IllegalArgumentException("Unsupported browser type: " + browser + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit, phantomjs."); } // move browser windows to specific position. It's useful for // debugging... final int browserInitPositionX = properties.getBrowserInitPositionX(); final int browserInitPositionY = properties.getBrowserInitPositionY(); if (browserInitPositionX != 0 || browserInitPositionY != 0) { wd.manage().window().setSize(new Dimension(1280, 1024)); wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY)); } wd.manage().timeouts().implicitlyWait(properties.getAppearWaitTime(), TimeUnit.MILLISECONDS); } return wd; }