使用 WatiN 使 IE 会话过期
我正在尝试使用 WatiN 编写验收测试,该测试检查用户在会话超时后导航到页面时是否会重定向到登录页面。我正在使用 WatiN 的 IE
浏览器类,并尝试以下操作:
// 1. Login
// 2. Do this:
Browser.ClearCookies();
Browser.ClearCache();
// 3. Navigate to a different page
但用户始终仍处于登录状态。其他信息:
- 运行的 NUnit GUI 运行测试
- 我正在通过以管理员身份 一个 ASP.NET MVC 3 站点,使用表单身份验证和进程内会话状态
- 我正在使用 IE9。
- 如果我手动清除 Chrome 中的所有 cookie,用户将注销
- 如果我手动清除 IE 中的所有 cookie,用户将保持登录状态
- 如果我调用
Browser.Eval("alert(document.cookie)");
在 IE 中,它会警告空字符串
鉴于上述情况,我假设这是 IE 的一个怪癖;我有什么想法可以解决它吗?
I'm trying to write an acceptance test using WatiN which checks that a user is redirected to the login page if they navigate to a page after their session times out. I'm using WatiN's IE
class for the browser, and trying the following:
// 1. Login
// 2. Do this:
Browser.ClearCookies();
Browser.ClearCache();
// 3. Navigate to a different page
But the user is always still logged in. Other info:
- I'm running the test through the NUnit GUI running as an administrator
- It's an ASP.NET MVC 3 site, using forms authentication and in-process session state
- I'm using IE9.
- If I manually clear all cookies in Chrome, the user is logged out
- If I manually clear all cookies in IE the user stays logged in
- If I call
Browser.Eval("alert(document.cookie)");
in IE it alerts an empty string
Given the above, I'm assuming this is a quirk with IE; any ideas how I can work around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这是由于 IE 处理会话的方式以及删除身份验证 cookie 造成的;我发现埋在 此博客,您可以通过让 WatiN 执行以下 JavaScript 来清除 IE 中的身份验证信息:
这有效!执行此行后,会话将被清除,下一页导航将重定向到登录屏幕。
It turns out this is due to the way IE deals with sessions and the deletion of authentication cookies; I found buried in this blog that you can clear authentication information in IE by making WatiN execute the following JavaScript:
This works! After this line executes the session is cleared and the next page navigation redirects to the login screen.
我环顾四周,发现了这个页面: http ://fwdnug.com/blogs/ddodgen/archive/2008/07/03/watin-api-clearcookies.aspx
本质上说WaTiN无权删除IE内的cookie,因此ClearCookies方法不起作用。我只是将您的身份验证 cookie(我认为默认值是 ASP.NET_SessionId)设置为空,看看是否有效。
I looked around a bit and found this page: http://fwdnug.com/blogs/ddodgen/archive/2008/07/03/watin-api-clearcookies.aspx
Essentially says that WaTiN doesn't have the rights to delete cookies within IE, so the ClearCookies method doesn't work. I'd just set your auth cookie(s) (I think the default is ASP.NET_SessionId) to empty and see if that works.