import java.io.File;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class WebDriverProducerFactory {
public static FirefoxDriver getFireFoxDriver() throws InterruptedException{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","C:\\QA Team Files\\ESGManager\\download\\FireFoxDownload\\");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf");
firefoxProfile.setEnableNativeEvents(true);
File fin = new File("C:\\QA Team Files\\ESGManager\\download\\FireFoxDownload\\");
File[] finlist = fin.listFiles();
for (int n = 0; n < finlist.length; n++) {
if (finlist[n].isFile()) {
System.gc();
Thread.sleep(2000);
finlist[n].delete();
}
}
File pathToBinary = new File("C:/Program Files (x86)/FrontMotion/Firefox/firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
ESGManagerFireFoxWebDriver esgManagerFireFoxWebDriver = new ESGManagerFireFoxWebDriver(ffBinary,firefoxProfile);
esgManagerFireFoxWebDriver.manage().window().setPosition(new Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
esgManagerFireFoxWebDriver.manage().window().setSize(dim);
return esgManagerFireFoxWebDriver;
}
public static FirefoxDriver getFireFoxPathDownloadDriver(String path) throws InterruptedException{
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
//Anyway, in order to make Firefox saving pdf files to a pre-defined folder as the default behaviour, you might want to try the following code, where setting pdfjs.disabled to true will prevent Firefox previewing the files.
profile.setPreference("pdfjs.disabled", true);
// Use this to disable Acrobat plugin for previewing PDFs in Firefox (if you have Adobe reader installed on your computer)
profile.setPreference("plugin.scan.Acrobat", "99.0");
profile.setPreference("plugin.scan.plid.all", false);
profile.setPreference("browser.download.dir",path);
String file_types = "application/acrobat, application/nappdf, application/x-pdf, application/vnd.pdf, text/pdf, text/x-pdf, application/vnd.sealedmedia.softseal.pdf" +
"text/comma-separated-values,text/csv, text/pdf, application/pdf, application/x-msdos-program, application/x-unknown-application-octet-stream,"
+ "application/vnd.ms-powerpoint, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel,"
+ "application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip, application/x-stuffit,"
+"application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar,"
+ "video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff, text/plain, application/vnd.ms-excel [official],"
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msexcel, application/x-msexcel,"
+ "application/x-excel, application/excel, application/x-ms-excel, application/x-dos_ms_excel,"
+ "text/csv, text/comma-separated-values, application/octet-stream, application/haansoftxls application/xml, application/xhtml+xml,"
+ "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf,"
+ "application/vnd.ms-excel (official), application/msexcel, application/x-msexcel, application/x-ms-excel, application/x-excel, application/x-dos_ms_excel, application/xls, application/x-xls, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx),"
+ "application/softgrid-xls, x-softmaker-pm, text/tab-separated-values, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel (official)";
// String file_types = "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf";
profile.setPreference("browser.helperApps.neverAsk.openFile", file_types);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", file_types);
// profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");
File fin = new File(path);
if (!fin.exists()) {
fin.mkdirs();
}
File pathToBinary = new File("C:/Program Files (x86)/FrontMotion/Firefox/firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
ESGManagerFireFoxWebDriver esgManagerFireFoxWebDriver = new ESGManagerFireFoxWebDriver(ffBinary,profile);
esgManagerFireFoxWebDriver.manage().window().setPosition(new Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
esgManagerFireFoxWebDriver.manage().window().setSize(dim);
return esgManagerFireFoxWebDriver;
}
public static RemoteWebDriver getWebDriver(String browserType){
if (browserType.toLowerCase().contains(Constant.FIREFOX)){
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","C:\\QA Team Files\\ESGManager\\download\\FireFoxDownload\\");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf");
firefoxProfile.setEnableNativeEvents(true);
File pathToBinary = new File("C:/Program Files (x86)/FrontMotion/Firefox/firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
ESGManagerFireFoxWebDriver esgManagerFireFoxWebDriver = new ESGManagerFireFoxWebDriver(ffBinary,firefoxProfile);
esgManagerFireFoxWebDriver.manage().window().setPosition(new Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
esgManagerFireFoxWebDriver.manage().window().setSize(dim);
return esgManagerFireFoxWebDriver;
}
if (browserType.toLowerCase().contains(Constant.IEXPLORER)){
System.setProperty("webdriver.ie.driver","C:\\bby\\selenium\\2.32\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
ESGManagerInternetExprolerWebDriver esgManagerInternetExplorerWebDriver =
new ESGManagerInternetExprolerWebDriver(ieCapabilities);
esgManagerInternetExplorerWebDriver.manage().window().setPosition(new Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
esgManagerInternetExplorerWebDriver.manage().window().setSize(dim);
return esgManagerInternetExplorerWebDriver ;
}
return null;
}
}
分享到:
相关推荐
Firefox and Thunderbird Garage is a book dedicated to helping readers get the most out of these new programs from download to installation to configuration. This book includes extensive information ...
m3u8 m3u8文件下载器库以及chrome和firefox扩展/插件用法下载并保存m3u8文件: var p = new m3u8_processor . DownloadFileAndSaveInputParams (){ m3u8FileUrl = < M3U8> , OutputFileName = @" C:\abc.avi " ,};...
NEW When opening a new tab, users are now presented with their most visited pages NEW The default home page now has quicker access to bookmarks, history, settings, and more CHANGED SPDY protocol now ...
registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); ``` 七、暂停和取消下载 `DownloadManager`提供了暂停和取消下载的方法: ```java // 暂停下载 download...
Now you can use the link right-click menu item "Download Express: download this file." Also, FireFox will offer you to use Download Express to download files. --------------------------------------...
对于非IE浏览器,如Firefox、Chrome、Safari、360等,它们不支持ActiveXObject。我们可以使用Blob对象和URL.createObjectURL方法创建一个临时的文件URL,然后创建一个`<a>`标签指向这个URL,模拟点击下载。同时,...
NeatDownloadManager Extension是一款Chrome和Firefox浏览器的扩展程序,它可以用来下载文件。这个扩展程序可以让您更有效地管理您的下载,包括恢复和暂停下载,设置下载速度限制,以及下载完成后自动执行某些操作,...
4. **集成浏览器**:IDM支持与多种主流浏览器无缝集成,如Chrome、Firefox、Edge等,使得下载操作更为便捷。 5. **断点续传**:在因网络问题或其他原因导致下载中断后,IDM可以从上次停止的位置继续下载,确保文件...
DownThemAll (or just dTa) is a powerful yet easy-to-use Mozilla Firefox extension that adds new advanced download capabilities to your browser. DownThemAll lets you download all the links or images ...
DownThemAll (or just dTa) is a powerful yet easy-to-use Mozilla Firefox extension that adds new advanced download capabilities to your browser. DownThemAll lets you download all the links or images ...
} else if (agent.contains("Firefox")) { // 火狐浏览器 //java 9和以上版本已经处理掉了 BASE64Encoder类 /*BASE64Encoder base64Encoder = new BASE64Encoder(); filename = "=?utf...
它支持多种浏览器,包括IE、Firefox、Opera和Safari。 2. **dematte.at/colorPicker** - 另一个颜色选择器,可能提供了不同风格和功能的色彩选取组件,帮助开发者增强用户体验。 3. **...
标题“download_img_from_1000_for_ff”和描述中的信息表明,这是一个与批量下载图片相关的项目,可能特别针对Firefox浏览器。考虑到标签是“JavaScript”,我们可以推断这个项目使用JavaScript语言来实现从某个源...
Selenium WebDriver 支持多种浏览器,包括 Firefox、Internet Explorer 和 HtmlUnit 等。其中 Firefox 是 Selenium 最早且支持最成熟的浏览器之一。然而,在实际的自动化测试中,考虑到性能因素,尤其是为了加速持续...
uniGUI Web Application Framework extends Web application development experience to a new dimension. uniGUI enables Delphi ...Supported Browsers: IE 9+, Microsoft Edge, FireFox, Chrome, Safari and Opera
**vimperator 是一款基于 Firefox 浏览器的扩展,它将浏览器的操作模式转变为 Vim 编辑器的风格,提供了一种高效、键盘驱动的浏览体验。这篇博客文章将探讨 vimperator 的一些配置方法,帮助用户根据个人喜好定制其...
- **下载地址**: [http://www.firefox.com.cn/download/](http://www.firefox.com.cn/download/) - **插件安装**: - **Selenium IDE**: 将下载的`.xpi`文件拖拽至Firefox浏览器中进行安装。 - **Firebug**: 在Fire...