亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium2/Webdriver啟動各種瀏覽器的方法
作者:網絡轉載 發布時間:[ 2017/2/15 11:31:39 ] 推薦標簽:功能測試 selenium

  本文主要記錄下在使用selenium2/webdriver時啟動各種瀏覽器的方法、以及如何加載插件、定制瀏覽器信息(設置profile)等
  一、Driver下載地址:
  http://docs.seleniumhq.org/download/
  二、啟動firefox瀏覽器(不需要下載驅動,原生支持)
  1、firefox安裝在默認路徑下:
1     //啟動默認安裝路徑下的ff
2     public void StartFireFoxByDefault(){
3         System.out.println("start firefox browser...");
4         WebDriver driver = new FirefoxDriver();      //直接new一個FirefoxDriver即可
5         Navigation navigation = driver.navigate();
6         navigation.to("http://www.baidu.com/");
7         System.out.println("start firefox browser succeed...");
8     }
  2、firefox未安裝在默認路徑下:
1 public static void StartFireFoxNotByDefault(){
2         System.out.println("start firefox browser...");
3         System.setProperty("webdriver.firefox.bin",     //指定firefox的安裝路徑
4                 "D:/Program Files/Mozilla Firefox/firefox.exe");
5         WebDriver driver = new FirefoxDriver();
6         Navigation navigation = driver.navigate();
7         navigation.to("http://www.baidu.com/");
8         System.out.println("start firefox browser succeed...");
9     }
  3、啟動firefox時加載插件:
  首先,要知道我們為什么需要加載插件?原因是webdriver在啟動瀏覽器時,啟動的一個干凈的沒有任務、插件及cookies信息的瀏覽器(即使你本機的firefox安裝了某些插件,webdriver啟動firefox也是沒有這些插件的),但是有可能被測系統本身需要插件或者需要調試等等,此時可以用如下方法在啟動firefox時加載插件,下面示例加載firebug插件:
1     public static void StartFireFoxLoadPlugin(){
2         System.out.println("start firefox browser...");
3         System.setProperty("webdriver.firefox.bin",
4                 "D:/Program Files/Mozilla Firefox/firefox.exe");
5         File file = new File("files/firebug-2.0.7-fx.xpi");
6         FirefoxProfile profile = new FirefoxProfile();
7         try {
8             profile.addExtension(file);
9         } catch (IOException e) {
10             e.printStackTrace();
11         }
12         profile.setPreference("extensions.firebug.currentVersion", "2.0.7");
13         //active firebug extensions
14         profile.setPreference("extensions.firebug.allPagesActivation", "on");
15         WebDriver driver = new FirefoxDriver(profile);
16         driver.get("http://www.baidu.com");
17         System.out.println("start firefox browser succeed...");
18     }
  4、啟動firefox時設置profile:
  上面提到過webdriver啟動firefox時是啟動一個完全新的瀏覽器,我們除了可以使用上面提到的方法定制插件,webdriver還可以對profile進行定制(在firefox地址欄中輸入about:config,可以查看firefox的參數),下面設置代理和默認下載路徑:
1     public static void StartFireFoxByProxy(){
2         String proxyIp = "10.17.171.11";
3         int proxyPort = 8080;
4         System.out.println("start firefox browser...");
5         System.setProperty("webdriver.firefox.bin",
6                 "D:/Program Files/Mozilla Firefox/firefox.exe");
7
8         FirefoxProfile profile = new FirefoxProfile();
9         //設置代理參數
10         profile.setPreference("network.proxy.type", 1);
11         profile.setPreference("network.proxy.http", proxyIp);
12         profile.setPreference("network.proxy.http_port", proxyPort);
13
14         //設置默認下載路徑
15         profile.setPreference("browser.download.folderList", 2);
16         profile.setPreference("browser.download.dir", "D:\");
17
18         WebDriver driver = new FirefoxDriver(profile);
19         driver.get("http://www.baidu.com");
20
21         System.out.println("start firefox browser succeed...");
22     }
  5、啟動本機器的firefox配置:
  每次啟動如果都像上面那樣在代碼里面配置profile比較麻煩,可以使用下面的方法啟動本機器的firefox的配置,換句話說是我們可以 事先配置本機的firefox然后用webdriver啟動它,這樣本機上的firefox安裝了什么插件都可以直接使用了,不需要在配置 profile:
1     public static void StartLocalFirefox(){
2         System.out.println("start firefox browser...");
3         System.setProperty("webdriver.firefox.bin",
4                 "D:/Program Files/Mozilla Firefox/firefox.exe");
5         ProfilesIni pi = new ProfilesIni();
6         FirefoxProfile profile = pi.getProfile("default");
7         WebDriver driver = new FirefoxDriver(profile);
8         driver.get("http://www.baidu.com/");
9         System.out.println("start firefox browser succeed...");
10     }
  6、如果在機器B上要啟動機器A上的firefox配置,可以先導出A的配置,然后加載:
  1、將A機器上的Profiles文件夾”C:UserscloudchenAppDataLocalMozillaFirefoxProfiles”給拷貝出來到某個目錄
  2、代碼:
1     public static void StartFireFoxByOtherConfig(){
2         System.out.println("start firefox browser...");
3         System.setProperty("webdriver.firefox.bin",
4                 "D:/Program Files/Mozilla Firefox/firefox.exe");
5         File file = new File("files\lg6mie1i.default");        //profiles文件目錄,這里我是放在工程目錄下的files文件夾下
6         FirefoxProfile profile = new FirefoxProfile(file);
7         WebDriver driver = new FirefoxDriver(profile);
8         driver.get("http://www.baidu.com");
9         System.out.println("start firefox browser succeed...");
10     }
  PS:如果插件或其它東東未加載成功,可以檢查下profile文件夾下是否包含插件信息。

上一頁12下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 在线观看国产欧美 | 夜夜穞狠狠穞 | 日韩在线三级视频 | 欧美一级v片 | 91社区在线观看精品 | 精品小视频| 男女午夜激情 | 亚洲福利一区二区三区 | 真人一级毛片免费完整视 | 成人免费在线视频网 | 国产三级欧美 | a级毛片免费完整视频 | 免费一级黄色片 | 黄色国产在线观看 | 免费黄色福利 | 大陆一级黄色片 | 深夜在线| 黄色网址免费在线观看 | a黄色片 | 日本欧美视频在线 | 51视频在线| 欧美日韩免费播放一区二区 | 在线 中文字幕 日韩 欧美 | 欧美天堂在线观看 | 小泽玛利亚在线观看123 | 国产欧美一级片 | 亚洲视频一区网站 | 日韩美女性行为免费视频 | 奇米777狠狠色噜噜狠狠狠 | 日韩欧美手机在线 | 天堂网视频在线观看 | 夜夜躁日日躁狠狠久久 | 亚洲欧美日韩国产精品26u | 欧美任你躁免费精品一区 | 国产精品视频网址 | 一级毛片免费全部播放完整 | 成年网址网站在线观看 | 黄色三级视频网站 | 国内一卡2卡三卡四卡在线 国外欧美一区另类中文字幕 | 久久综合九色婷婷97 | 日韩在线不卡视频 |