Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can further extend StresStimulus run-time by creating an external component.  An external component traps StresStimulus run-time events to extend its functionality. Components can be created by writing .NET code. Once created, they are displayed in the Component section of the workflow tree (a). 


To create

...

a component inside StresStimulus,

...

  1. Using a .NET IDE of your choice, create a new class library project.
  2. Add a reference to the StresStimulus.Core.dll to your project. This .dll is located in the StresStimulus installation directory. If you are running tests using StresStimulus Fiddler Addon version, reference the StresStimulus.Core.Fiddler.dll instead
  3. Create a class and implement the StresStimulus.Extensibility.IExternalComponent interface.
  4. Compile the .dll and copy it into the bin subfolder in the test folder. For example, for the test MyTest.ssconfig, copy the .dll to MyTest\bin folder.

The StresStimulus.Extensibility.IExternalComponent2 interface has the following interface definition:  

Code Block
firstline1
titleIExternalComponent Members
linenumberstrue
/// <summary>
/// Interface to handle test events. Must have a no argument - constructor.
/// </summary>
public interface IExternalComponent2
{
    /// <summary>
    /// Fired when test started.
    /// </summary>
    void OnTestStart();
    /// <summary>
    /// Fired when test ends.
    /// </summary>
    void OnTestEnd();
    /// <summary>
    /// Returns true if OnBeforeRequest, OnBeforeResponse, OnAfterResponse will be invoked for all sessions in the test. Return false if those methods will be invoked only for specified sessions.
    /// </summary>
    bool InvokeForAllSessions { get; }
    /// <summary>
    /// Fired before a request is sent.
    /// </summary>
    /// <param name="session">The session object</param>
    void OnBeforeRequest(RuntimeSession session);
    /// <summary>
    /// Fired after a response is received but before processed.
    /// </summary>
    /// <param name="session">The session object</param>
    void OnBeforeResponse(RuntimeSession session);
    /// <summary>
    /// Fired after a response is received.
    /// </summary>
    /// <param name="session">The session object</param>
    void OnAfterResponse(RuntimeSession session);
    /// <summary>
    /// Fired after iteration is complete
    /// </summary>
    /// <param name="vu">The vu object</param>
    void OnAfterIteration(RuntimeVU vu);
}
  • OnTestStart(): Use this method initialize any test specific objects that will be used during the test, or to run any pre-test script (such as cleaning previously created database records).
  • OnTestEnd(): Use this method to clean up any objects used during the test or run any post-test script.
  • OnBeforeRequest(): This is called before a request is sent. It receives an instance of RuntimeSession object that can be used to customize the request headers and body. This method is called after all parameters have been applied to the request.
  • OnBeforeResponse(): This is called after a response is received but before it can be processed by StresStimulus. It receives an instance of RuntimeSession object to read the response headers and body for further automation.
  • OnAfterResponse(): This is called after a response is received. It receives an instance of RuntimeSession object to read the response headers and body for further automation.
  • OnAfterIteration(): This is called after an iteration is complete. It receives an instance of RuntimeVU object to read the VU properties.

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:

Code Block
firstline1
titleRuntimeSession Members
linenumberstrue
 /// <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>
    /// 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>
    /// 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>
    /// 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.
    /// </summary>
    public int ResponseCode;
    /// <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>
/// Name/value pair representation.
/// </summary>
public class NameValuePair
{
    /// <summary>
    /// The name.
    /// </summary>
    public string Name { get; }
    /// <summary>
    /// The value.
    /// </summary>
    public string Value { get; }
}

...

Code Block
languagec#
firstline1
titleRuntimeVU Members
linenumberstrue
/// <summary>
///  A runtime VU object.
/// </summary>
public class RuntimeVU
{        
    /// <summary>
    /// The extractor runtime object for the VU.
    /// </summary>
    public ExtractorRuntime ExtractorRuntime { get; }        
    /// <summary>
    /// The VU number.
    /// </summary>
    public int VUNumber { get; }
    /// <summary>
    /// The VU iteration number.
    /// </summary>
    public int Iteration { get; }
    /// <summary>
    /// If iteration was aborted
    /// </summary>
    public bool IsAbortedIteration { get; }    
    /// <summary>
    /// If virtual user is warming up.
    /// </summary>
    public bool IsWarmup { get; }
    /// <summary>
    /// If virtual user is running a verify.
    /// </summary>
    public bool IsVerify { get; }
    /// <summary>
    /// Which test case is currently being executed.
    /// </summary>
    public string TestCase{ 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);
}

navigate to the Components tab (a). From there, you can create your own variable. Select one of three languages you wish to use: C#, VB.NET, or JScript.NET (b).

Give your component a name (c) and chose when you want to invoke it (d). 

There are two modes of component invocation:

  • On every session: the component is invoked for every session in every test case inside the test
  • On sessions with a hook: the component is invoked only for sessions whose component hook property is the name of the component.

You can edit or delete your component later on by going back to the Components tab, selecting the variable you wish to modify, and then clicking either Edit (e) or Delete (f). Click OK to bring up the code editor window. If you don't see your component, click Open File (g) to select the code file to edit.


There are two types of components that differ by the method they are created:

  • Internal components are created in StresStimulus. Their benefit is simplicity as they do not require any additional development tools.
  • External components are created by developing external .NET DLLs using Microsoft Visual Studio. This allows to develop more sophisticated functionality and behavior using external libraries and powerful development and debugging Visual Studio environment

Image Added

...