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

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

问题描述

我在 Java 中使用 Selenium Web Driver API.每次我想调试我的测试用例时,都会在临时文件目录中为 Firefox 创建一个临时配置文件.这在两个方面都令人头疼.

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. 创建配置文件肯定会花费不必要的时间并占用不必要的空间.
  2. 我无法安装下次启动测试用例时可用的任何插件.

我该如何解决这个问题?

How do I get around this?

推荐答案

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

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.

例如:

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

更新 - 来自 Ranhiru

我是如何处理 Java 的

How I handled it for Java

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

然后我更改了 Firefox 中的设置以在退出时清除所有 cookie 和缓存.查看此处了解如何操作.

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天全站免登陆