Skip to content

Instantly share code, notes, and snippets.

@stackedsax
Created March 31, 2012 09:56
Show Gist options
  • Save stackedsax/2261402 to your computer and use it in GitHub Desktop.
Save stackedsax/2261402 to your computer and use it in GitHub Desktop.
Provides a way to load a locally-stored Firefox profile and maintains the ability to send a profile as a json string
Index: java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java
===================================================================
--- java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java (revision 16421)
+++ java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java (working copy)
@@ -101,10 +101,13 @@
if (raw instanceof FirefoxProfile) {
profile = (FirefoxProfile) raw;
} else if (raw instanceof String) {
- try {
- profile = FirefoxProfile.fromJson((String) raw);
- } catch (IOException e) {
- throw new WebDriverException(e);
+ profile = new ProfilesIni().getProfile((String) raw);
+ if (profile == null){
+ try {
+ profile = FirefoxProfile.fromJson((String) raw);
+ } catch (IOException e) {
+ throw new WebDriverException(e);
+ }
}
}
}
@lukeis
Copy link

lukeis commented Mar 31, 2012

what's wrong with doing this? (i'm not sure i see what problem you're trying to solve)

FirefoxProfile fp = new ProfilesIni().getProfile("profileName");
WebDriver driver = new Firefox(fp);

@stackedsax
Copy link
Author

I want to use a profile that lives on the remote machine. The code you pasted would pass "profileName" from the machine that's executing the test. Since we start up browsers many many times during our suites, I want to reduce the amount of information that gets sent over the wire.

We already provide this sort of behaviour, but the ability is limited to a single profile: we can set the -Dwebdriver.firefox.profile in the command line startup of the node. This suggests that priming a remote test machine with a special profile is a perfectly legitimate way of organizing test profiles. My change merely expands this ability to allow us to select any profiles that exist on the remote test machine.

It amounts to a 2-line change. ProfilesIni returns null if the string does not match any profile name saved in the Map created by ProfilesIni of the profiles.ini file. It seems like a fairly safe thing to do and would allow people to do what they're trying to do. In my searching for a solution on this, I noticed a number of comments which indicated people were trying to do this exact same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment