Overview
The MxVDev COM interface is used primarily to automate the execution of a Scenario or a Regression Command File. You can use it with any .NET language, such as C# or VBScript. The API provides the following objects and their associated methods and properties:
Used to access high level features of MxVDev. To launch MxVDev and create the application object, use: CreateObject (“MicroMax.MxVDev.Application”)
|
Used to perform operations on the current project. This sample code shows how to create an application object, open a project, and and use the LoadHarness method on the project object:
set mxv = CreateObject("MicroMax.MxVDev.Application")
|
Used to perform operations on the current Scenario.
|
The result from a single regression test in the .mxreg file.
|
The results from all regression tests in the .mxreg file. To create an instance, use: CreateObject("MicroMax.MxVGUI.Automation.RegressionResults")
|
Used to control various aspects of the regression test. To create an instance, use: CreateObject("MicroMax.MxVGUI.Automation.RegressionSettings")
|
Describes a Signal failure detected when running a Scenario.
|
Use the CreateTestCaseImportParameters method to create this object. Use the ImportTestCaseCSV method to import data from a CSV file into this object. For the format of the CSV file, see Importing Test Data. See ITestCaseImportParameters Interface.
|
For examples of VBScripts using the COM API, see Automation.vbs in the Automation sample project folder and Automation.xls in the TurnDoorSample folder.
The Automation sample project folder contains a sample Visual Basic Script named AutomationCreateProject.vbs that programmatically creates a MxVDev project. The name and location of the project are specified in the script. The sample script creates a project named MxTest.mxp in this folder: C:\Documents\MxSuiteSamples\Automation\CreateCOMProject
|
Interface Definition
Interface IScenarioRunResult:
public enum Results { NotRun, RunTimeError, Skipped, NotComplete, Fail, Pass, Missing } //the same as Scenario RunResults public interface IScenarioRunResult { Results RunResult { get; set; } int GetResultCode(); //enum value string GetResultString(); //enum name string }
Sample VBScript Note: To run this script, copy and paste it to a .vbs file. You may need to modify the path parameters.
on error resume next stop 'allows debugging set mxv = CreateObject("MicroMax.MxVDev.Application") if mxv is nothing then call MsgBox("Failed to create MxVDev automation object!") call WScript.Quit() end if
set project = mxv.OpenProject( "C:\TurnDoorSample\Mxv.mxp" ) if project is nothing then call MsgBox("Failed to open TurnDoorSample project!" ) call mxv.Quit() call WCsript.Quit() end if
set run = project.ExecuteScenario("C:\TurnDoorSample\ScenariosAndTestCases\DoorTurnScenario.mxs", false, false, "")
dim details details = project.GetResultDetailsSorted(run) call MsgBox(details)
call mxv.CloseProject() call mxv.Quit() Set mxv = Nothing
Sample Results The code above produces this output: |
This VBScript example creates a project then loads the Signal Dictionary and TestCases from CSV files. on error resume next stop 'allows debugging set mxv = CreateObject("MicroMax.MxVDev.Application") if mxv is nothing then call MsgBox("Failed to create MxVDev automation object!") call WScript.Quit() end if
' create a project, 4 parameters in function CreateProject(arg1, arg2, arg3, arg4) ' arg1: the project name, will be used for the project file name (project_name.mxp). This cannot be empty ' arg2: the project folder, the mxv project folder, this cannot be empty ' arg3: the company name, will be one of the properties in created mxv project. This can be an empty string ' arg4: the description of the project, will be one of the properties in created mxv project. This can be an empty string set project = mxv.CreateProject( "MxTest", "C:\ImportTestCaseProject\", "Danlaw Inc.", "Using COM to import TestCases from CSV files" ) if project is nothing then call MsgBox("Failed to create MxTest project!" ) call mxv.Quit() call WScript.Quit() end if
if not project.ImportSignalDictionaryCSV( "C:\ImportTestCaseProject\signalsForImport.csv" ) then CloseAndQuit mxv, "Failed to Import signal dictionary CSV file" + vbNewLine + mxv.GetLastErrorString(), 1 end if
set ParameterStructure = project.CreateTestCaseImportParameters() if ParameterStructure is nothing then call MsgBox("Failed to create ParameterStructure!" ) call mxv.Quit() call WScript.Quit() end if
ParameterStructure.OutputFile = "C:\ImportTestCaseProject\ScenariosAndTestCases\ImportedTC.mxc" ParameterStructure.ValueDelimiter = 0 ' comma ParameterStructure.DecimalDelimiter = 0 ' period ParameterStructure.CommentDelimiter = 0 ' semicolon ParameterStructure.DataFormat = 0 ' matrix ParameterStructure.LoadOption = 0 ' New TestCase ParameterStructure.MatrixTimeUnits = 2 ' Milliseconds ParameterStructure.HasColumnHeader = 1 ParameterStructure.MatrixHasTimeColumn = 1 ParameterStructure.MatrixTimeColumnIndex = 0 ParameterStructure.MatrixTimeColumnDeltaType = 0 ' Absolute ParameterStructure.TestCaseName = "Imported Test Case" ParameterStructure.TestCaseTestResolution = .01 ParameterStructure.TestCaseTimeUnits = 2' Milliseconds ParameterStructure.TestCaseDuration = 50 ParameterStructure.TestCaseStartTime = 0 ParameterStructure.TestCaseEndTime = 50
result = project.ImportTestCaseCSV("C:\ImportTestCaseProject\Matrix Format Comma Separated.csv", ParameterStructure)
if result <> True then call MsgBox ("Import failed. result = " & result) else call MsgBox ("TestCase imported successfully") end if call mxv.CloseProject() call mxv.Quit() set mxv = Nothing
' This sample will create a project MxTest.mxp with a custom harness (an empty harness file can be found under the transforms folder MxTest.mxform) ' in the folder C:\Documents\MxSuiteSamples\Automation\CreateCOMProject\ |
The examples below use the MxVDev COM interface to automate the execution of a Regression Command File:
This is a VBScript using the MxVDev COM interface to automate the execution of a Regression Command File.
set mxv = CreateObject("MicroMax.MxVDev.Application") if mxv is nothing then call MsgBox("Failed to create MxVGUI") call WScript.Quit() end if
mxv.EnableLogging = true
dim errorString if mxv.ExecuteRegression("C:\Program Files\MicroMax\MxVDev\Samples\TurnDoorSample\Regression\Regression.mxreg") = false then errorString = mxv.GetLastErrorString() if mxv.EnableLogging = false then 'when logging disabled, force to log mxv.AddLog(errorString) end if 'optional : to show the message box about error, remove the comment ' below 'call MsgBox(errorString) end if 'repeat mxv.ExecuteRegression (Regression_Command_File) to run more regression tests call MsgBox("Regression Complete!")
call mxv.Quit() set mxv = Nothing
|
This C# code uses the MxVDev COM interface to automate the execution of a Regression Command File. //Create the application object. IApplication app = MicroMax.MxVDev.Automation.Activator.ActivateMxVGUI(); if (app == null) { MessageBox.Show("Unable to create application"); return; }
//Create a regression settings object IRegressionSettings settings = app.CreateRegressionSettings(); if( settings == null ) { MessageBox.Show("Unable to create regression settings"); return; }
//Execute the regression string path = @"C:\Users\mattm.ERMINE-STREET\Documents\MxSuiteSamples\InvertSample\Regression\Regression.mxreg"; if( !app.ExecuteRegression(path, settings)) MessageBox.Show(app.ExplainError(app.GetLastErrorCode()));
//Show a popup of results for entire regression. MessageBox.Show(string.Format("{1} Passed{0}{2} Failed{0}{3} Skipped{0}{4} Missing", Environment.NewLine, app.RegressionResults.TotalPassed, app.RegressionResults.TotalFailed, app.RegressionResults.TotalSkipped, app.RegressionResults.TotalMissing));
//Show a popup of results for each regression. object[] results = app.RegressionResults.Results as object[]; foreach (object obj in results) { IRegressionResult result = obj as IRegressionResult; MessageBox.Show(string.Format("{1}{0}{2} Passed{0}{3} Failed{0}{4} Skipped{0}{5} Missing", Environment.NewLine, result.Path, result.Passed, result.Failed, result.Skipped, result.Missing)); }
|
A sample Visual Studio solution is installed in the Samples\Automation\CSharp folder: COMSample.sln Before building the sample solution, be sure the version of MxSuite you are using is set as the Default version. When executed, the program creates an MxVDev project and TestCases based on Excel (.csv) files, and executes a Scenario. The CSV files are provided in the Automation sample folder.
|
Creating Tests with a C# Program