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

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

Source:FirefoxProfile.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

Source:FirefoxProfileTest.java Github

copy

Full Screen

...118 }119 @Test120 public void shouldInstallExtensionFromZip() {121 profile.addExtension(InProject.locate(FIREBUG_PATH).toFile());122 File profileDir = profile.layoutOnDisk();123 File extensionFile = new File(profileDir, "extensions/firebug@software.joehewitt.com.xpi");124 assertThat(extensionFile).exists().isFile();125 }126 @Test127 public void shouldInstallWebExtensionFromZip() {128 profile.addExtension(InProject.locate(MOOLTIPASS_PATH).toFile());129 File profileDir = profile.layoutOnDisk();130 File extensionFile = new File(profileDir, "extensions/MooltipassExtension@1.1.87.xpi");131 assertThat(extensionFile).exists().isFile();132 }133 @Test134 public void shouldInstallExtensionFromDirectory() throws IOException {135 File extension = InProject.locate(FIREBUG_PATH).toFile();136 File unzippedExtension = Zip.unzipToTempDir(new FileInputStream(extension), "unzip", "stream");137 profile.addExtension(unzippedExtension);138 File profileDir = profile.layoutOnDisk();139 File extensionDir = new File(profileDir, "extensions/firebug@software.joehewitt.com");140 assertThat(extensionDir).exists().isDirectory();141 }142 @Test143 public void shouldInstallWebExtensionFromDirectory() throws IOException {144 File extension = InProject.locate(MOOLTIPASS_PATH).toFile();145 File unzippedExtension = Zip.unzipToTempDir(new FileInputStream(extension), "unzip", "stream");146 profile.addExtension(unzippedExtension);147 File profileDir = profile.layoutOnDisk();148 File extensionDir = new File(profileDir, "extensions/MooltipassExtension@1.1.87");149 assertThat(extensionDir).exists();150 }151 @Test152 public void shouldInstallExtensionUsingClasspath() {153 profile.addExtension(FirefoxProfileTest.class, FIREBUG_RESOURCE_PATH);154 File profileDir = profile.layoutOnDisk();155 File extensionDir = new File(profileDir, "extensions/firebug@software.joehewitt.com.xpi");156 assertThat(extensionDir).exists();157 }158 @Test159 public void convertingToJsonShouldNotPolluteTempDir() throws IOException {160 File sysTemp = new File(System.getProperty("java.io.tmpdir"));161 Set<String> before = Arrays.stream(sysTemp.list())162 .filter(f -> f.endsWith("webdriver-profile")).collect(Collectors.toSet());163 assertThat(profile.toJson()).isNotNull();164 Set<String> after = Arrays.stream(sysTemp.list())165 .filter(f -> f.endsWith("webdriver-profile")).collect(Collectors.toSet());166 assertThat(after).isEqualTo(before);167 }168 @Test169 public void shouldConvertItselfIntoAMeaningfulRepresentation() throws IOException {170 profile.setPreference("i.like.cheese", true);171 String json = profile.toJson();172 assertThat(json).isNotNull();173 File dir = Zip.unzipToTempDir(json, "webdriver", "duplicated");174 File prefs = new File(dir, "user.js");175 assertThat(prefs.exists()).isTrue();176 try (Stream<String> lines = Files.lines(prefs.toPath())) {177 assertThat(lines.anyMatch(s -> s.contains("i.like.cheese"))).isTrue();178 }179 FileHandler.delete(dir);180 }181 private List<String> readGeneratedProperties(FirefoxProfile profile) throws Exception {182 File generatedProfile = profile.layoutOnDisk();183 File prefs = new File(generatedProfile, "user.js");184 BufferedReader reader = new BufferedReader(new FileReader(prefs));185 List<String> prefLines = new ArrayList<>();186 for (String line = reader.readLine(); line != null; line = reader.readLine()) {187 prefLines.add(line);188 }189 reader.close();190 return prefLines;191 }192 @Test193 public void layoutOnDiskSetsUserPreferences() throws IOException {194 profile.setPreference("browser.startup.homepage", "http://www.example.com");195 Preferences parsedPrefs = parseUserPrefs(profile);196 assertThat(parsedPrefs.getPreference("browser.startup.homepage"))197 .isEqualTo("http://www.example.com");198 }199 @Test200 public void userPrefsArePreservedWhenConvertingToAndFromJson() throws IOException {201 profile.setPreference("browser.startup.homepage", "http://www.example.com");202 String json = profile.toJson();203 FirefoxProfile rebuilt = FirefoxProfile.fromJson(json);204 Preferences parsedPrefs = parseUserPrefs(rebuilt);205 assertThat(parsedPrefs.getPreference("browser.startup.homepage"))206 .isEqualTo("http://www.example.com");207 }208 @Test209 public void backslashedCharsArePreservedWhenConvertingToAndFromJson() throws IOException {210 String dir = "c:\\aaa\\bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh\\iii\\jjj\\kkk\\lll\\mmm\\nnn\\ooo\\ppp\\qqq\\rrr\\sss\\ttt\\uuu\\vvv\\www\\xxx\\yyy\\zzz";211 profile.setPreference("browser.download.dir", dir);212 String json = profile.toJson();213 FirefoxProfile rebuilt = FirefoxProfile.fromJson(json);214 Preferences parsedPrefs = parseUserPrefs(rebuilt);215 assertThat(parsedPrefs.getPreference("browser.download.dir")).isEqualTo(dir);216 }217 private void assertPreferenceValueEquals(String key, Object value) throws Exception {218 List<String> props = readGeneratedProperties(profile);219 assertThat(props.stream().anyMatch(line -> line.contains(key) && line.contains(", " + value + ")"))).isTrue();220 }221 private Preferences parseUserPrefs(FirefoxProfile profile) throws IOException {222 File directory = profile.layoutOnDisk();223 File userPrefs = new File(directory, "user.js");224 FileReader reader = new FileReader(userPrefs);225 return new Preferences(new StringReader("{\"mutable\": {}, \"frozen\": {}}"), reader);226 }227}...

Full Screen

Full Screen

Source:MyFirefoxProfile.java Github

copy

Full Screen

...22 firefoxProfile = getDefaultProfile();23 setProfile(file);24 }25 public MyFirefoxProfile(FirefoxProfile profile) {26 super(profile.layoutOnDisk());27 firefoxProfile = profile;28 file = profile.layoutOnDisk();29 loadUserJS(file);30 setProfile(file);31 }32 public MyFirefoxProfile(FirefoxProfile profile, File file) {33 super(file);34 this.file = file;35 loadUserJS(file);36 firefoxProfile = profile;37 setProfile(file);38 }39 public MyFirefoxProfile(FirefoxProfile profile, String path) {40 super(new File(path));41 this.file = new File(path);42 loadUserJS(file);43 firefoxProfile = profile;44 setProfile(path);45 }46 public MyFirefoxProfile(String path) {47 this(new File(path));48 this.file = new File(path);49 loadUserJS(file);50 firefoxProfile = new FirefoxProfile(new File(path));51 setProfile(path);52 }53 public MyFirefoxProfile(File file) {54 super(file);55 this.file = file;56 loadUserJS(file);57 firefoxProfile = new FirefoxProfile(file);58 setProfile(file);59 }60 public MyFirefoxProfile(Reader defaultsReader, File profileDir) {61 super(defaultsReader, profileDir);62 this.file = profileDir;63 loadUserJS(file);64 firefoxProfile = new FirefoxProfile(profileDir);65 setProfile(profileDir);66 }67 public MyFirefoxProfile(FirefoxProfile firefoxProfile, Reader defaultsReader, File profileDir) {68 this.file = profileDir;69 loadUserJS(file);70 this.firefoxProfile = new FirefoxProfile(profileDir);71 setProfile(profileDir);72 }73 @Override74 public void addExtension(File extensionToInstall) throws IOException {75 super.addExtension(extensionToInstall);76 firefoxProfile.addExtension(extensionToInstall);77 }78 @Override79 public void addExtension(String key, Extension extension) {80 super.addExtension(key, extension);81 firefoxProfile.addExtension(key, extension);82 }83 @Override84 public void setEnableNativeEvents(boolean enableNativeEvents) {85 super.setEnableNativeEvents(enableNativeEvents);86 firefoxProfile.setEnableNativeEvents(enableNativeEvents);87 }88 public void setFirefoxProfile(FirefoxProfile firefoxProfile) {89 this.firefoxProfile = firefoxProfile;90 setProfile();91 }92 @Override93 public void setPreference(String key, String value) {94 super.setPreference(key, value);95 firefoxProfile.setPreference(key, value);96 }97 @Override98 public void setPreference(String key, boolean value) {99 super.setPreference(key, value);100 firefoxProfile.setPreference(key, value);101 }102 @Override103 public void setPreference(String key, int value) {104 super.setPreference(key, value);105 firefoxProfile.setPreference(key, value);106 }107 @Override108 public boolean shouldLoadNoFocusLib() {109 return firefoxProfile.shouldLoadNoFocusLib();110 }111 @Override112 public String toJson() throws IOException {113 return firefoxProfile.toJson();114 }115 @Override116 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);137 firefoxProfile.setAcceptUntrustedCertificates(acceptUntrustedSsl);138 }139 @Override140 public File layoutOnDisk() {141 return firefoxProfile.layoutOnDisk();142 }143 @Override144 public int hashCode() {145 return firefoxProfile.hashCode();146 }147 public static String getPORT_PREFERENCE() {148 return PORT_PREFERENCE;149 }150 @Override151 public int getIntegerPreference(String key, int defaultValue) {152 return firefoxProfile.getIntegerPreference(key, defaultValue);153 }154 public FirefoxProfile getFirefoxProfile() {155 return firefoxProfile;156 }157 public static String getALLOWED_HOSTS_PREFERENCE() {158 return ALLOWED_HOSTS_PREFERENCE;159 }160 @Override161 protected void finalize() throws Throwable {162 super.finalize();163 }164 @Override165 public boolean equals(Object obj) {166 return firefoxProfile.equals(obj);167 }168 @Override169 protected void deleteLockFiles(File profileDir) {170 super.deleteLockFiles(profileDir);171 }172 @Override173 public void deleteExtensionsCacheIfItExists(File profileDir) {174 super.deleteExtensionsCacheIfItExists(profileDir);175 firefoxProfile.deleteExtensionsCacheIfItExists(profileDir);176 }177 @Override178 protected void copyModel(File sourceDir, File profileDir) throws IOException {179 super.copyModel(sourceDir, profileDir);180 }181 @Override182 public boolean containsWebDriverExtension() {183 return firefoxProfile.containsWebDriverExtension();184 }185 @Override186 protected Object clone() throws CloneNotSupportedException {187 return super.clone();188 }189 @Override190 protected void cleanTemporaryModel() {191 super.cleanTemporaryModel();192 }193 @Override194 public void clean(File profileDir) {195 super.clean(profileDir);196 firefoxProfile.clean(profileDir);197 }198 @Override199 public boolean areNativeEventsEnabled() {200 return firefoxProfile.areNativeEventsEnabled();201 }202 @Override203 public void addExtension(Class<?> loadResourcesUsing, String loadFrom) throws IOException {204 super.addExtension(loadResourcesUsing, loadFrom);205 firefoxProfile.addExtension(loadResourcesUsing, loadFrom);206 }207 private void setProfile() {208 setProfile(firefoxProfile.layoutOnDisk());209 }210 private void setProfile(String path) {211 setProfile(new File(path));212 }213 private void setProfile(File file) {214 if (!file.exists()) {215 file.mkdirs();216 }217 this.setAcceptUntrustedCertificates(true);218 this.setPreference("signon.importedFromSqlite", true);219 this.setPreference("services.sync.prefs.sync.signon.rememberSignons", true);220 this.setPreference("security.ask_for_password", "0");221 this.setPreference("plugin.importedState", true);222 this.setPreference("browser.download.importedFromSqlite", true);...

Full Screen

Full Screen

Source:NewProfileExtensionConnection.java Github

copy

Full Screen

...58 try {59 port = determineNextFreePort(profile.getIntegerPreference("webdriver_firefox_port", 7055));60 profile.setPreference("webdriver_firefox_port", port);61 62 profileDir = profile.layoutOnDisk();63 64 delegate = new HttpCommandExecutor(buildUrl(host, port));65 delegate.setLocalLogs(logs);66 String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");67 68 if (firefoxLogFile != null) {69 if ("/dev/stdout".equals(firefoxLogFile)) {70 process.setOutputWatcher(System.out);71 } else {72 process.setOutputWatcher(new MultiOutputStream(new CircularOutputStream(), new FileOutputStream(firefoxLogFile)));73 }74 }75 76 process.startProfile(profile, profileDir, new String[] { "-foreground" });...

Full Screen

Full Screen

Source:ZeUltimateLocalhostFirefoxConnection.java Github

copy

Full Screen

...37 //lock.lock(connectTimeout);38 try {39 port = determineNextFreePort(7070);40 profile.setPreference(PORT_PREFERENCE, port);41 profileDir = profile.layoutOnDisk();42 //process.clean(profile, profileDir);43 delegate = new HttpCommandExecutor(buildUrl("localhost", port));44 delegate.setLocalLogs(logs);45 String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");46 if (firefoxLogFile != null) {47 if ("/dev/stdout".equals(firefoxLogFile)) {48 //process.setOutputWatcher(System.out);49 } else {50 File logFile = new File(firefoxLogFile);51 ///process.setOutputWatcher(new CircularOutputStream(logFile, BUFFER_SIZE));52 }53 }54 //process.startProfile(profile, profileDir, "-foreground");55 // Just for the record; the critical section is all along while firefox is starting with the...

Full Screen

Full Screen

Source:XpiDriverService.java Github

copy

Full Screen

...60 lock.lock();61 try {62 profile.setPreference("webdriver_firefox_port", port);63 addWebDriverExtension(profile);64 profileDir = profile.layoutOnDisk();65 66 binary.setOutputWatcher(getOutputStream());67 68 binary.startProfile(profile, profileDir, new String[] { "-foreground" });69 70 waitUntilAvailable();71 72 lock.unlock(); } finally { lock.unlock();73 }74 }75 76 public void stop()77 {78 lock.lock();...

Full Screen

Full Screen

Source:AbstractSeleniumTest.java Github

copy

Full Screen

...81 profile.setEnableNativeEvents(false);82 profile.setPreference("app.update.auto", false);83 profile.setPreference("app.update.enabled", false);84 profile.setPreference("app.update.silent", false);85 LOG.info("Created Firefox Profile: " + profile + ", [" + profile.layoutOnDisk().getAbsolutePath() + "]");86 return profile;87 } catch (UnableToCreateProfileException e) {88 throw new RuntimeException("Unable to create profile [" + e.getMessage() + "]" + ".", e);89 }90 }91 private void loadProperties() {92 try {93 InputStream input = new FileInputStream(CONFIG_FILE_NAME);94 CONFIG_PROPERTIES.load(input);95 } catch (IOException e) {96 fail(e.getMessage());97 }98 }99 private String getProperty(String key) {...

Full Screen

Full Screen

Source:FirefoxTrafficEater.java Github

copy

Full Screen

...56 protected void profileCreated(File profileDir) {57 // no op58 }59 @Override60 public File layoutOnDisk() {61 File profileDir = super.layoutOnDisk();62 profileCreated(profileDir);63 return profileDir;64 }65 }66}...

Full Screen

Full Screen

layoutOnDisk

Using AI Code Generation

copy

Full Screen

1package com.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.firefox.FirefoxDriver;6public class SourceCode {7public static void main(String[] args) {8System.setProperty("webdriver.gecko.driver", "C:\\Users\\Selenium\\Desktop\\geckodriver.exe");9WebDriver driver = new FirefoxDriver();10driver.manage().window().maximize();11WebElement element = driver.findElement(By.cssSelector("body"));

Full Screen

Full Screen

layoutOnDisk

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.FirefoxProfile;3import org.openqa.selenium.WebDriver;4public class FirefoxProfileDemo {5public static void main(String[] args) {6 FirefoxProfile profile = new FirefoxProfile();7 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");8 profile.setPreference("startup.homepage_welcome_url", "about:blank");9 profile.setPreference("browser.startup.homepage", "about:blank");10 profile.setPreference("browser.startup.page", 0);11 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");12 profile.setPreference("startup.homepage_welcome_url", "about:blank");13 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");14 profile.setPreference("browser.startup.page", 0);15 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");16 profile.setPreference("startup.homepage_welcome_url", "about:blank");17 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");18 profile.setPreference("browser.startup.page", 0);19 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");20 profile.setPreference("startup.homepage_welcome_url", "about:blank");21 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");22 profile.setPreference("browser.startup.page", 0);23 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");24 profile.setPreference("startup.homepage_welcome_url", "about:blank");25 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");26 profile.setPreference("browser.startup.page", 0);27 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");28 profile.setPreference("startup.homepage_welcome_url", "about:blank");29 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");30 profile.setPreference("browser.startup.page", 0);31 profile.setPreference("browser.start

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