The RuntimeSession class has access to the run-time session object that has access to request and response data. It contains the following properties and methods:


RuntimeSession Members
 /// <summary>
/// A replayed runtime session object.
/// </summary>
public class RuntimeSession
{
    /// <summary>
    /// The recorded session id.
    /// </summary>
    public int RecordedSession { get; }

    /// <summary>
    /// The recorded test case name.
    /// </summary>
    public string RecordedTestCase { get; }

    /// <summary>
    /// The current iteration number.
    /// </summary>
    public int IterationNumber { get; }

    /// <summary>
    /// The current request number in iteration.
    /// </summary>
    public int RequestNumber { get; }

    /// <summary>
    /// The VU number.
    /// </summary>
    public int VUNumber { get; }

    /// <summary>
    /// If currently in a loop, return the current loop index. Otherwise return -1.
    /// </summary>
    public int LoopIndex { get; }

    /// <summary>
    /// The extractor runtime object for the VU.
    /// </summary>
    public ExtractorRuntime ExtractorRuntime { get; }   
 
	/// <summary>
    /// Returns the data source with the given name.
    /// </summary>
    /// <param name="name">The name of the data set.</param>
    /// <returns>The DataTable object that represents the data set. Returns null if data source does not exist.</returns>
    public DataTable GetDatasource(string name);

	/// <summary>
    /// Returns the consumed row number for the given datasource in the current iteration.
    /// </summary>
    /// <param name="name">The name of the datasource.</param>
    /// <returns>The row number. Returns -1 if datasource is not found or has no rows.</returns>
	public int GetDatasourceRow(string name);

    /// <summary>
    /// Returns the given dataset cell value for the given column and the consumed row for the current iteration.
    /// </summary>
    /// <param name="name">The name of the datasource.</param>
    /// <param name="column">The name of the column in the datasource.</param>
    /// <returns>The cell value. Returns null if datasource or column is not found.</returns>
	public string GetDatasourceValue(string name, string column);

    /// <summary>
    /// Returns the current value of an iteration data generator. If the data generator is evalued on every request then a new value is generated. If the data generator doesn't exist then null is returned.
    /// </summary>
    /// <param name="name">The name of the data generator.</param>
    /// <returns></returns>
    public string GetDatageneratorValue(string name);

    /// <summary>
    /// Gets or sets the property whether the response is marked as an error.
    /// </summary>
    public bool IsError { get; set; }

    /// <summary>
    /// Custom error message for an error response.
    /// </summary>
    public string ErrorMessage { get; set; }

	/// <summary>
    /// If set to true before request is sent then cancel the request to the server.
    /// </summary>
    public bool CancelRequest { get; set; }

    /// <summary>
    /// The url.
    /// </summary>
    public Uri Url { get; }

    /// <summary>
    /// Get request headers.
    /// </summary>
    /// <returns>An enumerable list of request headers.</returns>
    public IEnumerable<NameValuePair> GetRequestHeaders();

    /// <summary>
    /// Gets a string representation of the request body.
    /// </summary>
    /// <returns>The string representation of the request body.</returns>
    public string GetRequestBody();

    /// <summary>
    /// Gets the raw request body.
    /// </summary>
    /// <returns>The byte[] representation of the request body.</returns>
    public byte[] GetRawRequestBody();

    /// <summary>
    /// Change or add a request header. Set the value to null to remove the header.
    /// </summary>
    /// <param name="name">The name of the request header.</param>
    /// <param name="value">The value of the request header.</param>
    public void SetRequestHeader(string name, string value);
    /// <summary>
    /// Change the request body.
    /// </summary>
    /// <param name="body">The byte[] of the new response body.</param>
    public void SetRequestBody(byte[] body);

    /// <summary>
    /// Returns the response code. If no response exists then returns 0.
    /// </summary>
    public int ResponseCode { get; }

    /// <summary>
    /// Returns the response status. If no response exists then returns null.
    /// </summary>
    public string ResponseStatus { get; }

    /// <summary>
    /// Get response headers.
    /// </summary>
    /// <returns>An enumerable list of response headers.</returns>
    public IEnumerable<NameValuePair> GetResponseHeaders();

    /// <summary>
    /// Gets a string representation of the response body.
    /// </summary>
    /// <returns>The string representation of the response body.</returns>
    public string GetResponseBody();

    /// <summary>
    /// Gets the raw request body.
    /// </summary>
    /// <returns>Returns the byte[] representation of the response body.</returns>
    public byte[] GetRawResponseBody();

	/// <summary>
	/// Set a string value to VU storage with a given key.
	/// </summary>
	/// <param name="key">The key name</param>
	/// <param name="value">The string value</param>
	public void SetValue(string key, string value);

	/// <summary>
	/// Get a value from VU storage with a given key.
	/// </summary>
	/// <param name="key">The key name</param>
	/// <returns>The value associated with the key</returns>
	public string GetValue(string key);

	/// <summary>
	/// Set an object to VU storage
	/// </summary>
	/// <param name="key">The key name</param>
	/// <param name="value">The object</param>
	public void SetObject(string key, object value);

	/// <summary>
	/// Get an object from VU storage
	/// </summary>
	/// <param name="key">The key name</param>
	/// <returns>The object associated with the key</returns>
	public object GetObject(string key)	;

    /// <summary>
    /// The the VU storage.
    /// </summary>
    public string ClearValues();

    /// <summary>
    /// Stop sending requests in the current iteration.
    /// </summary>
    /// <param name="failIteration">If true, the aborted iteration will count as a failure, otherwise it will count as a success.</param>
    public void AbortIteration(bool failIteration);

    /// <summary>
    /// Stops sending all requests and ignore all further responses from the current session's VU
    /// </summary>
    public void AbortVU();

    /// <summary>
    /// Aborts the test and stops all VUs from sending requests and ignores all further responses.
    /// </summary>
    public void AbortTest();

}
/// <summary>
/// Name/value pair representation.
/// </summary>
public class NameValuePair
{
    /// <summary>
    /// The name.
    /// </summary>
    public string Name { get; }
    /// <summary>
    /// The value.
    /// </summary>
    public string Value { get; }
}
  • No labels