Use of FireFox Profile
Available constructors
Here we will see how Firefox driver can make use of a already created profile in firefox.
To check out which profile Firefox is using currently enter about:support in Firefox address bar and check for "Profile Folder".
Firefox Profile :
Firefox profile has a default constructor and other constructor taken an argument of type file.
To check out which profile Firefox is using currently enter about:support in Firefox address bar and check for "Profile Folder".
To create / modify/ delete a new Firefox profile
To create, rename, or delete a profile, you have to perform the following steps:
1. Open the Firefox profile manager. To do that, in the command prompt
terminal, you have to navigate to the install directory of Firefox; typically, it
would in Program Files if you are on Windows. Navigate to the location where
you can find the firefox.exe file, and execute the following command:
firefox.exe -p
It will open the profile manager that will look like the following screenshot:
Note that before executing the above command, you need to make sure you
close all your currently running Firefox instances.
2. Use the Create Profile... button to create another profile, Rename Profile...
button to rename an existing profile, and Delete Profile... button to delete one.
Firefox Profile :
Firefox profile has a default constructor and other constructor taken an argument of type file.
Use of constructor FirefoxDriver(FirefoxProfile profile)
// using a already created profile
public static void fireFoxProfileA(WebDriver driver) { FirefoxProfile profile = new FirefoxProfile( new File("C:\\Users\\sudas\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\t1skcchd.sudas1")); driver = new FirefoxDriver(profile); driver.get("http://www.yahoo.com"); }
// Creating an instance of firefox profile for a specific plugin and store as JSON
public static void fireFoxProfileB(WebDriver driver) { FirefoxProfile profile = new FirefoxProfile(); try {
// adding a extension to the new Firefox session
profile.addExtension(new File("C:\\Java_Source_Code\\FireFoxExtensions\\firebug-2.0.13-fx.xpi"));
String json = profile.toJson();
// write the profile to a file
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(new File("C:\\Java_Source_Code\\FireFoxExtensions\\profile.json")));
bos.write(json.getBytes());
driver = new FirefoxDriver(profile);
driver.get("http://www.yahoo.com");
bos.flush();
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Use of preference with Firefox
FirefoxDriver overwrites all the default preferences of Firefox in the user.js file
for you
List of preference
user_pref("extensions.update.notifyUser", false);
user_pref("security.warn_entering_secure.show_once", false);
user_pref("devtools.errorconsole.enabled", true);
user_pref("extensions.update.enabled", false);
user_pref("browser.dom.window.dump.enabled", true);
user_pref("offline-apps.allow_by_default", true);
user_pref("dom.disable_open_during_load", false);
user_pref("extensions.blocklist.enabled", false);
user_pref("browser.startup.page", 0);
user_pref("toolkit.telemetry.rejected", true);
user_pref("prompts.tab_modal.enabled", false);
user_pref("app.update.enabled", false);
user_pref("app.update.auto", false);
user_pref("toolkit.networkmanager.disable", true);
user_pref("browser.startup.homepage", "about:blank");
user_pref("network.manage-offline-status", false);
user_pref("browser.search.update", false);
user_pref("toolkit.telemetry.enabled", false);
user_pref("browser.link.open_newwindow", 2);
user_pref("browser.EULA.override", true);
user_pref("extensions.autoDisableScopes", 10);
user_pref("browser.EULA.3.accepted", true);
user_pref("security.warn_entering_weak", false);
user_pref("toolkit.telemetry.prompted", 2);
user_pref("browser.safebrowsing.enabled", false);
user_pref("security.warn_entering_secure", false);
user_pref("security.warn_leaving_secure.show_once", false);
user_pref("webdriver_accept_untrusted_certs", true);
user_pref("browser.download.manager.showWhenStarting", false);
user_pref("dom.max_script_run_time", 30);
user_pref("javascript.options.showInConsole", true);
user_pref("network.http.max-connections-per-server", 10);
user_pref("network.http.phishy-userpass-length", 255);
user_pref("extensions.logging.enabled", true);
user_pref("security.warn_leaving_secure", false);
user_pref("browser.offline", false);
user_pref("browser.link.open_external", 2);
user_pref("signon.rememberSignons", false);
user_pref("webdriver_enable_native_events", true);
user_pref("browser.tabs.warnOnClose", false);
user_pref("security.fileuri.origin_policy", 3);
user_pref("security.fileuri.strict_origin_policy", false);
user_pref("webdriver_assume_untrusted_issuer", true);
user_pref("startup.homepage_welcome_url", "");
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("security.warn_submit_insecure", false);
user_pref("webdriver_firefox_port", 7055);
user_pref("dom.report_all_js_exceptions", true);
user_pref("security.warn_viewing_mixed", false);
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.tabs.warnOnOpen", false);
user_pref("security.warn_viewing_mixed.show_once", false);
user_pref("security.warn_entering_weak.show_once", false);
To set the preference use the Key, Value pair
Use FireFox profile with preference
Firefox profile methods
Here I am using an already existing profile and setting a preference on the profile
// using firefox profile along with preference
public static void fireFoxProfileA(WebDriver driver) {
FirefoxProfile profile = new FirefoxProfile(
new File("C:\\Users\\sudas\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\t1skcchd.sudas1"));
//setting preference
profile.setPreference("browser.startup.homepage", "https://www.yahoo.co.in/");
driver = new FirefoxDriver(profile);
// driver.get("http://www.yahoo.com");
}
No comments:
Post a Comment