Powershell
Last updated
Last updated
How to set up a PowerShell agent can be read in the chapter Automation Agent; Creation & Configuration. The PowerShell agent is required for executing a test case with PowerShell scripts.
To add a PowerShell script to a test case, open a test case and navigate to step designer. Switch to the tab 'Automation'.
When you select PowerShell, a sample PowerShell script is automatically inserted. You can use the sample script to easily understand the functionality that the PowerShell agent provides. You can then further customise the script or replace it directly with other scripts.
Here is some more information about the objects and functions that the PowerShell agent provides for PowerShell scripts:
variables – array of objects containing TC variables (and their values) used for execution. Name and Value are the most important properties of each object.
tempDir – string variable containing path of the temporary directory where the script attachments have been saved (if applicable).
aquaCallback – reference to AquaShellCallbackHelper object that can be used to communicate with aqua from within the PowerShell script. Available functionalities include:
sending log messages to aqua (also with screenshots)
sending attachments to aqua (saved as attachments in the execution object)
sending execution status via AddExecutionData
retrieve test execution information (Ids of project, test case, test execution, test scenario, test scenario execution)
StopRequest property - set by agent on abort requests received from aqua. Long-running scripts should periodically check this flag and stop gently in case when set. If not stopped in 5 seconds after the flag is set, the agent does a forced stop of the running script.
To call nunit by PowerShell, you can use commands like:
To use exposed objects, PowerShell script needs to declare their usage by issuing the following command:
Note that all used variables must be declared in a single “param” command.
Sample script using those objects:
# Sample PowerShell script that uses .NET objects and TC variables from aqua
#Request Test Execution information via $aquaCallback.GetExecutionInfo()#Returns an object with ProjectId, TestCaseId, TestExecutionId, [TestScenarioId and TestScenarioExecutionId]
# Possible Types of [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]
# SUTError, ScriptExecutionError, PreparationError, ExecutionError, InformationalInfo, InformationalDebug, InformationalWarn, InformationalSuccess
# Return status of script execution. One of: Ready, Blocked, Fail, Aborted return "Ready"