function1(){
–> call macro1
→ check if macro1 run was successful or not
-
The principle is that UI Vision writes a log file after each macro is done, and in the first line of the log is the status (= successful or not). So the first line either has the text “Status=OK” or “Status=error message”. That is very easy to parse.
-
The name of the log file is set with &savelog=abc.txt when you start UIVision via command line.
-
What the code below also does is the throw a timeout error in case it can not find the log file after X seconds. This can happen if UI Vision or the browser crashes. Or the website opened a modal dialog box (which hangs UI Vision as well).
-
See also: How to run UI Vision RPA 24x7
This is how you do this in Powershell. Same code in Python.
#############Wait for macro to complete => Wait for log file to appear in download folder
$status_runtime = 0
Write-Host "Log file will show up at " + $path_log
while (!(Test-Path $path_log) -and ($status_runtime -lt $timeout_seconds))
{
Write-Host "Waiting for macro to finish, seconds=" $status_runtime
Start-Sleep 1
$status_runtime = $status_runtime + 1
}
#Macro done - or timeout exceeded:
if ($status_runtime -lt $timeout_seconds)
{
#Read FIRST line of log file, which contains the status of the last run
$status_text = Get-Content $path_log -First 1
#Check if macro completed OK or not
$status_int = -1
If ($status_text -contains "Status=OK") {$status_int = 1}
}
else
{
$status_text = "Macro did not complete within the time given:" + $timeout_seconds
$status_int = -2
#Cleanup => Kill Chrome instance
#taskkill /F /IM chrome.exe /T
}
remove-item $path_log #clean up