如何在 Selenium WebDriver 中对 FirefoxDriver、ChromeDriver 和 IEdriver 执行基本身份验证? [英] How to perform Basic Authentication for FirefoxDriver, ChromeDriver and IEdriver in Selenium WebDriver?
问题描述
我正在使用 Selenium-Firefox-driver 和 Selenium-Chrome-Driver 2.0a5 版(Web Driver API),并且我我正在尝试测试具有 BASIC 身份验证的 Web 应用程序(当我点击任何页面时,会出现一个弹出窗口来验证用户,该弹出窗口不是 HTML 的一部分).
I am using the Selenium-Firefox-driver and Selenium-Chrome-Driver version 2.0a5 (Web Driver API), and I am trying to test a web app that has BASIC authentication (there is a popup that come up to authenticate the user when I hit whatever page, the popup is not part of the HTML).
现在,我需要一个策略来验证 Firefox、Chrome 和 IE 中的用户(我将很快导入 IE 驱动程序).
Now, I need to a strategy to authenticate the user in Firefox, Chrome and IE (I'm going to import the IE Driver soon).
我在几篇文章中读到了我可以设置 Firefox 配置文件的内容,例如:
I was reading in few articles that I can set a Firefox profile for instance..something like:
FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.setPreference("network.http.phishy-userpass-length", 255);
WebDriver driver = new FirefoxDriver(ffProfile);
driver.get("http://username:password@hostname");
但它似乎对我不起作用.有没有人有适用于这些浏览器的可行解决方案?
but it doesn't seem to work for me. Does anyone have a working solution for those browsers?
推荐答案
是的,目前不支持 BASIC HTTP 身份验证,但我现在让它适用于 FF 和 Chrome.
True, BASIC HTTP authentication is not currently supported but I got it working now for FF and for Chrome.
我在问题中编写的代码适用于这些驱动程序.我只是尝试使用 FF3.6 作为 Firefox 默认浏览器(安装在 Firefox 文件夹中)而不是 FF4(尚不支持).对于 IE,我可能会尝试通过 Windows 注册表禁用身份验证.
The code I wrote in the questions works for those drivers. I just tried using FF3.6 as Firefox default browser (installed in Firefox folder) instead of FF4 (not supported yet). For IE, i may try to disable the authentication through Windows Registry.
此页面 http://code.google.com/p/selenium/issues/detail?id=34 可能会有所帮助.
This page http://code.google.com/p/selenium/issues/detail?id=34 may help.
这篇关于如何在 Selenium WebDriver 中对 FirefoxDriver、ChromeDriver 和 IEdriver 执行基本身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!