How to use updateUserPrefs method of org.openqa.selenium.firefox.FirefoxProfile class

Best Selenium code snippet using org.openqa.selenium.firefox.FirefoxProfile.updateUserPrefs

Source:FirefoxProfile.java Github

copy

Full Screen

...189 protected Preferences getAdditionalPreferences() {190 return additionalPrefs;191 }192 193 public void updateUserPrefs(File userPrefs) {194 Preferences prefs = new Preferences(onlyOverrideThisIfYouKnowWhatYouAreDoing());195 196 prefs.setPreference("browser.startup.homepage", "about:blank");197 198 prefs.setPreference("browser.startup.page", 0);199 200 if (userPrefs.exists()) {201 prefs = new Preferences(onlyOverrideThisIfYouKnowWhatYouAreDoing(), userPrefs);202 if (!userPrefs.delete()) {203 throw new WebDriverException("Cannot delete existing user preferences");204 }205 }206 207 additionalPrefs.addTo(prefs);208 209 prefs.setPreference("webdriver_accept_untrusted_certs", acceptUntrustedCerts);210 211 prefs.setPreference("webdriver_assume_untrusted_issuer", untrustedCertIssuer);212 213 Object homePage = prefs.getPreference("browser.startup.homepage");214 if ((homePage != null) && ((homePage instanceof String))) {215 prefs.setPreference("startup.homepage_welcome_url", "");216 }217 218 if (!"about:blank".equals(prefs.getPreference("browser.startup.homepage"))) {219 prefs.setPreference("browser.startup.page", 1);220 }221 try {222 FileWriter writer = new FileWriter(userPrefs);Throwable localThrowable3 = null;223 try { prefs.writeTo(writer);224 }225 catch (Throwable localThrowable1)226 {227 localThrowable3 = localThrowable1;throw localThrowable1;228 } finally {229 if (writer != null) if (localThrowable3 != null) try { writer.close(); } catch (Throwable localThrowable2) { localThrowable3.addSuppressed(localThrowable2); } else writer.close();230 } } catch (IOException e) { throw new WebDriverException(e);231 }232 }233 234 protected void deleteLockFiles(File profileDir) {235 File macAndLinuxLockFile = new File(profileDir, ".parentlock");236 File windowsLockFile = new File(profileDir, "parent.lock");237 238 macAndLinuxLockFile.delete();239 windowsLockFile.delete();240 }241 242 public void deleteExtensionsCacheIfItExists(File profileDir) {243 File cacheFile = new File(profileDir, "extensions.cache");244 if (cacheFile.exists()) {245 cacheFile.delete();246 }247 }248 249 @Deprecated250 public boolean areNativeEventsEnabled()251 {252 return false;253 }254 255 @Deprecated256 public void setEnableNativeEvents(boolean enableNativeEvents) {}257 258 public boolean shouldLoadNoFocusLib()259 {260 return loadNoFocusLib;261 }262 263 public void setAlwaysLoadNoFocusLib(boolean loadNoFocusLib)264 {265 this.loadNoFocusLib = loadNoFocusLib;266 }267 268 public void setAcceptUntrustedCertificates(boolean acceptUntrustedSsl)269 {270 acceptUntrustedCerts = acceptUntrustedSsl;271 }272 273 public void setAssumeUntrustedCertificateIssuer(boolean untrustedIssuer)274 {275 untrustedCertIssuer = untrustedIssuer;276 }277 278 public void clean(File profileDir) {279 TemporaryFilesystem.getDefaultTmpFS().deleteTempDir(profileDir);280 }281 282 public String toJson() throws IOException {283 return Zip.zip(layoutOnDisk());284 }285 286 public static FirefoxProfile fromJson(String json) throws IOException {287 return new FirefoxProfile(Zip.unzipToTempDir(json, "webdriver", "duplicated"));288 }289 290 protected void cleanTemporaryModel() {291 clean(model);292 }293 294 public File layoutOnDisk()295 {296 try297 {298 File profileDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("anonymous", "webdriver-profile");299 File userPrefs = new File(profileDir, "user.js");300 301 copyModel(model, profileDir);302 installExtensions(profileDir);303 deleteLockFiles(profileDir);304 deleteExtensionsCacheIfItExists(profileDir);305 updateUserPrefs(userPrefs);306 return profileDir;307 } catch (IOException e) {308 throw new UnableToCreateProfileException(e);309 }310 }311 312 protected void copyModel(File sourceDir, File profileDir) throws IOException {313 if ((sourceDir == null) || (!sourceDir.exists())) {314 return;315 }316 317 FileHandler.copy(sourceDir, profileDir);318 }319 ...

Full Screen

Full Screen

Source:MyFirefoxProfile.java Github

copy

Full Screen

...116 public String toString() {117 return firefoxProfile.toString();118 }119 @Override120 public void updateUserPrefs(File userPrefs) {121 super.updateUserPrefs(userPrefs);122 firefoxProfile.updateUserPrefs(userPrefs);123 }124 @Override125 public void setAssumeUntrustedCertificateIssuer(boolean untrustedIssuer) {126 super.setAssumeUntrustedCertificateIssuer(untrustedIssuer);127 firefoxProfile.setAssumeUntrustedCertificateIssuer(untrustedIssuer);128 }129 @Override130 public void setAlwaysLoadNoFocusLib(boolean loadNoFocusLib) {131 super.setAlwaysLoadNoFocusLib(loadNoFocusLib);132 firefoxProfile.setAlwaysLoadNoFocusLib(loadNoFocusLib);133 }134 @Override135 public void setAcceptUntrustedCertificates(boolean acceptUntrustedSsl) {136 super.setAcceptUntrustedCertificates(acceptUntrustedSsl);...

Full Screen

Full Screen

Source:ProfileManager.java Github

copy

Full Screen

...114 // Install extension if necessary.115 profile.addWebDriverExtensionIfNeeded(false);116 // Set port and update user prefs.117 profile.setPort(port);118 profile.updateUserPrefs();119 // Clean up the profile.120 try {121 binary.clean(profile);122 } catch (IOException e) {123 throw new WebDriverException("Unable to clean profile", e);124 }125 }126}...

Full Screen

Full Screen

Source:FirefoxLauncher.java Github

copy

Full Screen

...42 System.out.println("Attempting to install the WebDriver extension");43 profile.addWebDriverExtensionIfNeeded(true);44 System.out.println("Updating user preferences with common, useful settings");45 profile.setPort(port);46 profile.updateUserPrefs();47 System.out.println("Deleting existing extensions cache (if it already exists)");48 profile.deleteExtensionsCacheIfItExists();49 System.out.println("Firefox should now start and quit");50 binary.startProfile(profile);51 52 repeatedlyConnectUntilFirefoxAppearsStable(port);53 }54 private void repeatedlyConnectUntilFirefoxAppearsStable(int port) {55 ExtensionConnection connection;56 // maximum wait time is a minute57 long maxWaitTime = System.currentTimeMillis() + 60000;58 59 while (System.currentTimeMillis() < maxWaitTime) {60 try {...

Full Screen

Full Screen

Source:NewProfileExtensionConnection.java Github

copy

Full Screen

...37 try {38 int portToUse = determineNextFreePort(host, profile.getPort());39 this.process.setOutputWatcher(new CircularOutputStream(bufferSize));40 profile.setPort(portToUse);41 profile.updateUserPrefs();42 this.process.clean(profile);43 this.process.startProfile(profile);44 setAddress(host, portToUse);45 connectToBrowser(this.process.getTimeout());46 } finally {47 lock.unlock();48 }49 }50 @Override51 protected void connectToBrowser(long timeToWaitInMilliSeconds) throws IOException {52 try {53 super.connectToBrowser(timeToWaitInMilliSeconds);54 } catch (IOException e) {55 throw new WebDriverException(...

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.FirefoxProfile;3public class FirefoxProfileDemo {4 public static void main(String[] args) {5 FirefoxProfile profile = new FirefoxProfile();6 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");7 profile.setPreference("browser.download.folderList", 2);8 profile.setPreference("browser.download.dir", "C:\\selenium");9 profile.setPreference("network.proxy.type", 1);10 profile.setPreference("network.proxy.http", "

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1FirefoxProfile profile = new FirefoxProfile();2profile.setPreference("startup.homepage_welcome_url", "about:blank");3profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");4profile.setPreference("browser.startup.homepage_override.mstone", "ignore");5profile.setPreference("browser.startup.page", 1);6profile.setPreference("browser.startup.homepage_override.mstone", "ignore");7profile.setPreference("startup.homepage_welcome_url", "about:blank");8profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");9profile.setPreference("browser.startup.homepage_override.mstone", "ignore");10profile.setPreference("browser.startup.page", 1);11FirefoxDriver driver = new FirefoxDriver(profile);12FirefoxDriver driver = new FirefoxDriver();13FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));14FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));15FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));16FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));17FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));18FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));19FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));20FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new FirefoxOptions().setLegacy(true));21FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(), profile, new

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxProfile;2import org.openqa.selenium.firefox.FirefoxDriver;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import java.util.HashMap;7import java.util.Map;8public class FirefoxProfileExample {9 public static void main(String[] args) {10 Map<String, Object> prefs = new HashMap<String, Object>();11 prefs.put("profile.default_content_setting_values.notifications", 2);12 FirefoxProfile profile = new FirefoxProfile();13 profile.setPreference("dom.webnotifications.enabled", false);14 profile.setPreference("dom.push.enabled", false);15 profile.setPreference("dom.push.connection.enabled", false);16 profile.setPreference("dom.push.serverURL", "");17 profile.setPreference("dom.push.userAgentID", "");18 profile.setPreference("dom.push.connection.wakeupDelay", -1);19 profile.setPreference("dom.push.debug", false);20 profile.setPreference("dom.push.enabled", false);21 profile.setPreference("dom.push.serverURL", "");22 profile.setPreference("dom.push.userAgentID", "");23 profile.setPreference("dom.push.connection.wakeupDelay", -1);24 profile.setPreference("dom.push.debug", false);25 profile.setPreference("dom.push.enabled", false);26 profile.setPreference("dom.push.serverURL", "");27 profile.setPreference("dom.push.userAgentID", "");

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.firefox.FirefoxDriver;3import org.openqa.selenium.firefox.FirefoxProfile;4import org.openqa.selenium.firefox.internal.ProfilesIni;5import org.openqa.selenium.remote.DesiredCapabilities;6public class FirefoxProfileExample {7public static void main(String[] args) {8WebDriver driver = new FirefoxDriver();9FirefoxProfile profile = new FirefoxProfile();10profile.setPreference("browser.download.dir","C:\\Users\\Selenium\\Downloads");11profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");12profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");13profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");14driver = new FirefoxDriver(profile);15}16}

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1FirefoxProfile profile = new FirefoxProfile();2profile.setPreference("startup.homepage_welcome_url", "about:blank");3profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");4profile.setPreference("browser.startup.page", 1);5profile.setPreference("browser.tabs.warnOnClose", false);6profile.setPreference("browser.tabs.warnOnOpen", false);7profile.setPreference("browser.download.folderList", 2);8profile.setPreference("browser.download.dir", "C:\\Downloads");9profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");10profile.setPreference("pdfjs.disabled", true);11profile.setPreference("plugin.scan.plid.all", false);12profile.setPreference("plugin.scan.Acrobat", "99.0");13profile.setPreference("plugin.scan.Quicktime", "99.0");14profile.setPreference("plugin.scan.WindowsMediaPlayer", "99.0");15profile.setPreference("plugin.scan.SunJRE", "

Full Screen

Full Screen

updateUserPrefs

Using AI Code Generation

copy

Full Screen

1public class FirefoxProfileExample {2 public static void main(String[] args) {3 FirefoxProfile profile = new FirefoxProfile();4 profile.setPreference("permissions.default.image", 2);5 WebDriver driver = new FirefoxDriver(profile);6 driver.quit();7 }8}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful