PowerShell agent exposes several objects available for PowerShell scripts:
-
variables – array of aqua.ProcessEngine.WebServiceProxy.VariableValue objects containing TC variables (and their values) used for execution. Name and Value are most important properties of VariableValue.
-
tempDir – string variable containing path of temporary directory where script attachments have been saved (if applicable).
-
aquaCallback – reference to AquaShellCallbackHelper object that can be used to communicate with aqua from PowerShell script. Available functionality includes:
-
sending log messages to aqua (also with screenshots)
-
sending attachments to aqua (saved as attachments in the execution object)
-
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 stop in 5 seconds after flag is set, agent does forced stop of the running script.
To use exposed objects, PowerShell script needs to declare their usage by issuing the following command:
param($variables, $tempDir, $aquaCallback)
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
param($variables, $tempDir, $aquaCallback)
$text = new-object System.Text.StringBuilder
$date = [System.DateTime]::Now
$text.AppendLine($date.ToLongDateString())
$text.AppendLine($date.ToLongTimeString())
echo "$text" > script-sample.log
foreach ($var in $variables)
{
$varName = $var.Name
$varValue = $var.Value
echo "Variable: $varName : $varValue" >> script-sample.log
}
# Possible Types of [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]
# SUTError, ScriptExecutionError, PreparationError, ExecutionError, InformationalInfo, InformationalDebug, InformationalWarn, InformationalSuccess
$aquaCallback.SendMessage("hello, I was sent from script", [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]::InformationalWarn, "my category");
$aquaCallback.SendMessageWithScreenshot("and this is Screenshot", "c:\sample.jpg", [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]::InformationalWarn, "my category");
dir $tempDir >> script-sample.log
$aquaCallback.AddExecutionAttachment("script-sample.log");
while ($true)
{
if ($aquaCallback.StopRequest)
{
$aquaCallback.SendMessage("Aborting on StopRequest", [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]::InformationalWarn, "my category");
return "Aborted"
}
Start-Sleep -s 10
aquaCallback.SendMessage("Looping in PowerShell…", [aqua.ProcessEngine.WebServiceProxy.ExecutionLogMessageType]::InformationalWarn, "my category");
}
# Return status of script execution. One of: Ready, Blocked, Fail, Aborted
39. return "Ready"