It allows us to add some firefox addons like FireBug, and also using “setPreference()” method we can customize Firefox settings for out tests.
Let's look into a simple firefox profile for selenium tests example:
[code lang="java"]FirefoxDriver firefoxDriver = new FirefoxDriver(getFireFoxProfile());
firefoxDriver.navigate().to("http://www.skillim.com");[/code]
In method
getFireFoxProfile() we will set up some specific Firefox settings:[code lang="java"]
private FirefoxProfile getFireFoxProfile(){
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", 4);
firefoxProfile.setPreference("browser.startup.homepage", "about:blank");
firefoxProfile.setPreference("privacy.popups.showBrowserMessage", false);
firefoxProfile.setPreference("network.cookie.prefsMigrated", true);
firefoxProfile.setPreference("network.cookie.lifetimePolicy", 3);
firefoxProfile.setPreference("network.cookie.lifetime.days", 30);
firefoxProfile.setPreference("app.update.enabled", false);
firefoxProfile.setPreference("app.update.auto", false);
return firefoxProfile;
}[/code]
Let's briefly describe all these properties.
[code lang="java" title="<strong>Configure desirable proxy settings</strong>" firstline="3"]
firefoxProfile.setPreference("network.proxy.type", 4);
[/code]
[code lang="java" title="<strong>Setting coockies life time</strong>" firstline="7"]
firefoxProfile.setPreference("network.cookie.lifetimePolicy", 3);
[/code]
[code lang="java" title="<strong>Setting cookies lifetime limit(default value=90 days)</strong>" firstline="8"]
firefoxProfile.setPreference("network.cookie.lifetime.days", 30);
[/code]
firefoxProfile.setPreference("network.proxy.type", 4);
[/code]
0 - Direct connection, no proxy
1 - Manual proxy configuration.
2 - Proxy auto-configuration (PAC).
3 - The same like 0
4 - Auto-detect proxy settings
5- Use system proxy settings
[code lang="java" title="<strong>Setting start page value - 'about:blank'</strong>" firstline="4"]
firefoxProfile.setPreference("browser.startup.homepage", "about:blank");
[/code]
firefoxProfile.setPreference("browser.startup.homepage", "about:blank");
[/code]
[code lang="java" title="<strong>Switching off popups dialogs</strong>" firstline="5"]
firefoxProfile.setPreference("privacy.popups.showBrowserMessage", false);
[/code]
firefoxProfile.setPreference("privacy.popups.showBrowserMessage", false);
[/code]
[code lang="java" title="<strong>Cookies migration preferences for other profiles</strong>" firstline="6"]
firefoxProfile.setPreference("network.cookie.prefsMigrated", true);
[/code]
firefoxProfile.setPreference("network.cookie.prefsMigrated", true);
[/code]
[code lang="java" title="<strong>Setting coockies life time</strong>" firstline="7"]
firefoxProfile.setPreference("network.cookie.lifetimePolicy", 3);
[/code]
0 - Accept cookies normally
1 - Prompt for each cookie
2 - Accept for current session only
3 - Accept for N days
[code lang="java" title="<strong>Setting cookies lifetime limit(default value=90 days)</strong>" firstline="8"]
firefoxProfile.setPreference("network.cookie.lifetime.days", 30);
[/code]
This option could be used only if network.cookie.lifetimePolicy is set to 3
More information about cookies properties you can find here
[code lang="java" title="S<strong>witching off firefox automatic updates</strong>" firstline="9"]
firefoxProfile.setPreference("app.update.enabled", "false");
firefoxProfile.setPreference("app.update.auto", "false");
[/code]
firefoxProfile.setPreference("app.update.enabled", "false");
firefoxProfile.setPreference("app.update.auto", "false");
[/code]
All avaliable firefox properties you can find in firefox browser
1. Start Browser
2. Open "about:config" page
3. Page with all available parametrs will be opened
No comments:
Post a Comment