Java Code Examples for org.openqa.selenium.firefox.FirefoxProfile

The following examples show how to use org.openqa.selenium.firefox.FirefoxProfile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void main(String... args) throws IOException {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.addExtension(
                new File("./src/test/resources/extensions/xpath_finder.xpi"));

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

        try {
            driver.get("http://www.google.com");
        } finally {
            driver.quit();
        }

    }
 
Example 2
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.shell.checkDefaultBrowser", true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setAcceptUntrustedCertificates(false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example 3
FirefoxProfile createProfile() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("app.update.enabled", false);
    
    String userAgentOverride = getUserAgentOverride();
    if (StringUtils.isNotEmpty(userAgentOverride)) {
        profile.setPreference("general.useragent.override", userAgentOverride);
    }
    
    String ntlmOverride = getNtlmSetting();
    if (StringUtils.isNotEmpty(ntlmOverride)) {
        profile.setPreference("network.negotiate-auth.allow-insecure-ntlm-v1", true);
    }

    addExtensions(profile);
    setPreferences(profile);

    return profile;
}
 
Example 4
private void setPreferences(FirefoxProfile profile) {
    JMeterProperty property = getProperty(PREFERENCES);
    if (property instanceof NullProperty) {
        return;
    }
    CollectionProperty rows = (CollectionProperty) property;
    for (int i = 0; i < rows.size(); i++) {
        ArrayList row = (ArrayList) rows.get(i).getObjectValue();
        String name = ((JMeterProperty) row.get(0)).getStringValue();
        String value = ((JMeterProperty) row.get(1)).getStringValue();
        switch (value) {
            case "true":
                profile.setPreference(name, true);
                break;
            case "false":
                profile.setPreference(name, false);
                break;
            default:
                profile.setPreference(name, value);
                break;
        }
    }
}
 
Example 5
public static DesiredCapabilities build(RemoteCapability capability){
 DesiredCapabilities desiredCapabilities;
 if(RemoteCapability.CHROME.equals(capability)){
  ChromeOptions options = new ChromeOptions();
     desiredCapabilities = DesiredCapabilities.chrome();
     desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
  return desiredCapabilities;
 } else if (RemoteCapability.FIREFOX.equals(capability)){
  FirefoxProfile profile = new FirefoxProfile();
  desiredCapabilities = DesiredCapabilities.firefox();
  desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
  return desiredCapabilities;
 } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)){
  desiredCapabilities = DesiredCapabilities.internetExplorer();
  return desiredCapabilities;
 } else if (RemoteCapability.PHANTOMJS.equals(capability)){
  desiredCapabilities = DesiredCapabilities.phantomjs();
  return desiredCapabilities;
 }
 throw new IllegalArgumentException("No such capability");
}
 
Example 6
Source Project: jsflight   Source File: SeleniumDriver.java    License: Apache License 2.0 6 votes vote down vote up
private FirefoxProfile createDefaultFirefoxProfile()
{
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("nglayout.initialpaint.delay", "0");
    firefoxProfile.setPreference("network.http.pipelining", true);
    firefoxProfile.setPreference("image.animation_mode", "none");
    firefoxProfile.setPreference("layers.acceleration.force-enabled", true);
    firefoxProfile.setPreference("layers.offmainthreadcomposition.enabled", true);
    firefoxProfile.setPreference("browser.sessionstore.interval", 3600000);
    firefoxProfile.setPreference("privacy.trackingprotection.enabled", true);
    firefoxProfile.setPreference("content.notify.interval", 849999);
    firefoxProfile.setPreference("content.notify.backoffcount", 5);
    firefoxProfile.setPreference("network.http.max-connections", 50);
    firefoxProfile.setPreference("network.http.max-connections-per-server", 150);
    firefoxProfile.setPreference("network.http.pipelining.aggressive", false);
    firefoxProfile.setPreference("browser.tabs.animate", false);
    firefoxProfile.setPreference("browser.display.show_image_placeholders", false);
    firefoxProfile.setPreference("browser.cache.use_new_backend", 1);
    firefoxProfile.setPreference("ui.submenuDelay", 0);
    firefoxProfile.setPreference("browser.cache.disk.enable", false);
    firefoxProfile.setPreference("browser.cache.memory.enable", true);
    firefoxProfile.setPreference("browser.cache.memory.capacity", 128000);
    return firefoxProfile;
}
 
Example 7
/**
     * 
     * @param firefoxProfile
     * @return an initialised instance of TestRunFactory
     */
    private TestRunFactory initTestRunFactory (FirefoxProfile firefoxProfile){
        TgTestRunFactory testRunFactory = new TgTestRunFactory();
        testRunFactory.addNewPageListener(this);
        testRunFactory.setFirefoxProfile(firefoxProfile);
        testRunFactory.setJsScriptMap(jsScriptMap);
        if (implicitelyWaitDriverTimeout != -1) {
            testRunFactory.setImplicitlyWaitDriverTimeout(implicitelyWaitDriverTimeout);
        }
        testRunFactory.setPageLoadDriverTimeout(pageLoadDriverTimeout);
        
        testRunFactory.setScreenHeight(
                Integer.valueOf(
                        parameterDataService.getParameter(
                                webResource.getAudit(), ParameterElement.SCREEN_HEIGHT_KEY).getValue()));
        testRunFactory.setScreenWidth(
                Integer.valueOf(
                        parameterDataService.getParameter(
                                webResource.getAudit(), ParameterElement.SCREEN_WIDTH_KEY).getValue()));
//      ((TgTestRunFactory)testRunFactory).setFirefoxDriverObjectPool(firefoxDriverObjectPool);
        return testRunFactory;
    }
 
Example 8
/**
     * 
     * @return 
     *      a set-up Firefox profile
     */
    private FirefoxProfile getProfile(boolean loadImage) {
        if (StringUtils.isNotBlank(pathToPreSetProfile)) {
            File presetProfileDir = new File(pathToPreSetProfile);
            if (presetProfileDir.exists() 
                  && presetProfileDir.canRead() 
                  && presetProfileDir.canExecute()
                  && presetProfileDir.canWrite()) {
                Logger.getLogger(this.getClass()).debug(
                        "Start firefox profile with path " 
                        + presetProfileDir.getAbsolutePath());
                return new FirefoxProfile(presetProfileDir);
            } else {
                Logger.getLogger(this.getClass()).debug(
                        "The profile with path " 
                        + presetProfileDir.getAbsolutePath()
                        + " doesn't exist or don't have permissions");
            }
        }
        Logger.getLogger(this.getClass()).debug("Start firefox with fresh new profile");
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        setUpPreferences(firefoxProfile, loadImage);
//        setUpExtensions(firefoxProfile);
        setUpProxy(firefoxProfile);
        return firefoxProfile;
    }
 
Example 9
Source Project: hsac-fitnesse-fixtures   Source File: LocalDriverFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set firefox profile. For example to make sure text/csv file is downloaded without asking (convenient if run on buildserver), do:
 * |script           |selenium driver setup                                                                                               |
 * |start driver for |firefox              |with profile|!{browser.download.folderList:2,browser.helperApps.neverAsk.saveToDisk:text/csv}||
 * @param profile setting from subtable
 * @return firefox profile with specified settings
 */
public static FirefoxProfile getFirefoxProfile(Map<String, Object> profile) {
    FirefoxProfile fxProfile = new FirefoxProfile();
    if (profile != null) {
        for (Map.Entry<String, Object> profileEntry : profile.entrySet()) {
            String key = profileEntry.getKey();
            Object value = profileEntry.getValue();
            if (value instanceof Boolean) {
                fxProfile.setPreference(key, (Boolean) value);
            } else if (value instanceof Integer) {
                fxProfile.setPreference(key, (Integer) value);
            } else if (value == null) {
                fxProfile.setPreference(key, null);
            } else {
                fxProfile.setPreference(key, value.toString());
            }
        }
    }
    return fxProfile;
}
 
Example 10
Source Project: rice   Source File: JiraIssueCreation.java    License: Educational Community License v2.0 6 votes vote down vote up
private void login() throws InterruptedException {DesiredCapabilities capabilities = new DesiredCapabilities();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(false);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    driver.get(jiraBase + "/secure/Dashboard.jspa");

    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.className("login-link"),
            this.getClass().toString()).click();

    // CAS
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"),
            this.getClass().toString());
    driver.findElement(By.id("username")).sendKeys(System.getProperty("cas.username"));
    driver.findElement(By.id("password")).sendKeys(System.getProperty("cas.password"));
    driver.findElement(By.name("submit")).click();
}
 
Example 11
Source Project: selenium   Source File: XpiDriverService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected XpiDriverService createDriverService(
    File exe,
    int port,
    Duration timeout,
    List<String> args,
    Map<String, String> environment) {
  try {
    return new XpiDriverService(
        exe,
        port,
        timeout,
        args,
        environment,
        binary == null ? new FirefoxBinary() : binary,
        profile == null ? new FirefoxProfile() : profile,
        getLogFile());
  } catch (IOException e) {
    throw new WebDriverException(e);
  }
}
 
Example 12
Source Project: selenium   Source File: XpiDriverServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void builderPassesTimeoutToDriverService() {
  File exe = new File("someFile");
  Duration defaultTimeout = Duration.ofSeconds(45);
  Duration customTimeout = Duration.ofSeconds(60);

  FirefoxProfile mockProfile = mock(FirefoxProfile.class);
  FirefoxBinary mockBinary = mock(FirefoxBinary.class);
  XpiDriverService.Builder builderMock = spy(XpiDriverService.Builder.class);
  builderMock.withProfile(mockProfile);
  builderMock.withBinary(mockBinary);
  doReturn(exe).when(builderMock).findDefaultExecutable();
  builderMock.build();

  verify(builderMock).createDriverService(any(), anyInt(), eq(defaultTimeout), any(), any());

  builderMock.withTimeout(customTimeout);
  builderMock.build();
  verify(builderMock).createDriverService(any(), anyInt(), eq(customTimeout), any(), any());
}
 
Example 13
@Override
public void start() throws CandybeanException {
	String profileName = candybean.config.getValue("browser.firefox.profile", "default");
	File ffBinaryPath = new File(candybean.config.getPathValue("browser.firefox.binary"));
	if(!ffBinaryPath.exists()){
		String error = "Unable to find firefox browser driver from the specified location in the configuration file! \n"
				+ "Please add a configuration to the candybean config file for key \"browser.firefox.binary\" that"
				+ "indicates the location of the binary.";
		logger.severe(error);
		throw new CandybeanException(error);
	} else {
		FirefoxProfile ffProfile = (new ProfilesIni()).getProfile(profileName);
		FirefoxBinary ffBinary = new FirefoxBinary(ffBinaryPath);
		logger.info("Instantiating Firefox with profile name: "
				+ profileName + " and binary path: " + ffBinaryPath);
		super.wd = new FirefoxDriver(ffBinary, ffProfile);
		super.start(); // requires wd to be instantiated first
	}
}
 
Example 14
Source Project: at.info-knowledge-base   Source File: FireFoxProxyViaProfile.java    License: MIT License 6 votes vote down vote up
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", proxyIp);
    profile.setPreference("network.proxy.http_port", port);

    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    //or
    //driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
 
Example 15
Source Project: submarine   Source File: FirefoxWebDriverProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver createWebDriver(String webDriverPath) {
  FirefoxBinary ffox = new FirefoxBinary();
  if ("true".equals(System.getenv("TRAVIS"))) {
    // xvfb is supposed to run with DISPLAY 99
    ffox.setEnvironmentProperty("DISPLAY", ":99");
  }
  ffox.addCommandLineOptions("--headless");

  FirefoxProfile profile = new FirefoxProfile();
  profile.setPreference("browser.download.folderList", 2);
  profile.setPreference("browser.download.dir",
      FileUtils.getTempDirectory().toString() + "/firefox/");
  profile.setPreference("browser.helperApps.alwaysAsk.force", false);
  profile.setPreference("browser.download.manager.showWhenStarting", false);
  profile.setPreference("browser.download.manager.showAlertOnComplete", false);
  profile.setPreference("browser.download.manager.closeWhenDone", true);
  profile.setPreference("app.update.auto", false);
  profile.setPreference("app.update.enabled", false);
  profile.setPreference("dom.max_script_run_time", 0);
  profile.setPreference("dom.max_chrome_script_run_time", 0);
  profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
      "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
  profile.setPreference("network.proxy.type", 0);

  System.setProperty(
      GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, webDriverPath);
  System.setProperty(
      FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");

  FirefoxOptions firefoxOptions = new FirefoxOptions();
  firefoxOptions.setBinary(ffox);
  firefoxOptions.setProfile(profile);
  firefoxOptions.setLogLevel(FirefoxDriverLogLevel.TRACE);

  return new FirefoxDriver(firefoxOptions);
}
 
Example 16
Source Project: JYTB   Source File: BotWorker.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
     * Sets the webdriver to FireFox. We set our optimal parameters here
     * to ensure our proxy is set correctly.
     */
    private void setFirefoxDriver() {
        FirefoxOptions options = new FirefoxOptions();
        FirefoxProfile profile = new FirefoxProfile();
        FirefoxBinary binary = new FirefoxBinary(this.driverLocation);
        LoggingPreferences logPrefs = new LoggingPreferences();
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
        // hide firefox logs from console
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/tmp/rust_");

        profile.setPreference("media.volume_scale", "0.0");
        profile.setPreference("general.useragent.override", userAgent.randomUA());
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.http_port", this.proxies.getCurrentProxyModel().getPort());
        profile.setPreference("network.proxy.ssl", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.ssl_port", this.proxies.getCurrentProxyModel().getPort());

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.setProfile(profile);
        options.setHeadless(true);
        options.setBinary(binary);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());
        this.webDriver = new FirefoxDriver(options);

        Log.WINFO(this.workerName, this.workerColor, "Firefox Driver Set");
    }
 
Example 17
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("general.useragent.override",
                "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) " +
                        "AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 " +
                        " Mobile/15A356 Safari/604.1");
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);
        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example 18
private void addExtensions(FirefoxProfile profile) {
    JMeterProperty property = getProperty(EXTENSIONS_TO_LOAD);
    if (property instanceof NullProperty) {
        return;
    }
    CollectionProperty rows = (CollectionProperty) property;
    for (int i = 0; i < rows.size(); i++) {
        ArrayList row = (ArrayList) rows.get(i).getObjectValue();
        String filename = ((JMeterProperty) row.get(0)).getStringValue();
        profile.addExtension(new File(filename));
    }
}
 
Example 19
Source Project: teasy   Source File: FireFoxCaps.java    License: MIT License 5 votes vote down vote up
private FirefoxProfile createFirefoxProfile() {
    FirefoxProfile profile = new FirefoxProfile();

    profile.setPreference("dom.max_chrome_script_run_time", 999);
    profile.setPreference("dom.max_script_run_time", 999);

    //Disable plugin container. fix problem with 'FF plugin-container has stopped working'.
    profile.setPreference("dom.ipc.plugins.enabled", false);
    profile.setPreference("dom.ipc.plugins.enabled.npctrl.dll", false);
    profile.setPreference("dom.ipc.plugins.enabled.npqtplugin.dll", false);
    profile.setPreference("dom.ipc.plugins.enabled.npswf32.dll", false);
    profile.setPreference("dom.ipc.plugins.enabled.nptest.dll", false);
    profile.setPreference("dom.ipc.plugins.timeoutSecs", -1);
    //Add this to avoid JAVA plugin certificate warnings
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(true);
    profile.setPreference("plugin.state.java", 2);

    //TODO VE NT check if this is still actual
    //disable  Advocacy/heartbeat in Firefox 37
    //http://selenium2.ru/news/131-rekomenduetsya-otklyuchit-advocacy-heartbeat-v-firefox-37.html
    profile.setPreference("browser.selfsupport.url", "");

    //for sso auth
    profile.setPreference("network.http.phishy-userpass-length", 255);
    profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "http://,https://");

    return profile;
}
 
Example 20
private static DesiredCapabilities getFFUAECaps(DesiredCapabilities caps, Emulator emulator) {
    FirefoxProfile profile = new FirefoxProfile();
    if (!emulator.getUserAgent().trim().isEmpty()) {
        profile.setPreference("general.useragent.override", emulator.getUserAgent());
    }
    caps.setCapability(FirefoxDriver.PROFILE, profile);
    return caps;
}
 
Example 21
Source Project: PatatiumWebUi   Source File: TestBaseCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 用枚举类型列出浏览器列表,用于设置浏览器类型的函数参数
 * @author zheng
 *
 */
private WebDriver setDriver(String browsername)
{
	switch (browsername)
	{

		case "FirefoxDriver" :
			System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
			FirefoxProfile firefoxProfile=new FirefoxProfile();
			//设置默认下载路径
			firefoxProfile.setPreference("browser.download.folderList", 2);
			firefoxProfile.setPreference("browser.download.dir", "D:\\自动化测试下载文件");
			//加载firebug插件
			firefoxProfile.setPreference("extensions.firebug.currentVersion", "2.0.13");
			firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "none");
			//加载firepath插件
			firefoxProfile.setPreference("extensions.firepath.currentVersion", "0.9.7.1.1");
			firefoxProfile.setPreference("extensions.firepath.allPagesActivation", "on");
			this.driver=new FirefoxDriver(firefoxProfile);
			break;
		case "ChormeDriver":
			System.setProperty("webdriver.chrome.driver", "resource\\chromedriver.exe");
			this.driver=new ChromeDriver();
			break;
		case "InternetExplorerDriver":
			System.setProperty("webdriver.ie.driver", "resource\\IEDriverServer_Win32_2.48.0\\IEDriverServer.exe");
			DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
			dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
			dc.setCapability("ignoreProtectedModeSettings", true);
			this.driver=new InternetExplorerDriver(dc);
			break;
		case "HtmlUnitDriver":
			this.driver=new HtmlUnitDriver();
			break;
		default:
			this.driver=new FirefoxDriver();
			break;
	}
	return driver;
}
 
Example 22
public Capabilities getFirefoxCapabilities() {
	DesiredCapabilities firefox = DesiredCapabilities.firefox();
	FirefoxProfile profile = new FirefoxProfile();
	profile.setAcceptUntrustedCertificates(true);
	profile.setAssumeUntrustedCertificateIssuer(true);
	firefox.setCapability(FirefoxDriver.PROFILE, profile);
	firefox.setCapability("marionette", true);
	return firefox;
}
 
Example 23
Source Project: openvidu   Source File: FirefoxUser.java    License: Apache License 2.0 5 votes vote down vote up
public FirefoxUser(String userName, int timeOfWaitInSeconds) {
	super(userName, timeOfWaitInSeconds);

	DesiredCapabilities capabilities = DesiredCapabilities.firefox();
	capabilities.setAcceptInsecureCerts(true);
	capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
	FirefoxProfile profile = new FirefoxProfile();

	// This flag avoids granting the access to the camera
	profile.setPreference("media.navigator.permission.disabled", true);
	// This flag force to use fake user media (synthetic video of multiple color)
	profile.setPreference("media.navigator.streams.fake", true);

	capabilities.setCapability(FirefoxDriver.PROFILE, profile);

	String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX");
	if (REMOTE_URL != null) {
		log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
		try {
			this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	} else {
		log.info("Using local web driver");
		this.driver = new FirefoxDriver(capabilities);
	}

	this.configureDriver();
}
 
Example 24
@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("media.navigator.permission.disabled", true);
    profile.setPreference("media.navigator.streams.fake", true);
    capability.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
            capability);
}
 
Example 25
Source Project: full-teaching   Source File: FirefoxUser.java    License: Apache License 2.0 5 votes vote down vote up
public FirefoxUser(String userName, int timeOfWaitInSeconds) {
	super(userName, timeOfWaitInSeconds);
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("acceptInsecureCerts", true);
	FirefoxProfile profile = new FirefoxProfile();

	// This flag avoids granting the access to the camera
	profile.setPreference("media.navigator.permission.disabled", true);
	// This flag force to use fake user media (synthetic video of multiple color)
	profile.setPreference("media.navigator.streams.fake", true);

	capabilities.setCapability(FirefoxDriver.PROFILE, profile);
	
	String eusApiURL = System.getenv("ET_EUS_API");
	
	if(eusApiURL == null) {
		this.driver = new FirefoxDriver(capabilities);
	} else {
		try {
			capabilities.setBrowserName("firefox");
			
	        this.driver = new RemoteWebDriver(new URL(eusApiURL),  capabilities);
	        				
		} catch (MalformedURLException e) {
			throw new RuntimeException("Exception creaing eusApiURL",e);
		}
	}
	
	this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
	
	this.configureDriver();
}
 
Example 26
Source Project: adf-selenium   Source File: FirefoxDriverResource.java    License: Apache License 2.0 5 votes vote down vote up
protected FirefoxProfile createProfile(String language) {
    FirefoxProfile profile = new FirefoxProfile();
    // native events cause "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsINativeMouse.click]"
    // on Windows with multiple calls to AdfSelectOneChoice.clickItemByIndex (and others)
    profile.setEnableNativeEvents(false);
    profile.setPreference("app.update.enabled", false); // don't bother updating Firefox (takes too much time)
    profile.setPreference("browser.usedOnWindows10", true); // don't show first-time windows 10 welcome page
    profile.setPreference("intl.accept_languages", language);
    return profile;
}
 
Example 27
Source Project: adf-selenium   Source File: BotStyleTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    final FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    profile.setPreference("app.update.enabled", false);
    driver = new FirefoxDriver(profile);

    DialogManager.init(driver, TIMEOUT_MSECS);
    dialogManager = DialogManager.getInstance();
}
 
Example 28
Source Project: jsflight   Source File: SeleniumDriver.java    License: Apache License 2.0 5 votes vote down vote up
private FirefoxDriver createFirefoxDriver(String display, String binaryPath,
        DesiredCapabilities desiredCapabilities)
{
    FirefoxProfile profile = createDefaultFirefoxProfile();
    FirefoxBinary binary = !StringUtils.isBlank(binaryPath) ? new FirefoxBinary(new File(binaryPath))
            : new FirefoxBinary();

    LOG.info("Binding to {} display", display);
    availableDisplays.compute(display, (d, value) -> value == null ? 1 : value + 1);
    binary.setEnvironmentProperty(DISPLAY, display);
    LOG.info("Firefox path is: {}", binaryPath);

    return openFirefoxDriver(desiredCapabilities, profile, binary);
}
 
Example 29
Source Project: jsflight   Source File: SeleniumDriver.java    License: Apache License 2.0 5 votes vote down vote up
private FirefoxDriver openFirefoxDriver(DesiredCapabilities desiredCapabilities, FirefoxProfile profile,
        FirefoxBinary binary)
{
    try
    {
        return new FirefoxDriver(binary, profile, desiredCapabilities);
    }
    catch (WebDriverException ex)
    {
        LOG.warn(ex.getMessage());
        awakenAllDrivers();
        return openFirefoxDriver(desiredCapabilities, profile, binary);
    }
}
 
Example 30
protected void configProfile(final FirefoxProfile profile, final DriverConfig webDriverConfig) {
    profile.setAcceptUntrustedCertificates(webDriverConfig.isSetAcceptUntrustedCertificates());
    profile.setAssumeUntrustedCertificateIssuer(webDriverConfig.isSetAssumeUntrustedCertificateIssuer());

    if (webDriverConfig.getFirefoxBinPath() != null) {
        System.setProperty("webdriver.firefox.bin", webDriverConfig.getFirefoxBinPath());
    }

    if (webDriverConfig.getUserAgentOverride() != null) {
        profile.setPreference("general.useragent.override", webDriverConfig.getUserAgentOverride());
    }

    if (webDriverConfig.getNtlmAuthTrustedUris() != null) {
        profile.setPreference("network.automatic-ntlm-auth.trusted-uris", webDriverConfig.getNtlmAuthTrustedUris());
    }

    if (webDriverConfig.getBrowserDownloadDir() != null) {
        profile.setPreference("browser.download.dir", webDriverConfig.getBrowserDownloadDir());
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
            "application/octet-stream,text/plain,application/pdf,application/zip,text/csv,text/html");
    }

    if (!webDriverConfig.isEnableJavascript()) {
        profile.setPreference("javascript.enabled", false);
    }

    // fix permission denied issues
    profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess");
    profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess");
    profile.setPreference("capability.policy.default.HTMLDocument.compatMode.get", "allAccess");
    profile.setPreference("capability.policy.default.Document.compatMode.get", "allAccess");
    profile.setPreference("dom.max_chrome_script_run_time", 0);
    profile.setPreference("dom.max_script_run_time", 0);
}