Python result reporting extensions

To create a Python result reporting extension is required to implement an AutotestResultPlugin class:

class AutotestResultPlugin:
    def __init__(self, system, user, password):
    def GetConfigurationOptions(self):
    def ExportResult(self, options, result):
    def Shutdown(self):

Constructor

def __init__(self, system, user, password):
public class MyDotNetResultReportingExtension : ACustomResultReportingExtension
{
    public MyDotNetResultReportingExtension(string System, string UserId, string Password)
            : base(System, UserId, Password)
    {
    }
}

Python the constructor is provided with the system, user and password. The user and password are credentials provided in the workspace Settings configuration in Autotest.

Note that during configuration user and password may be set to empty string, if the user hasn’t supplied any credentials:

  1. If possible, allow GetConfigurationOptions to execute also without credentials.
  2. If GetConfigurationOptions requires credentials, throw an exception rather than returning an empty return structure.
  3. Always throw an exception in ExportResult if credentials are required but missing or invalid.

GetConfigurationOptions

def GetConfigurationOptions(self):
public override List<Plugin_Parameter> GetConfigurationOptionsImpl()
{
    return new List<Plugin_Parameter>
    {
        new Plugin_Parameter
        {
            Type = Plugin_DataType.STRING,
            Mandatory = true,
            Name = "outputFile",
            Description = "Output File"
        },
        new Plugin_Parameter
        {
            Type = Plugin_DataType.STRING,
            Mandatory = false,
            Name = "testCaseId",
            Description = "Test Case ID"
        },
        new Plugin_Parameter
        {
            Type = Plugin_DataType.BOOL,
            Mandatory = true,
            Name = "success",
            Description = "Success"
        }
    };            
}

Defines input to the extension in the form of a list of Parameters. Functionality is the exact same as query extension parameters. (Please see section 5.3 for full details on parameters).

While during execution the extension is supplied with the complete execution result as defined by OmniFi, Configuration options are extension specific input parameters that are useful to provide extension specific configuration.

Configuration options are resolved run-time and can be linked both to variables and expressions in Autotest making them very versatile.

Typical usage includes:

  • Static configuration such as an API URL to a target system, or an email address.
  • Runtime values and references, such as test-case-id.

ExportResult

def ExportResult(self, options, result):
public override void ExportResultImpl(
    List<Plugin_Argument> Options,
    List<Plugin_Argument> Result)
{
    Logger.Debug("ExportResultImpl(): Enter");
    var options = Options.ToDictionary((x) => x.ParameterName);
    var result = ParseTestResult(Result);
    Plugin_Argument fileArg, testCaseIdArg, successArg;
 
    if (!options.TryGetValue("outputFile", out fileArg)
        || String.IsNullOrEmpty(fileArg.StringValue))
    {
        throw new ArgumentException("Output File not supplied");
    }
    string outputFile = fileArg.StringValue;
 
    string testCaseId;
    if (options.TryGetValue("testCaseId", out testCaseIdArg)
        && testCaseIdArg.StringValue != null)
    {
        testCaseId = testCaseIdArg.StringValue;
    }
    else
    {
        Logger.Warning(
            "ExportResultImpl(): No Test Case ID supplied, reverting to default.");
        testCaseId = result.Path;
    }
 
    if (!options.TryGetValue("success", out successArg)
        || successArg.BooleanValue == null)
    {
        throw new ArgumentException("Success not supplied");
    }
    bool success = (bool)successArg.BooleanValue;
 
    var directory = Path.GetDirectoryName(outputFile);
    if (!Directory.Exists(directory))
        Directory.CreateDirectory(directory);
            
    var lastExecuted = result.LastExecuted.ToString("yyyy-MM-dd hh:mm:ss");
 
    Logger.Trace("ExportResultImpl(): using file: " + outputFile);
 
    File.AppendAllLines(
        outputFile, 
        new string[] { $"{testCaseId};{lastExecuted};{success}" });
    Logger.Debug("ExportResultImpl(): Leave");
}

Export result is the main worker of the result reporting extension. It is important to note that the ExportResult method may be executed any number of times for different items during an execution. This means you must be careful and avoid modifying the script state during execution.

Options argument

Configuration option values are provided as an Argument list by the options method argument. You can use an ArgumentReader to read this:

def ExportResult(self, options, result):
        argReader = ArgumentReader(options)
        paramValue = argReader.TryGetArgumentValue("paramName")
        if (paramValue != None):
            pass # Do something

Result argument

The result argument is an Argument list describing the full execution result. As with argument lists in general, you can read it using and ArgumentReader. Please see Result reporting data for a detailed description of this data structure.

Shutdown

def Shutdown(self):

The shutdown method is called just before the extension is closed, allowing you to clean up any cached state.