Firefox 中通过 URL 的 HTTP 基本身份验证不起作用? [英] HTTP Basic Auth via URL in Firefox does not work?

查看:12
本文介绍了Firefox 中通过 URL 的 HTTP 基本身份验证不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道通常您可以通过在 URL 中传递用户名和密码来登录需要使用 Selenium 进行 HTTP 基本身份验证的站点,例如:

I know that normally you can login to sites that require HTTP basic authentication with Selenium by passing the username and password in the URL, e.g.:

selenium.open("http://myusername:myuserpassword@mydomain.com/mypath");

我一直在使用 Firefox 2 或 3 运行 Selenium 测试,但仍然出现需要身份验证"对话框窗口?

I've been running a Selenium test with Firefox 2 or 3 and there I still get the "Authentication Required" dialog window?

更新:这似乎不是 Selenium 的问题,而是 Firefox 的问题.如果我在 FF 中手动输入 URL,我会看到身份验证对话框,但如果我在 Opera 中输入 URL,我的页面将显示而不显示身份验证对话框.

Update: It seems not to be a Selenium problem but rather a Firefox issue. If I enter the URL manually within FF I'll get the authentication dialog, but if I enter the URL in Opera, my page is displayed without showing an authentication dialog.

推荐答案

为 Druska 的答案做出贡献,您可以使用 Selenium 2 API 进行相同的配置:

Contributing to Druska´s answer, you can do the same configuration using Selenium 2 API:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
profile.setPreference("network.automatic-ntlm-auth.trusted-uris","yourDomain");
new FirefoxDriver(profile);

这种方法更简单,您不必要求每个开发人员更改他们的 Firefox 配置.我只测试了 Firefox 驱动程序.

This approach is simpler and you do not have to ask every developer to change their Firefox configuration. I only tested with the Firefox driver.

更新:

出于某种原因(可能在 https://stackoverflow.com/a/14348701/256245 中解释的那些),上述解决方案不适用于较新版本的 Firefox.这是现在对我有用的方法(使用 Firefox 19.0.2 测试):

For some reason (maybe the ones explained at https://stackoverflow.com/a/14348701/256245), the above solution does not work with newer versions of Firefox. Here is what works for me now (tested with Firefox 19.0.2):

  1. 安装AutoAuth Firefox 插件;
  2. 访问需要进行身份验证的站点.输入您的用户名和密码,并确保选择保存凭据;
  3. 在您的硬盘上保存 AutoAuth 安装文件:在插件页面,右键单击添加到 Firefox"和将链接另存为";
  4. 按如下方式实例化 Firefox 网络驱动程序:

  1. Install AutoAuth Firefox plugin;
  2. Visit the site where the authentication is needed. Enter your username and password and make sure to choose to save the credentials;
  3. Save AutoAuth installation file at your hard drive: at the plugin page, right click at "Add to Firefox" and "Save link as";
  4. Instantiate Firefox webdriver as following:

FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
return new FirefoxDriver(firefoxProfile);

确保使用您保存插件安装的正确路径实例化 pluginAutoAuth 文件.如果您不喜欢使用默认配置文件,您可以使用 Firefox 配置文件管理器并创建一个特定于您的测试的配置文件.

Make sure to instantiate the pluginAutoAuth File with the correct path where you saved the plugin installation. If you do not feel comfortable using the default profile, you can use Firefox Profile Manager and create one specific to your tests.

参考这个新的解决方案:http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/

Reference to this new solution: http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/

这篇关于Firefox 中通过 URL 的 HTTP 基本身份验证不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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