问题
Every link I've found about cookies in JMeter is based on cookie manager. But unfortunately, JMeter losts cookies if path is changed, and I can't change JMeter properties to use solutions about that, so I have to use setting variable by JSR223 PostProcessor after request.
But I can't find any information about that - every link is about using HTTP Cookie Manager.
Please help with solution WITHOUT Cookie Manager.
回答1:
blazemeter has a good examples about creating cookies in JSR223
import org.apache.jmeter.protocol.http.control.* //Get cookie manager CookieManager cm = sampler.getCookieManager() //Set cookie currency to EUR cm.addFile("C:/work/jmeter-scripts-samples/cookie.txt")
The method CookieManager.addFile(String cookieFile) adds the cookie defined in the cookieFile parameter (cookie.txt in this example) to the cookie manager.
We will create a cookie by adding the following line to the PreProcessor script:
Cookie c = new Cookie("sampleCookie", "sample", "opencart.abstracta.us", "/", false, 1557578515)
回答2:
First of all described situation sounds very weird, JMeter should be able to parse the cookies given:
- The cookies are valid (fully compliant with RFC 6265)
- HTTP Request sampler has proper configuration (domain matches cookie domain, path matches cookie path, etc.)
If you're absolutely sure that your application is doing what it is supposed to be doing (including setting invalid cookies) you can work this around by making HTTP Cookie Manager less restrictive by:
Adding the next line to user.properties file:
CookieManager.check.cookies=false
Using another
Cookie Policy
, i.e. netscape
As you can see even given Domain
and Path
are blank JMeter still adds the cookie to the request:
More information: HTTP Cookie Manager Advanced Usage - A Guide
In any case you should be able to extract cookies from the Set-Cookie header using Regular Expression Extractor and add it to the requests as it is described above.
来源:https://stackoverflow.com/questions/58910036/jmeter-jsr223-postprocessor-get-cookie