PowerShellPowerShell agent exposes several objects available for PowerShell scripts:
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"
|