zoukankan      html  css  js  c++  java
  • [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();

      }

    }

  • 相关阅读:
    CATIA 各个版本代号详解
    CATIA 基础详解 第01章 CATIA初认识
    CATIA 使用技巧--转换出轻巧的tif格式文件
    中国水墨动画系列 内容简介
    Python开发 第02课 Python 数据类型
    Python开发 第01课 Python 简介
    UG 常用设置
    matplotlib 学习笔记02:marker标记详解
    matplotlib 知识点13:绘制散点图(scatter函数精讲)
    matplotlib 知识点11:绘制饼图(pie 函数精讲)
  • 原文地址:https://www.cnblogs.com/feifeidxl/p/4538556.html
Copyright © 2011-2022 走看看