使用 JUnit 和 Selenium-RC 以编程方式设置凭据
我必须使用硒测试应用程序。应用程序本身根据活动目录服务器进行身份验证。所有用户帐户的格式均为“[email protected]”。我必须使用使用 selenium java 客户端库的 Java JUnit (4.x) 测试。
不幸的是,我无法将用户名和密码直接设置到网址中。据我所知,@ 符号必须在 url 中进行编码。
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://username%64domain.tld:password@server/appbase");
我得到的只是一些授权异常:
com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://username%64domain.tld:password@server/appbase/mapage Response_Code = 401 Error_Message = Unauthorized
是否有任何方法可以在 url 中设置用户凭据(对于具有给定命名方案的用户)?是否有其他方法以编程方式向用户提供凭据?
预先感谢您的任何答复
问候,Marco
I have to test an application using selenium. The application itself authenticates against an active directory server. All user accounts are of the form "[email protected]". I have to use Java JUnit (4.x) tests that are using the selenium java client libs.
Unfortunately I'm not able to set the username and password directly into the url. As far as I know the @ sign has to be encoded within the url.
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://username%64domain.tld:password@server/appbase");
All I get is some authorization exceptions:
com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://username%64domain.tld:password@server/appbase/mapage Response_Code = 401 Error_Message = Unauthorized
Is there any way to set the user credentials (for a user with the given naming scheme) within the url? Are there other ways to give the user credentials programatically?
Thanks in advance for any answer(s)
Regards, Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近研究了使用 Selenium 进行身份验证,并了解到由于安全原因,大多数浏览器中不推荐使用这样的 url 身份验证。
我们的解决方案(运行 selenium rc 1.0.3)是在 user-extensions.js 中编写一个函数来查找登录控件(使用类名),如果找到,则插入 id 和密码并登录。这当然取决于使用表单身份验证,因此请求链是:
再次翻页
——
I looked into doing authentication with Selenium recently and learned that url authentication like that is deprecated in most browsers due to security reasons.
Our solution (running selenium rc 1.0.3) was to write a function in user-extensions.js that looked for a login control (using a class name) and if it's found, inserts the id and password and logs in. This of course depends on using Forms authentication, so that the request chain is:
page again
-
Magomi,
我们最近偶然发现了同样的问题(包括用户名是电子邮件地址以及对它们进行编码的需要);
所描述的解决方案:
http://wiki.openqa.org /display/SEL/Selenium+Core+FAQ#SeleniumCoreFAQ-HowdoIuseSeleniumtologintositesthatrequireHTTPbasicauthentication%28wherethebrowsermakeamodaldialogaskingforcredentials%29%3F
基本上是正确的,但它有点缺乏一些细节,因此您的方法失败了。
我们通过以下方式使其工作:(按照您的示例):
a) 配置/设置:只有 selenium 基本 url,没有凭据
b) 使用以下命令启动所有测试:
打开
http://username%64domain.tld:password@server/appbase
从那时起 Selenium (实际上是当前会话中的浏览器)将发送所有后续请求,包括上述凭据,并且您的 AUT 会感觉良好;-)
问候 georg
PS:在 Selenium-IDE 中使用上述方法仍然需要您单击弹出窗口;然而,这个弹出窗口对于最新的 Selenium-RC 来说是没有问题的
Magomi,
We recently stumbled across the same issue (including usernames being email-addresses and the need for encoding them);
The described solution:
http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ#SeleniumCoreFAQ-HowdoIuseSeleniumtologintositesthatrequireHTTPbasicauthentication%28wherethebrowsermakesamodaldialogaskingforcredentials%29%3F
is principally correct, however it kinda lacks some detail, thus your approach failed.
We got it working by: (following your example):
a) config/setup: only the selenium base url without credentials
b) start all tests with the following command:
open
http://username%64domain.tld:password@server/appbase
From then onwards Selenium (actually the Browser within it's current session) will send all subsequents requests including the above credentials and your AUT will feel fine ;-)
regards georg
PS: Using the above method in Selenium-IDE will still require you to click a pop-up; this pop-up however is no problem withing the latest Selenium-RC