How to use FileExtension class of org.openqa.selenium.firefox package

Best Selenium code snippet using org.openqa.selenium.firefox.FileExtension

Source:FirefoxProfile.java Github

copy

Full Screen

...13import org.openqa.selenium.Beta;14import org.openqa.selenium.WebDriverException;15import org.openqa.selenium.firefox.internal.ClasspathExtension;16import org.openqa.selenium.firefox.internal.Extension;17import org.openqa.selenium.firefox.internal.FileExtension;18import org.openqa.selenium.io.FileHandler;19import org.openqa.selenium.io.TemporaryFilesystem;20import org.openqa.selenium.io.Zip;21public class FirefoxProfile22{23 public static final String PORT_PREFERENCE = "webdriver_firefox_port";24 public static final String ALLOWED_HOSTS_PREFERENCE = "webdriver_firefox_allowed_hosts";25 private static final String defaultPrefs = "/org/openqa/selenium/firefox/webdriver_prefs.json";26 private Preferences additionalPrefs;27 private Map<String, Extension> extensions = Maps.newHashMap();28 private boolean loadNoFocusLib;29 private boolean acceptUntrustedCerts;30 private boolean untrustedCertIssuer;31 private File model;32 private static final String ACCEPT_UNTRUSTED_CERTS_PREF = "webdriver_accept_untrusted_certs";33 private static final String ASSUME_UNTRUSTED_ISSUER_PREF = "webdriver_assume_untrusted_issuer";34 35 public FirefoxProfile() {36 this(null);37 }38 39 public FirefoxProfile(File profileDir)40 {41 this(null, profileDir);42 }43 44 @Beta45 @VisibleForTesting46 protected FirefoxProfile(Reader defaultsReader, File profileDir) {47 if (defaultsReader == null) {48 defaultsReader = onlyOverrideThisIfYouKnowWhatYouAreDoing();49 }50 51 additionalPrefs = new Preferences(defaultsReader);52 53 model = profileDir;54 verifyModel(model);55 56 File prefsInModel = new File(model, "user.js");57 if (prefsInModel.exists()) {58 StringReader reader = new StringReader("{\"frozen\": {}, \"mutable\": {}}");59 Preferences existingPrefs = new Preferences(reader, prefsInModel);60 acceptUntrustedCerts = getBooleanPreference(existingPrefs, "webdriver_accept_untrusted_certs", true);61 untrustedCertIssuer = getBooleanPreference(existingPrefs, "webdriver_assume_untrusted_issuer", true);62 existingPrefs.addTo(additionalPrefs);63 } else {64 acceptUntrustedCerts = true;65 untrustedCertIssuer = true;66 }67 68 loadNoFocusLib = false;69 try70 {71 defaultsReader.close();72 } catch (IOException e) {73 throw new WebDriverException(e);74 }75 }76 77 @Beta78 protected Reader onlyOverrideThisIfYouKnowWhatYouAreDoing()79 {80 URL resource = Resources.getResource(FirefoxProfile.class, "/org/openqa/selenium/firefox/webdriver_prefs.json");81 try {82 return new InputStreamReader(resource.openStream());83 } catch (IOException e) {84 throw new WebDriverException(e);85 }86 }87 88 private boolean getBooleanPreference(Preferences prefs, String key, boolean defaultValue) {89 Object value = prefs.getPreference(key);90 if (value == null) {91 return defaultValue;92 }93 94 if ((value instanceof Boolean)) {95 return ((Boolean)value).booleanValue();96 }97 98 throw new WebDriverException("Expected boolean value is not a boolean. It is: " + value);99 }100 101 public String getStringPreference(String key, String defaultValue) {102 Object preference = additionalPrefs.getPreference(key);103 if ((preference != null) && ((preference instanceof String))) {104 return (String)preference;105 }106 return defaultValue;107 }108 109 public int getIntegerPreference(String key, int defaultValue) {110 Object preference = additionalPrefs.getPreference(key);111 if ((preference != null) && ((preference instanceof Integer))) {112 return ((Integer)preference).intValue();113 }114 return defaultValue;115 }116 117 public boolean getBooleanPreference(String key, boolean defaultValue) {118 Object preference = additionalPrefs.getPreference(key);119 if ((preference != null) && ((preference instanceof Boolean))) {120 return ((Boolean)preference).booleanValue();121 }122 return defaultValue;123 }124 125 private void verifyModel(File model) {126 if (model == null) {127 return;128 }129 130 if (!model.exists())131 {132 throw new UnableToCreateProfileException("Given model profile directory does not exist: " + model.getPath());133 }134 135 if (!model.isDirectory())136 {137 throw new UnableToCreateProfileException("Given model profile directory is not a directory: " + model.getAbsolutePath());138 }139 }140 141 public boolean containsWebDriverExtension() {142 return extensions.containsKey("webdriver");143 }144 145 public void addExtension(Class<?> loadResourcesUsing, String loadFrom)146 {147 File file = new File(loadFrom);148 if (file.exists()) {149 addExtension(file);150 return;151 }152 153 addExtension(loadFrom, new ClasspathExtension(loadResourcesUsing, loadFrom));154 }155 156 public void addExtension(File extensionToInstall)157 {158 addExtension(extensionToInstall.getName(), new FileExtension(extensionToInstall));159 }160 161 public void addExtension(String key, Extension extension) {162 String name = deriveExtensionName(key);163 extensions.put(name, extension);164 }165 166 private String deriveExtensionName(String originalName) {167 String[] pieces = originalName.replace('\\', '/').split("/");168 169 String name = pieces[(pieces.length - 1)];170 name = name.replaceAll("\\..*?$", "");171 return name;172 }...

Full Screen

Full Screen

Source:NewProfileExtensionConnection.java Github

copy

Full Screen

...114 private static Optional<Extension> loadCustomExtension() {115 String xpiProperty = System.getProperty("webdriver.firefox.driver");116 if (xpiProperty != null) {117 File xpi = new File(xpiProperty);118 return Optional.of(new FileExtension(xpi));119 }120 return Optional.empty();121 }122 123 private static Extension loadDefaultExtension() {124 return new ClasspathExtension(FirefoxProfile.class, "/" + FirefoxProfile.class125 .getPackage().getName().replace(".", "/") + "/webdriver.xpi");126 }127 128 public Response execute(Command command) throws IOException {129 return delegate.execute(command);130 }131 132 protected int determineNextFreePort(int port)...

Full Screen

Full Screen

Source:XpiDriverService.java Github

copy

Full Screen

...11import java.util.concurrent.locks.ReentrantLock;12import org.openqa.selenium.WebDriverException;13import org.openqa.selenium.firefox.internal.ClasspathExtension;14import org.openqa.selenium.firefox.internal.Extension;15import org.openqa.selenium.firefox.internal.FileExtension;16import org.openqa.selenium.remote.service.DriverService;17import org.openqa.selenium.remote.service.DriverService.Builder;18public class XpiDriverService19 extends DriverService20{21 private final Lock lock = new ReentrantLock();22 23 private final int port;24 25 private final FirefoxBinary binary;26 27 private final FirefoxProfile profile;28 29 private File profileDir;30 31 private XpiDriverService(File executable, int port, ImmutableList<String> args, ImmutableMap<String, String> environment, FirefoxBinary binary, FirefoxProfile profile)32 throws IOException33 {34 super(executable, port, args, environment);35 36 Preconditions.checkState(port > 0, "Port must be set");37 38 this.port = port;39 this.binary = binary;40 this.profile = profile;41 42 String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");43 44 if (firefoxLogFile != null) {45 if ("/dev/stdout".equals(firefoxLogFile)) {46 sendOutputTo(System.out);47 } else {48 sendOutputTo(new FileOutputStream(firefoxLogFile));49 }50 }51 }52 53 protected URL getUrl(int port) throws IOException54 {55 return new URL("http", "localhost", port, "/hub");56 }57 58 public void start() throws IOException59 {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();79 try {80 binary.quit();81 profile.cleanTemporaryModel();82 profile.clean(profileDir);83 84 lock.unlock(); } finally { lock.unlock();85 }86 }87 88 private void addWebDriverExtension(FirefoxProfile profile) {89 if (profile.containsWebDriverExtension()) {90 return;91 }92 profile.addExtension("webdriver", (Extension)loadCustomExtension().orElse(loadDefaultExtension()));93 }94 95 private Optional<Extension> loadCustomExtension() {96 String xpiProperty = System.getProperty("webdriver.firefox.driver");97 if (xpiProperty != null) {98 File xpi = new File(xpiProperty);99 return Optional.of(new FileExtension(xpi));100 }101 return Optional.empty();102 }103 104 private static Extension loadDefaultExtension() {105 return new ClasspathExtension(FirefoxProfile.class, "/" + FirefoxProfile.class106 107 .getPackage().getName().replace(".", "/") + "/webdriver.xpi");108 }109 110 public static XpiDriverService createDefaultService()111 {112 try113 {...

Full Screen

Full Screen

FileExtension

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.FirefoxProfile;3import org.openqa.selenium.firefox.FileExtension;4public class FileExtensionExample {5 public static void main(String[] args) {6 FirefoxProfile profile = new FirefoxProfile();7 profile.setPreference("browser.download.folderList", 2);8 profile.setPreference("browser.download.dir", "C:\\Selenium");9 profile.setPreference("browser.download.useDownloadDir", true);10 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");11 profile.setPreference("pdfjs.disabled", true);12 profile.setPreference("browser.helperApps.neverAsk.openFile", "application/zip");13 profile.setPreference("browser.helperApps.alwaysAsk.force", false);14 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);15 profile.setPreference("browser.download.manager.focusWhenStarting", false);16 profile.setPreference("browser.download.manager.useWindow", false);17 profile.setPreference("browser.download.manager.showAlertOnComplete", false);18 profile.setPreference("browser.download.manager.closeWhenDone", false);19 profile.setPreference("pdfjs.disabled", true);20 profile.setPreference("plugin.scan.plid.all", false);21 profile.setPreference("plugin.scan.Acrobat", "99.0");22 profile.setPreference("plugin.scan.Quicktime", false);23 profile.setPreference("plugin.scan.WindowsMediaPlayer", false);24 profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf");25 profile.setPreference("extensions.firebug.currentVersion", "1.12.1");26 profile.setPreference("extensions.firebug.allPagesActivation", "on");27 profile.setPreference("extensions.firebug.defaultPanelName", "net");28 profile.setPreference("extensions.firebug.net.enableSites", true);29 profile.setPreference("extensions.firebug.previousPlacement", 1);30 profile.setPreference("extensions.firebug.onByDefault", true);31 profile.setPreference("extensions.firebug.showFirstRunPage", false);32 profile.setPreference("extensions.firebug.net.enableSites", true);33 profile.setPreference("extensions.firebug.console.enableSites", true);34 profile.setPreference("extensions.firebug.script.enableSites", true);

Full Screen

Full Screen

FileExtension

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.example;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.firefox.FirefoxProfile;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class FirefoxProfileExample {10 public static void main(String[] args) {11 FirefoxProfile profile = new FirefoxProfile();12 profile.setPreference("browser.download.folderList", 2);13 profile.setPreference("browser.download.manager.showWhenStarting", false);14 profile.setPreference("browser.download.dir", "C:\\Users\\Downloads");15 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");16 profile.setPreference("browser.helperApps.neverAsk.openFile", "application/zip");17 profile.setPreference("browser.helperApps.alwaysAsk.force", false);18 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);19 profile.setPreference("browser.download.manager.closeWhenDone", true);20 profile.setPreference("browser.download.manager.focusWhenStarting", false);21 profile.setPreference("browser.download.useDownloadDir", true);22 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");23 profile.setPreference("pdfjs.disabled", true);24 DesiredCapabilities cap = DesiredCapabilities.firefox();25 cap.setCapability(FirefoxDriver.PROFILE, profile);26 WebDriver driver = new FirefoxDriver(cap);27 WebDriverWait wait = new WebDriverWait(driver, 10);28 wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("q

Full Screen

Full Screen

FileExtension

Using AI Code Generation

copy

Full Screen

1public class FirefoxProfileDemo {2 public static void main(String[] args) {3 FirefoxProfile profile = new FirefoxProfile();4 profile.setPreference("browser.startup.homepage_override.mstone", "ignore");5 profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");6 profile.setPreference("browser.startup.page", 1);7 profile.setPreference("browser.download.folderList", 2);8 profile.setPreference("browser.download.dir", "C:\\Users\\Public\\Documents");9 profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/plain");10 profile.setPreference("browser.helperApps.alwaysAsk.force", false);11 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);12 profile.setPreference("browser.download.manager.closeWhenDone", true);13 profile.setPreference("browser.download.manager.focusWhenStarting", false);14 profile.setPreference("browser.download.manager.showAlertOnComplete", false);15 profile.setPreference("browser.download.manager.useWindow", false);16 profile.setPreference("browser.download.manager.showWhenStarting", false);17 profile.setPreference("browser.download.manager.alertOnEXEOpen", false);18 profile.setPreference("browser.download.manager.showAlertOnComplete", false);19 profile.setPreference("browser.download.manager.useWindow", false);20 profile.setPreference("browser.download.manager.showWhenStarting", false);21 profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);22 profile.setPreference("pdfjs.disabled", true);23 profile.setPreference("plugin.scan.Acrobat", "99.0");24 profile.setPreference("plugin.scan.plid.all", false);25 profile.setPreference("dom.ipc.plugins.flash.subprocess.crashreporter.enabled", false);26 profile.setPreference("dom.ipc.plugins.flash.subprocess.crashreporter.enabled", false);27 profile.setPreference("extensions.firebug.currentVersion", "2.0.4");28 profile.setPreference("extensions.firebug.allPagesActivation", "on");29 profile.setPreference("extensions.firebug.console.enableSites", true);30 profile.setPreference("extensions.firebug.defaultPanelName", "console");31 profile.setPreference("extensions.firebug.net.enableSites", true);32 profile.setPreference("extensions.firebug

Full Screen

Full Screen

FileExtension

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.firefox.FirefoxDriver;2import org.openqa.selenium.firefox.FirefoxProfile;3import org.openqa.selenium.firefox.FileExtension;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import java.util.concurrent.TimeUnit;7public class FileUpload {8public static void main(String[] args) {9FirefoxProfile profile = new FirefoxProfile();10profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");11FirefoxDriver driver = new FirefoxDriver(profile);12driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);13WebElement uploadButton = driver.findElement(By.name("filename"));14uploadButton.sendKeys("C:\\Users\\Sai\\Desktop\\Sample.csv");15driver.close();16}17}18import org.openqa.selenium.By;19import org.openqa.selenium.WebElement;20import org.openqa.selenium.chrome.ChromeDriver;21import java.util.concurrent.TimeUnit;22public class FileUpload {23public static void main(String[] args) {24System.setProperty("webdriver.chrome.driver", "C:\\Users\\Sai\\Downloads\\chromedriver_win32\\chromedriver.exe");25ChromeDriver driver = new ChromeDriver();26driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);27WebElement uploadButton = driver.findElement(By.name("filename"));28uploadButton.sendKeys("C:\\Users\\Sai\\Desktop\\Sample.csv");29driver.close();30}31}32import org.openqa.selenium.By;33import org.openqa.selenium.WebElement;34import org.openqa.selenium.ie.InternetExplorerDriver;35import java.util.concurrent.TimeUnit;36public class FileUpload {

Full Screen

Full Screen
copy
1public class Student {23 private int id;45 public int getId() {6 return this.id;7 }89 public setId(int newId) {10 this.id = newId;11 }12}13
Full Screen
copy
1public class Some {2 private int id;3 public int getId(){4 return this.id;5 }6 public setId( int newId ) {7 this.id = newId;8 }9}10
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.

...Most popular Stackoverflow questions on FileExtension

Most used methods in FileExtension

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful