Selenium 2 Firefox Profile Change Location

[亡魂溺海] 提交于 2020-01-13 04:42:16

问题


For many weeks now, I have been looking around and I have not seen anything regards to changing the location the Firefox Profile saves to.

I am using a specific Firefox profile, however, when the tests run the session is created in /tmp/. I would like the session to start up in a different location and save the files it uses in a location like: /var/tmp/. Is there any way to do this?

Note: This is not a question as to where I get the RemoteWebDriver to use a specific Firefox profile.

Edit: I am using Selenium 2.28 and Firefox 15.0.1


回答1:


Look at FirefoxProfile:442

File profileDir = TemporaryFilesystem.getDefaultTmpFS()
          .createTempDir("anonymous", "webdriver-profile");
copyModel(model, profileDir);

The TemporaryFilesystem takes it's location from "java.io.tmpdir":, which usually points to system's temp directory. Santoshsarma's solution will work because of this line (but it will also move your OS temp directory).

private static File sysTemp = new File(System.getProperty("java.io.tmpdir"));

We can do more! Look at the public method setTemporaryDirectory!

You can invoke this method just before instantiating your FirefoxDriver and it should create it's profile copy at the location you specified.




回答2:


Firefox uses the OS temp file location for storing temporary files

You need to change the location of the temp files in Windows in the control Panel if you want to use another location for temp files.

You can change the %TEMP% and %TMP% environment variables and make them point to a temp folder that you want to use.

Control Panel > System > Advanced > Environment variables

Refer : Firefox Support



来源:https://stackoverflow.com/questions/15124772/selenium-2-firefox-profile-change-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!