类org.openqa.selenium.firefox.FirefoxProfile源码实例Demo

下面列出了怎么用org.openqa.selenium.firefox.FirefoxProfile的API类实例代码及写法,或者点击链接到github查看源代码。

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();
        }

    }
 
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");
    }
 
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;
}
 
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;
        }
    }
}
 
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");
}
 
源代码6 项目: jsflight   文件: SeleniumDriver.java
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;
}
 
源代码7 项目: Asqatasun   文件: ScenarioLoaderImpl.java
/**
     * 
     * @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;
    }
 
源代码8 项目: Asqatasun   文件: ProfileFactory.java
/**
     * 
     * @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;
    }
 
/**
 * 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;
}
 
源代码10 项目: rice   文件: JiraIssueCreation.java
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();
}
 
源代码11 项目: selenium   文件: XpiDriverService.java
@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);
  }
}
 
源代码12 项目: selenium   文件: XpiDriverServiceTest.java
@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());
}
 
源代码13 项目: candybean   文件: FirefoxInterface.java
@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
	}
}
 
@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);
}
 
源代码15 项目: submarine   文件: FirefoxWebDriverProvider.java
@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);
}
 
源代码16 项目: JYTB   文件: BotWorker.java
/**
     * 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");
    }
 
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");
    }
 
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));
    }
}
 
源代码19 项目: teasy   文件: FireFoxCaps.java
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;
}
 
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;
}
 
源代码21 项目: PatatiumWebUi   文件: TestBaseCase.java
/**
 * 用枚举类型列出浏览器列表,用于设置浏览器类型的函数参数
 * @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;
}
 
源代码22 项目: SeleniumCucumber   文件: FirefoxBrowser.java
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;
}
 
源代码23 项目: openvidu   文件: FirefoxUser.java
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();
}
 
@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);
}
 
源代码25 项目: full-teaching   文件: FirefoxUser.java
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();
}
 
源代码26 项目: adf-selenium   文件: FirefoxDriverResource.java
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;
}
 
源代码27 项目: adf-selenium   文件: BotStyleTest.java
@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();
}
 
源代码28 项目: jsflight   文件: SeleniumDriver.java
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);
}
 
源代码29 项目: jsflight   文件: SeleniumDriver.java
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);
    }
}
 
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);
}
 
 类所在包
 同包方法