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