如何阻止Selenium使用Web驱动程序创建临时的Firefox配置文件? [英] How to stop Selenium from creating temporary Firefox Profiles using Web Driver?

查看:132
本文介绍了如何阻止Selenium使用Web驱动程序创建临时的Firefox配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Web Driver API和Java。每次我想调试我的测试用例时,都会在临时文件目录中创建一个临时的Firefox配置文件。这是一个令人头疼的问题。


  1. 无疑,创建一个配置文件并占用不必要的空间是不必要的。

  2. 我无法安装下次启动测试用例时可用的任何插件。 解决这个问题?

    解决方案

    您可以控制Firefox驱动程序如何选择配置文件。将 webdriver.firefox.profile 属性设置为要使用的配置文件的名称。大多数人认为这是一个坏主意,因为你会继承所有的cookie,缓存内容,等等。以前使用的配置文件,但它是允许的,如果你真的想要做到这一点。



    例如:

      System.setProperty(webdriver.firefox.profile,MySeleniumProfile); 
    WebDriver driver = new FirefoxDriver(...);

    更新 - 从

    我是如何处理Java的

    pre> FirefoxProfile profile = new FirefoxProfile(new File(D:\\Selenium Profile));
    WebDriver driver = new FirefoxDriver(profile);

    然后,我改变了Firefox中的设置,以便在退出时清除所有Cookie和缓存。 此处介绍如何操作。


    I am using Selenium Web Driver API with Java. Every time I want to debug my test cases, a temporary profile for Firefox is created in the temporary files directory. This is a headache in two ways.

    1. It definitely is taking unnecessary time to create a profile and is taking unnecessary space.
    2. I cannot install any addons that will be available next time I launch my test cases.

    How do I get around this?

    解决方案

    You can control how the Firefox driver chooses the profile. Set the webdriver.firefox.profile property to the name of the profile you want to use. Most folks think this is a bad idea, because you'll inherit all the cookies, cache contents, etc. of the previous uses of the profile, but it's allowed if you really want to do it.

    For example:

    System.setProperty("webdriver.firefox.profile", "MySeleniumProfile");
    WebDriver driver = new FirefoxDriver(...);
    

    UPDATE - From Ranhiru

    How I handled it for Java

    FirefoxProfile profile = new FirefoxProfile(new File("D:\\Selenium Profile"));                  
    WebDriver driver = new FirefoxDriver(profile);
    

    Then I changed settings in Firefox to clear all cookies and cache when exiting. Look here on how to do it.

    这篇关于如何阻止Selenium使用Web驱动程序创建临时的Firefox配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆