Cookie Jmeter obtain and pass on to the next thread

Jmeter is a testing tool will be used in the testing process, we can be used to measure the pressure of the press can also be used to interface function test, the result is not just HTTP, as well as DB, TCP, FTP, etc. . Of course, it also has many other useful features, such as a proxy server, mirror server, telnet, and so on. Today, its main talking Cookie Manager, because when using this feature stepped on a pit, but could not find other carded.

When Cookie Jmeter where access to HTTP Cookie manager need to use assembly elements disposed at the specific location of the list, as shown below:

Usually we are in a thread's Sampler added, because each thread should have its own has a Cookie Manager, after successfully added Jmeter the Cookie Manager interface are as follows:

The above operation Cookie FIG main memory, we added directly JSESSIONID of a cookie, the specific values ​​are taken from a variable; Note that the domain, the path need to fill, particularly the domain; current version as default Jmeter cross-domain request is not supported, Cookie not fill will not be provided if the belt.

The next step is to take the operation of Cookie, Cookie is usually taken from the Response Header taken in, the purpose is generally to take a different thread to use, because if it is the case with a thread of different iterations of it Jmeter will automatically bring, we do not need to set. That step taken away cookie, what does?

First, we need to modify the file jmeter.properties
find CookieManager.save.cookies = true set to true and
restart jmeter save the configuration file
to add a Http Cookie Manager threads need to take Cookie's
can is empty by default, but be sure to add, otherwise it is not will store a cookie variable
through the operation of the above steps, then we thread of execution, to get the cookie will be stored in the thread variable, the variable name specific format COOKIE_xxxx, where xxxx is the specific name of the actual cookie; so other operations within the same thread are components can be directly obtained by the $ {COOKIE_xxxx}

prompt:

The document said cookie variable is valid within the thread, external thread invalid, but the actual test thread with a group of other threads are directly accessible

If this is the case across the thread group, we can also have other ways to share cookie variables, most convenient way below this

import org.apache.jmeter.util.JMeterUtils;
String value = JMeterUtils.getPropDefault("name","");
JMeterUtils.setProperty("name", "value");
另一种是下面的方式,
if (bsh.shared.myObj == void){
    // not yet defined, so create it:
    myObj = new AnyObject();
}
bsh.shared.myObj.process();

Because it can directly take the test to be no original content from the official website of the document, http: //jmeter.apache.org/usermanual/best-practices.html, and I stepped in to take the pit is not the time to add a cookie empty http cookie manager, and tried some other way invalid shared variable.
----------------
Disclaimer: This article is CSDN blogger "God De assistant" in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/five3/article/details/53842283

Published 91 original articles · won praise 47 · views 90000 +

Guess you like

Origin blog.csdn.net/qq_30007885/article/details/103732019