How to use locateAppDataDirectory method of org.openqa.selenium.firefox.ProfilesIni class

Best Selenium code snippet using org.openqa.selenium.firefox.ProfilesIni.locateAppDataDirectory

Source:ProfilesIni.java Github

copy

Full Screen

...15{16 private Map<String, File> profiles = Maps.newHashMap();17 18 public ProfilesIni() {19 File appData = locateAppDataDirectory(Platform.getCurrent());20 profiles = readProfiles(appData);21 }22 23 protected Map<String, File> readProfiles(File appData) {24 toReturn = Maps.newHashMap();25 26 File profilesIni = new File(appData, "profiles.ini");27 if (!profilesIni.exists())28 {29 return toReturn;30 }31 32 boolean isRelative = true;33 String name = null;34 String path = null;35 36 BufferedReader reader = null;37 try {38 reader = new BufferedReader(new FileReader(profilesIni));39 40 String line = reader.readLine();41 42 while (line != null) {43 if (line.startsWith("[Profile")) {44 File profile = newProfile(name, appData, path, isRelative);45 if (profile != null) {46 toReturn.put(name, profile);47 }48 name = null;49 path = null;50 } else if (line.startsWith("Name=")) {51 name = line.substring("Name=".length());52 } else if (line.startsWith("IsRelative=")) {53 isRelative = line.endsWith("1");54 } else if (line.startsWith("Path=")) {55 path = line.substring("Path=".length());56 }57 58 line = reader.readLine();59 }60 61 File profile;62 63 File profile;64 65 return toReturn;66 }67 catch (IOException e)68 {69 throw new WebDriverException(e);70 } finally {71 try {72 if (reader != null) {73 profile = newProfile(name, appData, path, isRelative);74 if (profile != null) {75 toReturn.put(name, profile);76 }77 reader.close();78 }79 }80 catch (IOException localIOException2) {}81 }82 }83 84 protected File newProfile(String name, File appData, String path, boolean isRelative)85 {86 if ((name != null) && (path != null)) {87 File profileDir = isRelative ? new File(appData, path) : new File(path);88 return profileDir;89 }90 return null;91 }92 93 public FirefoxProfile getProfile(String profileName) {94 File profileDir = (File)profiles.get(profileName);95 if (profileDir == null) {96 return null;97 }98 99 File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("userprofile", "copy");100 try {101 FileHandler.copy(profileDir, tempDir);102 103 File compreg = new File(tempDir, "compreg.dat");104 if ((compreg.exists()) && 105 (!compreg.delete())) {106 throw new WebDriverException("Cannot delete file from copy of profile " + profileName);107 }108 }109 catch (IOException e) {110 throw new WebDriverException(e);111 }112 113 return new FirefoxProfile(tempDir);114 }115 116 protected File locateAppDataDirectory(Platform os) { File appData;117 File appData;118 if (os.is(Platform.WINDOWS)) {119 appData = new File(MessageFormat.format("{0}\\Mozilla\\Firefox", new Object[] { System.getenv("APPDATA") }));120 } else { File appData;121 if (os.is(Platform.MAC))122 {123 appData = new File(MessageFormat.format("{0}/Library/Application Support/Firefox", new Object[] {124 System.getenv("HOME") }));125 }126 else {127 appData = new File(MessageFormat.format("{0}/.mozilla/firefox", new Object[] { System.getenv("HOME") }));128 }129 }130 if (!appData.exists())...

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.ProfilesIni;3public class LocateAppDataDirectory {4 public static void main(String[] args) {5 ProfilesIni profile = new ProfilesIni();6 System.out.println(profile.getProfile("default").getPreference("app.update.auto", false));7 System.out.println(profile.getProfile("default").getPreference("app.update.enabled", false));8 System.out.println(profile.getProfile("default").getPreference("app.update.url", false));9 System.out.println(profile.getProfile("default").getPreference("app.update.url.manual", false));10 System.out.println(profile.getProfile("default").getPreference("app.update.url.details", false));11 System.out.println(profile.getProfile("default").getPreference("app.update.url.override", false));12 System.out.println(profile.getProfile("default").getPreference("app.update.url.android", false));13 System.out.println(profile.getProfile("default").getPreference("app.update.staging.enabled", false));14 System.out.println(profile.getProfile("default").getPreference("app.update.badge", false));15 System.out.println(profile.getProfile("default").getPreference("app.update.channel", false));16 System.out.println(profile.getProfile("default").getPreference("app.update.log", false));17 System.out.println(profile.getProfile("default").getPreference("app.update.promptWaitTime", false));18 System.out.println(profile.getProfile("default").getPreference("app.update.restart", false));19 System.out.println(profile.getProfile("default").getPreference("app.update.service.enabled", false));20 System.out.println(profile.getProfile("default").getPreference("app.update.silent", false));21 System.out.println(profile.getProfile("default").getPreference("app.update.url.android", false));22 System.out.println(profile.getProfile("default").getPreference("app.update.url.details", false));23 System.out.println(profile.getProfile("default").getPreference("app.update.url.manual", false));24 System.out.println(profile.getProfile("default").getPreference("app.update.url.override", false));25 System.out.println(profile.getProfile("default").getPreference("app.update.url", false));26 System.out.println(profile.getProfile("default").getPreference("app.update.enabled", false));27 System.out.println(profile.getProfile("default").getPreference("app.update.auto", false));28 System.out.println(profile.getProfile("default").getPreference("app.update.url.android", false

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxProfile;2import org.openqa.selenium.firefox.ProfilesIni;3public class FirefoxProfileDemo {4 public static void main(String[] args) {5 ProfilesIni profile = new ProfilesIni();6 FirefoxProfile myprofile = profile.getProfile("default");7 System.out.println(myprofile.getPreference("browser.startup.homepage"));8 }9}10import org.openqa.selenium.firefox.FirefoxProfile;11import org.openqa.selenium.firefox.ProfilesIni;12public class FirefoxProfileDemo {13 public static void main(String[] args) {14 ProfilesIni profile = new ProfilesIni();15 FirefoxProfile myprofile = profile.getProfile("default");16 System.out.println(myprofile.getPreference("browser.startup.homepage"));17 }18}19import org.openqa.selenium.firefox.FirefoxProfile;20import org.openqa.selenium.firefox.ProfilesIni;21public class FirefoxProfileDemo {22 public static void main(String[] args) {23 ProfilesIni profile = new ProfilesIni();24 FirefoxProfile myprofile = profile.getProfile("default");25 System.out.println(myprofile.getPreference("browser.startup.homepage"));26 }27}28import org.openqa.selenium.firefox.FirefoxProfile;29import org.openqa.selenium.firefox.ProfilesIni;30public class FirefoxProfileDemo {31 public static void main(String[] args) {32 ProfilesIni profile = new ProfilesIni();33 FirefoxProfile myprofile = profile.getProfile("default");34 System.out.println(myprofile.getPreference("browser.startup.homepage"));35 }36}

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1ProfilesIni profile = new ProfilesIni();2FirefoxProfile myprofile = profile.getProfile("default");3System.setProperty("webdriver.firefox.profile", "default");4WebDriver driver = new FirefoxDriver();5FirefoxProfile myprofile = new FirefoxProfile();6myprofile.setPreference("browser.download.folderList", 2);7myprofile.setPreference("browser.download.dir", "C:\\Users\\Downloads");8myprofile.setPreference("browser.download.useDownloadDir", true);9myprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel");10myprofile.setPreference("browser.download.manager.showWhenStarting", false);11myprofile.setPreference("pdfjs.disabled", true);12System.setProperty("webdriver.firefox.profile", "default");13WebDriver driver = new FirefoxDriver();14FirefoxOptions options = new FirefoxOptions();15options.setProfile(new FirefoxProfile());16WebDriver driver = new FirefoxDriver(options);17FirefoxOptions options = new FirefoxOptions();18options.setProfile(new FirefoxProfile());19FirefoxDriverService service = FirefoxDriverService.createDefaultService();20WebDriver driver = new FirefoxDriver(service, options);21FirefoxOptions options = new FirefoxOptions();22options.setProfile(new FirefoxProfile());23WebDriver driver = new FirefoxDriver(options);24FirefoxOptions options = new FirefoxOptions();25options.setProfile(new FirefoxProfile());26FirefoxDriverService service = FirefoxDriverService.createDefaultService();27WebDriver driver = new FirefoxDriver(service, options);28FirefoxOptions options = new FirefoxOptions();29options.setProfile(new FirefoxProfile());30WebDriver driver = new FirefoxDriver(options);

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1ProfilesIni profile = new ProfilesIni();2FirefoxProfile myprofile = profile.getProfile("default");3String path = myprofile.getPreference("browser.download.dir");4System.out.println(path);5File file = new File(path + "\\test.pdf");6System.out.println(file.exists());7long size = file.length();8System.out.println(size);9long lastModified = file.lastModified();10System.out.println(lastModified);11SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");12Date resultdate = new Date(lastModified);13System.out.println(sdf.format(resultdate));14String fileName = file.getName();15System.out.println(fileName);16String extension = fileName.substring(fileName.lastIndexOf(".") + 1);17System.out.println(extension);18String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));19System.out.println(fileNameWithoutExtension);20String filePath = file.getAbsolutePath();21System.out.println(filePath);22String parent = file.getParent();23System.out.println(parent);24File parentFile = file.getParentFile();25System.out.println(parentFile);26long freeSpace = file.getFreeSpace();27System.out.println(freeSpace);28long totalSpace = file.getTotalSpace();29System.out.println(totalSpace);30long usableSpace = file.getUsableSpace();31System.out.println(usableSpace);32long freeSpaceInMB = freeSpace / 1024 / 1024;33System.out.println(freeSpaceInMB + " MB");

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1ProfilesIni profile = new ProfilesIni();2FirefoxProfile myprofile = profile.getProfile("default");3String path = myprofile.getPreference("browser.download.dir");4System.out.println(path);5ProfilesIni profile = new ProfilesIni();6FirefoxProfile myprofile = profile.getProfile("default");7String path = myprofile.getPreference("browser.download.dir");8System.out.println(path);9ProfilesIni profile = new ProfilesIni();10FirefoxProfile myprofile = profile.getProfile("default");11String path = myprofile.getPreference("browser.download.dir");12System.out.println(path);13ProfilesIni profile = new ProfilesIni();14FirefoxProfile myprofile = profile.getProfile("default");15String path = myprofile.getPreference("browser.download.dir");16System.out.println(path);17ProfilesIni profile = new ProfilesIni();18FirefoxProfile myprofile = profile.getProfile("default");19String path = myprofile.getPreference("browser.download.dir");20System.out.println(path);21ProfilesIni profile = new ProfilesIni();22FirefoxProfile myprofile = profile.getProfile("default");23String path = myprofile.getPreference("browser.download.dir");24System.out.println(path);25ProfilesIni profile = new ProfilesIni();26FirefoxProfile myprofile = profile.getProfile("default");27String path = myprofile.getPreference("browser.download.dir");28System.out.println(path);29ProfilesIni profile = new ProfilesIni();30FirefoxProfile myprofile = profile.getProfile("default");31String path = myprofile.getPreference("browser.download.dir");32System.out.println(path);

Full Screen

Full Screen

locateAppDataDirectory

Using AI Code Generation

copy

Full Screen

1package com.zetcode;2import java.io.File;3import org.openqa.selenium.firefox.FirefoxDriver;4import org.openqa.selenium.firefox.FirefoxProfile;5import org.openqa.selenium.firefox.ProfilesIni;6public class FirefoxDownload {7 public static void main(String[] args) throws InterruptedException {8 ProfilesIni profile = new ProfilesIni();9 FirefoxProfile myprofile = profile.getProfile("default");10 File file = new File("C:\\Users\\MiroslavKucera\\Desktop\\test");11 myprofile.setPreference("browser.download.dir", file.getAbsolutePath());12 myprofile.setPreference("browser.download.folderList", 2);13 myprofile.setPreference("browser.helperApps.neverAsk.saveToDisk",14 "application/octet-stream");15 myprofile.setPreference("pdfjs.disabled", true);16 FirefoxDriver driver = new FirefoxDriver(myprofile);17 driver.findElementByLinkText("Download").click();18 Thread.sleep(3000);19 driver.quit();20 }21}

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.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful