是否可以将密码添加到作为 org.openqa.selenium.firefox.FirefoxProfile
实例创建的配置文件中? ?
从 Mozilla 文档 ( Profiles — Where Firefox stores your bookmarks, passwords and other user data ),我可以看到 Firefox 将密码存储在两个文件中:
- Passwords: Your passwords are stored in the key3.db and logins.json files. For more information, see Password Manager - Remember, delete, change and import saved passwords in Firefox.
但是在 FirefoxProfile
类中看不到任何方法来单独将密码添加到配置文件,或者传递像 logins.json/ 这样的文件key3.db。 (我在链接的 Mozilla 页面上也找不到任何内容,这些页面似乎以普通用户的身份存储密码,而不是以编程方式存储密码)
在我的 Selenium 测试套件中,我正在代码中动态创建一个 Firefox 配置文件,但我必须将密码(例如,对于开发服务器上的 HTTP Basic Auth)编码成这样的 URL:
http://user:pass@localhost/example.html
(我知道我可以创建一个完整的配置文件并将其添加到 Git,以便传递,但如果可以的话我想避免这种情况)
最佳答案
我通读了 selenium firefoxprofile code for v53.0并没有看到任何明显的东西。但是,您可以 copy those two files from the existing profile进入 selenium 创建的默认配置文件。您只需要新生成的默认 firefoxprofile 的位置,您可以在执行时(动态地)获取它:
FirefoxProfile profile = new FirefoxProfile();
System.out.println(">> path to profile=" + profile.layoutOnDisk().getAbsolutePath());
// Copy the two files
WebDriver driver = new FirefoxDriver(profile);
关于java - 是否可以在保存的密码中创建 Firefox 配置文件和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40584791/