Class VirtualUser
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
Synopsis
public class VirtualUser {
// Public Fields
public String id ;
public String name ;
// Public Methods
public 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();
}id
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
name
public String name ;The Virtual User name (e.g. "User1")
clearCache()
public void clearCache();Deletes all cache information for the Virtual User instance.
clearCookies()
public void clearCookies();Deletes all cookies for the Virtual User instance.
clearRuntimeVariables()
public void clearRuntimeVariables();Deletes all runtime variables for the Virtual User instance.
closeConnections()
public void closeConnections();Closes all the open connections to servers for the Virtual User instance (HTTP, HTTPS, websockets, RTMP).
get(Object)
public Object get(Object key);Parameters
- key
the key whose associated value is to be returned- return
the value to which the specified key is mapped, or null if the current Virtual User instance contains no mapping for the key.Returns the value to which the specified key is mapped, or null if there is no mapping for the key.
getCurrentIteration()
public int getCurrentIteration();Parameters
- return
The value 0 when the current runtime status is INIT or END.
The integer of the current iteration runtime when the Container is Actions.Returns the current instance number of a Virtual User runtime loop.
getCurrentStep()
public String getCurrentStep();Parameters
- return
The returned values can be:
- INIT
- ACTIONS
- END
Returns the current runtime step label for the Virtual User instance.
getElapsedTime()
public long getElapsedTime();Parameters
- return
the difference, measured in milliseconds, between the current time and the Virtual User start time.Returns the elapsed time in milliseconds since this Virtual User started.
getPopulationName()
public String getPopulationName();Parameters
- return
the name of the Population.Returns the name of the Population containing this Virtual User.
goToNextIteration()
public void goToNextIteration();Switches to the next iteration of the current runtime for the Virtual User instance.
put(Object, Object)
public void put(Object key,
Object value);Parameters
- key
key with which the specified value is to be associated- value
value to be associated with the specified keyStores a user-defined object in the Virtual User instance. It associates the specified value with the specified key.
remove(Object)
public Object remove(Object key);Parameters
- key
the key whose associated value is to be returned- return
the value to which the specified key is mapped, or null if the current Virtual User instance contains no mapping for the key.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.
setCookieForServer(String, String)
public void setCookieForServer(String serverName,
String cookie);Parameters
- serverName
the NeoLoad name of the server.- cookie
the cookie stringSets 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=/".
The name=value is mandatory, other information is optional.
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 msvar 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);
- Warning: The serverName parameters design the NeoLoad name of the server, not the physical one. Check you server names in the repository panel of NeoLoad.
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);stop()
@Deprecated public void stop();
Home