Reputation: 719
There is a way to pass local profile to Remote Driver:
FirefoxProfile p = new FirefoxProfile();
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setCapability(FirefoxDriver.PROFILE, p);
URL remote = null;
try {
remote = new URL("http://x.x.x.x:4444/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
RemoteWebDriver driver = new RemoteWebDriver(remote, capability);
After session is complete I see the folder like "anonymous2926416537184265625webdriver-profile" on x.x.x.x containing updated profile with new cookies, history, LocalStorage, etc.
There is a method p.toJson(), but it returns local profile. The question is how to get contents of the "anonymous2926416537184265625webdriver-profile" on x.x.x.x?
Upvotes: 0
Views: 322
Reputation: 3927
The anonymous folder which is created in Temp generally will not be useful once execution is completed/JVM exists. As per documentation provided here
"public java.io.File layoutOnDisk()
Call this to cause the current profile to be written to disk. The profile directory is returned. Note that this profile directory is a temporary one and will be deleted when the JVM exists (at the latest) This method should be called immediately before starting to use the profile and should only be called once per instance of the FirefoxDriver.
Returns: The directory containing the profile. "
If you observe the temp folder on execution, couple of anonymous folder go on created and deleted, finally only one folder will be there. We may get this folder name something like below but on exist it will have different name.
System.out.println(profile.layoutOnDisk());
all the profile preferences are updated in prefs.js which is available in that anonymous folder. it will contain provided setPreference, add extensions in script along with other default firefox profile preferences. As we already provided required preferences in script, i hope no need to fetch data from this file.
Starting firefox profile from directory also not recommended. As per document
"FirefoxProfile
public FirefoxProfile(java.io.File profileDir)
Constructs a firefox profile from an existing profile directory.
Users who need this functionality should consider using a named profile.
Parameters: profileDir - The profile directory to use as a model."
not only from this anonymous folder, for me it does not worked as expected from saved profile directory (generally in AppData\Local\Mozilla). I all ways use profile by name, off-course, i hope, mostly all will use by name only, instead of saved directory.
As known driver.manage().getCookies(); will provide Set of cookies, if required we can get those.
Thank You, Murali
Upvotes: 2