Create a runtime file

Relevant for: API testing only

Note: You must compile the DLL with a Target Framework of Framework 4.0.

Add Using statements

In your runtime file, provide the mandatory using statements. In your solution, you must also add a reference to the .dll files. The .dll files are located in the products installation's /bin folder. You must always add a reference to HP.ST.Fwk.RunTimeFWK.dll. If you are using internal logging, you must also add a reference to log4net.dll.

The following example shows the Using statements in the sample .cs file.

using HP.ST.Fwk.RunTimeFWK;
// If you need to implement Internal Logging
using log4net;

Back to top

Specify the namespace and class

Define the namespace and provide the activity's runtime code. The class you define for your custom activity must inherit from the STActivityBase class. For example:

namespace ReportMessageActivitySample
{
[Serializable]
public class ReportMessageActivitySample : STActivityBase
{

Back to top

Set the internal logging

Use the built-in logger manager to instruct the activity to create an internal log during runtime. This example gets the property values of the input properties and sends the output to either the run results only or to the run results and Output window. For example:

/// <summary> /// Internal log
/// </summary>
private static readonly ILog log = 
LogManager.GetLogger(typeof(ReportMessageActivitySample)); const string runResults = "Run Results"; const string runResultsAndOutputWindow = "Run Results and Output Window";

For details about other logging options, see Assert object.

Back to top

Initialize the properties

Initialize the custom Input and Output properties that you define in the signature file. The following example initializes the three input properties: Status, Message, and Destination. For example:

/// <summary>
/// Initializes properties.
/// </summary>
/// <param name="ctx">The runtime context</param>
public ReportMessageActivitySample(ISTRunTimeContext ctx, string name)
: base(ctx, name)
{
this.Status = String.Empty;
this.Message = String.Empty;
this.Destination = String.Empty;
}

Back to top

Retrieve the property values

This section retrieves or sets the input property values. For example:

/// <summary>
/// Gets or sets the status of the message to report.
/// </summary>
public string Status { get; set; }
/// <summary>
/// Gets or sets the details of the message to report.
/// </summary>
public string Message { get; set; }
/// <summary>
/// Gets or sets the destination where the message should be reported to.
/// </summary>
public string Destination { get; set; }

If you have array type properties that are not described by a schema, for example, key/value pairs, you must initialize all the members of the array explicitly, and indicate the actual number of elements.

The following example initializes 40 elements for the MyArrayName property. It contains 40 key and value pairs.

this. MyArrayName = new MyPair[40];
for (int i=0; i<40; i++)
{
this. MyArrayName [i] = new MyPair();
}
public MyPair[] MyArrayName;
public class MyPair
{
string Key;
string Value;
}

For arrays defined by a schema or WSDL, you can use the standard Select Link Source Dialog Box (API Testing) and link directly to the array element.

Back to top

Define events

Define one or more custom events, that you will invoke later. For example:

public event EventHandler CustomerEvent;
private void InvokeCustomerEvent(EventArgs MyArg)
{
EventHandler handler = this.CustomerEvent;
if (handler != null)
{
handler(this, MyArg);
}
}

Back to top

Execute the step

Execute the step and send the runtime information to the log. Use the STExecutionResult data type and its ExecuteStep function defined in the STActivityBase class. For example:

protected override STExecutionResult ExecuteStep()
{
string DetailsReport;
if (this.Destination == runResultsAndOutputWindow)
{
LogInfo("\n" + this.Message.Replace("\\n", "\n"));
}
/// <summary>
/// Reports message to test results and output window.
/// </summary>
// The line-breaks replacements allow the printing of multiple lines in the report
	DetailsReport = this.Message;
	DetailsReport = DetailsReport.Replace("\\n", "<BR>");	
	DetailsReport = DetailsReport.Replace("\n", "<BR>");
	this.Report("Message", DetailsReport);

If you defined a custom event, invoke it after the call to ExecuteStep.

...
protected override STExecutionResult ExecuteStep()
{
InvokeCustomerEvent();
}

Back to top

Set the status

Set the Status of the test run. The ReportMessageActivitySample.cs sample file uses enumeration to set the status, based on the STExecutionResult value. For example:

switch (this.Status)
{
case "Done":
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.DoneValueTag);
return new STExecutionResult(STExecutionStatus.Success);
case "Pass":
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.SuccessValueTag);
return new STExecutionResult(STExecutionStatus.Success);
case "Fail":
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.FailureValueTag);
return new STExecutionResult(STExecutionStatus.Success);
default:
return new STExecutionResult(STExecutionStatus.Success);
}

Back to top

Compile the runtime file

After you customize the code, you compile the .dll. The .dll name should be the same as the name of the addin file. For example, the runtime file, ReportMessageActivitySample.dll corresponds to the ReportMessageActivitySample.addin file.

After you create the runtime file in your development environment, you reference the .dll from the signature file, and the signature file from the addin file.

Back to top