if (Validate.nonEmpty(binary)) {
Validate.isExecutable(binary, "Firefox binary does not point to a valid executable, " + binary);
}
// set firefox profile from path if specified
FirefoxProfile firefoxProfile;
if (Validate.nonEmpty(profile)) {
Validate.isValidPath(profile, "Firefox profile does not point to a valid path " + profile);
firefoxProfile = new FirefoxProfile(new File(profile));
}
else {
firefoxProfile = new FirefoxProfile();
}
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
final String firefoxExtensions = (String) capabilities.getCapability("firefoxExtensions");
// no check is needed here, it will return empty array if null
for (String extensionPath : StringUtils.tokenize(firefoxExtensions)) {
try {
firefoxProfile.addExtension(new File(extensionPath));
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read XPI extension file: " + extensionPath, e);
}
}
// add user preferences from file
final String userPreferences = (String) capabilities.getCapability("firefoxUserPreferences");
if (Validate.nonEmpty(userPreferences)) {
Validate.isValidPath(userPreferences, "User preferences does not point to a valid path " + userPreferences);
// we need to manually parse preferences, as Selenium provides no way to set these value
for (Map.Entry<String, Object> preference : FirefoxPrefsReader.getPreferences(new File(userPreferences)).entrySet()) {
String key = preference.getKey();
Object value = preference.getValue();
if (value instanceof Boolean) {
firefoxProfile.setPreference(key, (Boolean) value);
}
else if (value instanceof Integer) {
firefoxProfile.setPreference(key, (Integer) value);
}
else if (value instanceof String) {
firefoxProfile.setPreference(key, (String) value);
}
}
}
return SecurityActions.newInstance(configuration.getImplementationClass(), new Class<?>[] { Capabilities.class },