package com.gloryroad.Demo;
import org.junit.Before;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class DownLoadFile {
public static String downloadFilePath="C:\\Doload";
WebDriver driver;
String baseUrl;
JavascriptExecutor js;
@BeforeMethod
public void beforeMethod(){
baseUrl="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/35.0b8/win32/zh-CN";
}
@AfterMethod
public void afterMethod(){
driver.quit();
}
@Test
public void testdataPicker(){
driver=new FirefoxDriver(FirefoxDriverProfile());
driver.get(baseUrl);
}
public static FirefoxProfile FirefoxDriverProfile(){
FirefoxProfile profile=new FirefoxProfile();
//设定为0则会下载到桌面,设定为2则会表示下载到用户的桌面上
profile.setPreference("browser.download.folderList", 2);
//设置为true表示下载的时候显示火狐浏览器文件下载窗口,设置false表示不显示
profile.setPreference("browser.download.manager.showWhenStarting", false);
//设定下载的文件的存储位置
profile.setPreference("browser.download.dir",downloadFilePath);
//完成提示框,默认为true,设定为false表示下载完成后不显示下载完成的提示框
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
//设定下载结束后是否自动关闭下载管理器默认为true,
profile.setPreference("browser.download.manager.closeWhenDone", false);
//让用户处理默认为true,设定为false,表示不会记录打开位置的MIKE类型的文件
profile.setPreference("browser.helperApps.alwaysAsk.froce", false);
//下载。exe文件弹出警告框,默认是true,设定为false则不会弹出来
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
//设定下载框在下载时会获取焦点,默认为true,设为false
profile.setPreference("browser.download.manager.focusWhenStarting", false);
//设定下载时是否显示下载框,默认为true,设为false
profile.setPreference("browser.download.manager.useWindow",false);
//不提示,直接下载文件
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "appliction/pdf");
return profile;
}
}
import org.junit.Before;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class DownLoadFile {
public static String downloadFilePath="C:\\Doload";
WebDriver driver;
String baseUrl;
JavascriptExecutor js;
@BeforeMethod
public void beforeMethod(){
baseUrl="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/35.0b8/win32/zh-CN";
}
@AfterMethod
public void afterMethod(){
driver.quit();
}
@Test
public void testdataPicker(){
driver=new FirefoxDriver(FirefoxDriverProfile());
driver.get(baseUrl);
}
public static FirefoxProfile FirefoxDriverProfile(){
FirefoxProfile profile=new FirefoxProfile();
//设定为0则会下载到桌面,设定为2则会表示下载到用户的桌面上
profile.setPreference("browser.download.folderList", 2);
//设置为true表示下载的时候显示火狐浏览器文件下载窗口,设置false表示不显示
profile.setPreference("browser.download.manager.showWhenStarting", false);
//设定下载的文件的存储位置
profile.setPreference("browser.download.dir",downloadFilePath);
//完成提示框,默认为true,设定为false表示下载完成后不显示下载完成的提示框
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
//设定下载结束后是否自动关闭下载管理器默认为true,
profile.setPreference("browser.download.manager.closeWhenDone", false);
//让用户处理默认为true,设定为false,表示不会记录打开位置的MIKE类型的文件
profile.setPreference("browser.helperApps.alwaysAsk.froce", false);
//下载。exe文件弹出警告框,默认是true,设定为false则不会弹出来
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
//设定下载框在下载时会获取焦点,默认为true,设为false
profile.setPreference("browser.download.manager.focusWhenStarting", false);
//设定下载时是否显示下载框,默认为true,设为false
profile.setPreference("browser.download.manager.useWindow",false);
//不提示,直接下载文件
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "appliction/pdf");
return profile;
}
}