背景介绍:
该站点是使用window ntlm身份也就是所谓的微软的域账户登录,当输入URL之后会自动弹出提示框,要求用户输入域账户用户和密码进行登录。与form登录不一样,所以在项目过程中通常会遇到这个问题,为了解决这个问题查询了很多资料,经过实践,最终测试步骤总结出来,分享给大家,如果有疑问可以留言。
演示站点
测试window身份认证的站点
设置Jmeter组件
组件如下:
1.Thread Group
2.HTTP Authorization Manager
3.HTTP Cookie Manager
4.HTTP REQUEST
5.HTTP REQUEST
设置HTTP Authorization Manager
设置HTTP Authorization Manager时,需要输入UserName和Passwor,这两个字段的值就是域账户登录名和密码,然后在Mechanism字段中选择BASIC_DIGEST。
设置HTTP Cookie Manager
在HTTP Cookie Manager中设置Cookie Policy为standard-strict
设置Http Request
设置Http Request的服务器地址,端口以及发送请求的方法,该url是访问站点入口。
设置Http Request
设置Http Request访问其他功能的页面。
添加View Results Tree
运行查看结果
运行后查看View Result Tree,查看运行后结果,显示成功。虽然是运行成功了,但是其中也有一些波折困扰了好久,最后还是解决了,以下是实践过程中遇到的问题。
Exceeded maximum number of redirects: 20
运行时多次出现一下异常信息:
java.io.IOException: Exceeded maximum number of redirects: 20
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:1572)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:1636)
at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.resultProcessing(HTTPAbstractImpl.java:525)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:536)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1189)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1178)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250)
at java.lang.Thread.run(Thread.java:745)
解决方法:
由于每次请求都需要带上Cookie,需要在Thread Group中添加一个Http Cookie Manager的管理可以解决该问题。
参考官方说明:
https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cookie_Manager
The Cookie Manager element has two functions:
First, it stores and sends cookies just like a web browser. If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site. Each JMeter thread has its own "cookie storage area". So, if you are testing a web site that uses a cookie for storing session information, each JMeter thread will have its own session. Note that such cookies do not appear on the Cookie Manager display, but they can be seen using the View Results Tree Listener.