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

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium各種場景下的啟動Firefox
作者:網絡轉載 發布時間:[ 2015/10/15 14:11:53 ] 推薦標簽:軟件測試工具 單元測試工具

  開始學習selenium時為了啟動Firefox可謂費盡周折,在大神的幫助下才堪堪搞定,走出了selenium的第一步:jdk1.8 + selenium_2.46 + Firefox國際版40.0.3。
  1、selenium啟動Firefox時,默認啟動一個全新的,不加載任何個人數據的瀏覽器,這也是簡單的:
  public void startFirefox(){
  driver = new FirefoxDriver();
  System.out.println("startFirefox.");
  }
  當然如果Firefox沒有安裝在默認路徑下這需要我們手動設置Firefox的啟動路徑:
  System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla firefox/firefox.exe");
  WebDriver driver = newFirefoxDriver();
  2、問題隨之而來,如果我們要讓瀏覽器啟動時帶上我想要的某個擴展,或者是直接按照我的配置文件來啟動,我們該怎么做呢?解決方法很簡單,也很人性化,那 是加載配置文件!!首先我們需要new一個Firefox的配置文件對象:FirefoxProfile,然后將我們需要的東西加入到這個文件對象中, 可以是一個插件,也可以是一個已經存在的配置文件:
  FirefoxProfile profile = new FirefoxProfile(); //創建一個Firefox的配置文件的對象
  {
  //創建需要添加的拓展或是配置文件的對象
  //將需要的拓展,已經存在的配置文件等添加到profile中,甚至是直接修改profile中的Firefox的各項參數
  }
  FirefoxDriver driver = new FirefoxDriver(profile); //以創建的profile配置文件對象啟動Firefox
  啟動時加載某個特定的插件,例如Firebug
  public void startFirefoxWithPlug(){
  File plugFile = new File("file/Firebug_2.0.12.xpi");
  FirefoxProfile profile = new FirefoxProfile();
  try {
  profile.addExtension(plugFile);
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  driver = new FirefoxDriver(profile);
  System.out.println("startFirefoxWithPlug.");
  }
  啟動時加載默認的本地配置文件,加載默認的本地配置文件時,需要首先初始化一個配置文件:default
  public void startFirefoxWithProfile(){
  ProfilesIni profiles = new ProfilesIni();
  FirefoxProfile profile = new FirefoxProfile();
  profile = profiles.getProfile("default");
  driver = new FirefoxDriver(profile);
  System.out.println("startFirefoxWithProfile.");
  }
  啟動時加載其他的配置文件:
  public void startFirefoxWithOtherProfile(){
  File profileDir = new File("Profiles/34t8j0sz.default");
  FirefoxProfile profile = new FirefoxProfile(profileDir);
  driver = new FirefoxDriver(profile);
  }
  啟動時設置瀏覽器的參數,以設置代理為例:
  public void setProxyOfFirefox(){
  FirefoxProfile profile = new FirefoxProfile();
  profile.setPreference("network.proxy.type", 1);
  profile.setPreference("network.proxy.http", "proxyIp");
  profile.setPreference("network.proxy.http_port", "proxyPort");
  driver = new FirefoxDriver(profile);
  System.out.println("setDownloadDirOfFirefox.");
  }
  這段代碼里的setPreference方法用于設置瀏覽器的參數,network.proxy.type則是Firefox中的配置代理相對應的字段,這些字段可以在Firefox中的about:config中看到;
  其實設置Firefox的啟動很簡單,只要記住Firefox啟動的各種場景都是圍繞這配置文件(profile)來設置的,這么一來不需要去死記那么多的代碼,了然于心自然會了。

軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 亚洲视屏在线观看 | 亚洲一区免费在线观看 | 国产精品久久久久久免费 | 国内自拍欧美 | 精品视频一区二区三三区四区 | 中文字幕一区中文亚洲 | 久艹在线观看 | 青青草国产精品欧美成人 | caopren免费视频国产 | 最近最好看2019年中文字幕 | 国产麻豆福利a v在线播放 | 看成年女人免费午夜视频 | 国产欧美日韩一区二区三区 | 操操干干 | 国产在线a不卡免费视频 | 狠狠色噜狠狠狠狠色综合久 | 欧美日本一本线在线观看 | 在线观看久草 | 亚洲tube | 天天色综合天天 | 国产精品黄在线观看免费网站 | 精品视频在线免费 | 国产成人爱片免费观看视频 | 国产一区二区三区在线观看免费 | 亚洲中文毛片播九公社 | 在线久色| 日本黄色二级片 | 国产精品tv| 日本黄色片网址 | 午夜影视大全 | h片在线播放免费高清 | 亚洲欧洲在线视频 | 国产aaaaaa | 黄色毛片视频免费 | 1024香蕉国产在线视频 | 国产成人精品日本亚洲网站 | 欧美日韩中文字幕在线观看 | 久久成人网18网站 | 中文国产成人精品久久无广告 | 永久免费视频网站在线观看 | 久久青草免费免费91线频观看 |