FirefoxProfile 用于定制待测试的Firefox 浏览器的特定属性,其中包括所存储的密码、书签、历史信息、Cookies等。某些测试用例需要用到特定的用户信息,因此可通过定制当前Firefox 运行实例的FirefoxProfile 来达到目标

1)如果需要查看当前Firefox 运行实例的FirefoxProfile, 可通过Help->Troubleshooting Information->Profile Folder来获取

2)如果希望在Firefox 启动的时候已经加载某个插件,可通过addExtension 提前加载以.xpi 为扩展名的插件

3)如果希望Firefox 以某些特定偏好设置启动,可通过setPreference 达到目的

4)如果希望Firefox 对SSL 证书的处理机制进行调整,可通过 setAssumeUntrustedCertificatelssur 和 setAcceptUntrustedCertificates 达到目的

5)如果希望将FirefoxProfile 导出成 JSON 格式,可通过toJson 来处理

示例代码如下:

public class testFirefoxProfile{

  public static void main(String[] args){

    String prodileInJson = " ";

    FirefoxProfile profile = new FirefoxProfile();

    try{

      profile.addExtension(new File("/path/to/extension.xpi"));

      profile.setPreference("browser.startup.homepage", "about:blank");

      profile.setAssumeUntrustedCertificatelssuer(false);

      profile.setAcceptUntrustedCertificates(false);

      profileInJson = profile.toJson();

      System.out.println(profileInJson);

    }catch(IOException e){

      e.printStackTrace();

    }

    WebDriver driver = new FirefoxDriver(profile);

    driver.get("http://www.baidu.com");

    driver.close();

  }

}

最新文章

  1. 使用Angularjs的ng-cloak指令避免页面乱码
  2. IIS启动网站出错的几个解决方法
  3. 根据List中对象的某一属性进行排序
  4. Intellij IDEA 使用Spring-boot-devTools无效解决办法
  5. php数组排序函数
  6. 【转】android 安卓APP获取手机设备信息和手机号码的代码示例
  7. C++关于编译器合成的默认构造函数
  8. 武汉科技大学ACM :1005: A+B for Input-Output Practice (V)
  9. HTML 表格入门
  10. ORA-01092 ORA-12432: LBAC error: zllegnp:OCIStmtExecute 故障一例
  11. Struts2 Spring3 Hibernate3 集成xml版本
  12. ●BZOJ 1416 [NOI2006]神奇的口袋
  13. JDBC详解(汇总)
  14. STM32L1X系列GPIO运用
  15. [NOI2018]屠龙勇士
  16. 前端JS基础知识
  17. 注册Docker官网账号 注册按钮不能点
  18. TRIO-basic指令--FLEXLINK
  19. EditPlus查找替换
  20. VS2010,VS2012,VS2013中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法

热门文章

  1. VirtualBox 5.0.10 中 Fedora 23 在安装了增强工具后无法自动调节虚拟机分辨率的问题(改)
  2. SQL Server 命令行操作
  3. android调用 .net webService
  4. 洛谷——P2690 接苹果
  5. LCA rmq st model
  6. 网络安全(超级详细)零基础带你一步一步走进缓冲区溢出漏洞和shellcode编写!
  7. HDC与CDC相互转换
  8. keras常见问题解答
  9. git 更新远程分支
  10. [Oracle] 获取运行计划的各方法总结