VirtualUser represents a Virtual User instance.
Typically, you have several instances of a Virtual User running at the same time.
Usually, for debugging purpose, you can get the id of the current Virtual User (e.g. "UserA#3") with context.currentVU.id
public class VirtualUser {
// Public Fieldspublic String id ;
public String name ;
// Public Methodspublic void clearCookies();
public void clearRuntimeVariables();
public Object get(Object key);
public int getCurrentIteration();
public String getCurrentStep();
public long getElapsedTime();
public String getPopulationName();
public void goToNextIteration();
public void put(Object key,
Object value);
public Object remove(Object key);
public void setCookieForServer(String serverName,
String cookie);
@Deprecated public void stop();
}
public String id ;
The id of the Virtual User (e.g. "User1#3"). This id is only valid if the Virtual User is context.currentVU. In all other cases, this id will be null
public String name ;
The Virtual User name (e.g. "User1")
public void clearCache();
Deletes all cache information for the Virtual User instance.
public void clearCookies();
Deletes all cookies for the Virtual User instance.
public void clearRuntimeVariables();
Deletes all runtime variables for the Virtual User instance.
public void closeConnections();
Closes all the open connections to servers for the Virtual User instance (HTTP, HTTPS, websockets, RTMP).
public Object get(Object key);
Parameters
key
return
Returns the value to which the specified key is mapped, or null if there is no mapping for the key.
public int getCurrentIteration();
Parameters
return
0
when the current runtime status is INIT
or END
.Actions
.Returns the current instance number of a Virtual User runtime loop.
public String getCurrentStep();
Parameters
return
INIT
ACTIONS
END
Returns the current runtime step label for the Virtual User instance.
public long getElapsedTime();
Parameters
return
Returns the elapsed time in milliseconds since this Virtual User started.
public String getPopulationName();
Parameters
return
Returns the name of the Population containing this Virtual User.
public void goToNextIteration();
Switches to the next iteration of the current runtime for the Virtual User instance.
public void put(Object key,
Object value);
Parameters
key
value
Stores a user-defined object in the Virtual User instance. It associates the specified value with the specified key.
public Object remove(Object key);
Parameters
key
return
Removes the mapping for a key if it is present.
Returns the value previously associated with the key, or null
if there is no mapping for the key.
public void setCookieForServer(String serverName,
String cookie);
Parameters
serverName
cookie
Sets a cookie for the Virtual User instance. The cookie is associated with the specified server so that the cookie will be sent in all following requests to the specified server according to the cookies settings: the cookie will be sent if the cookie path matches the request path and if the expiration date is not reached.
The cookie must have the standard format: e.g. "name=value; expires=Thu, 2 Aug 2007 20:47:11 UTC; path=/".
Example:
Sets a cookie that expires in 7 days, and that will be sent in requests which paths are under /app on the server jack_80
var today = new Date();
var oneDay = 1000 * 60 * 60 * 24; // 24H in ms
var expires = 7 * oneDay;
var expires_date = new Date(today.getTime()+expires);
var cookie = "username=John; expires=" + expires_date.toGMTString() +"; \
path=/app";
context.currentVU.setCookieForServer("jack_80",cookie);
To clear a cookie
Set a cookie with an expired date to remove the cookie for the Virtual User instance. Note that the cookie header should be removed from the request headers of the appropriate requests in the repository: the requests that come after the Javascript and which URL match the server and path of the cookie.
Example:
var expires_date = new Date(0);
var cookie = "username=John; expires=" + expires_date.toGMTString() +"; \
path=/app";
context.currentVU.setCookieForServer("jack_80",cookie);
@Deprecated public void stop();