如何在Selenium中获取HTTP状态码?
例如。所以我可以测试一下,如果浏览器请求/user/27并且不存在ID=27的用户,则返回HTTP 404?
我的主要兴趣是 Selenium RC,但如果有人知道“正常”selenium 的答案,我可能可以轻松地将其转换为 RC。
/Pete
对于此类测试,这可能不是 Selenium 的最佳用途。当您可以执行并进行更快的运行测试时,无需加载浏览器
[Test]
[ExpectedException(typeof(WebException), UserMessage = "The remote server returned an error: (404) Not Found")]
public void ShouldThrowA404()
{
HttpWebRequest task; //For Calling the page
HttpWebResponse taskresponse = null; //Response returned
task = (HttpWebRequest)WebRequest.Create("http://foo.bar/thiswontexistevenifiwishedonedayitwould.html");
taskresponse = (HttpWebResponse)task.GetResponse();
}
如果您的测试在 404 期间重定向到另一个页面,Selenium 可以检查最终页面是否符合您的预期。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)