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();

      }

    }

  • 相关阅读:
    python出现local variable 'f' referenced before assiginment""
    使用Python修改ifcfg-eth0文件
    在linux中运行py文件时,及时知道错误信息
    分词结果准确率、召回率计算-python
    oozie工作流
    combiner hadoop
    Python常用模块--base64
    Python常用模块--datetime
    树莓派(Raspbian系统)中使用pyinstaller封装Python代码为可执行程序
    LeetCode刷题笔记--Python--28. 实现strStr()
  • 原文地址:https://www.cnblogs.com/feifeidxl/p/4538556.html
Copyright © 2011-2022 走看看