Sign in to follow this  
Followers 0
ijourneaux

Struggling to improve script reliability

5 posts in this topic

I have been struggling to automate an existing application using AutoIt. I have switched to using all Control... type functions as the applcation is usually being run when the workstation is locked (learning experience on my part<grin>).

Unfortunately I am still having problems where the application doesn't seem to want to react to commands I am sending.

Here is a typical situation

Send a command

ControlSend($windowname, "", "[CLASS:Edit; INSTANCE:1]", $s_Filename)

; Wait for control of Save button. Save is Button2

Call("WaitForControl", $windowname, "&Save", "Button2", 200)

Wait for control is a function someone helped me with

Func WaitForControl($sTitle, $text, $sControlID, $iTimeout = 5, $Exit = 'True')
    Local $iTimer = TimerInit()
    
    While (ControlFocus($sTitle, $text, $sControlID) = 0)
        WriteToLogFile(@ScriptDir & $LogFileName, "Wait")
        if (TimerDiff($iTimer) / 1000) >= $iTimeout then 
            WriteToLogFile(@ScriptDir & $LogFileName, "Exit without Focus")
            if($exit = "True") then
                $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress,  $FromAddress, "IFM Report " & $FileName & " did not print!", "", "", $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
                $hWnd = WinGetHandle("InfoStore Client")
                _ScreenCapture_CaptureWnd (@ScriptDir & "\CurrentScreen_" & @hour & ".jpg", $hWnd)
                ProcessClose ("InfoStore.exe")
                Exit
            EndIf
            ExitLoop
        EndIf   
        Sleep(5000)     
        WriteToLogFile(@ScriptDir & $LogFileName, "Activate - " & $sTitle)  
        If (TimerDiff($iTimer) / 1000) >= $iTimeout/2 Then WinActivate($sTitle, $text)
    
     WEnd
    WriteToLogFile(@ScriptDir & $LogFileName, "Title = " & $sTitle)
    Sleep(3000)
     return 1
EndFunc

25% or more of the time, I never get focus on the control so the script stops.

I have toyed with loops like

Do
    Sleep(1000)
while (WinMenuSelectItem("InfoStore Client", "", "&View", "&Graphs", "SENA Scrolling &3D") = 0)

but it seems clumsy if I also include a loop counter so that I don't get stuck in the do loop. Is there a resource of best practices? Thanks

Share this post


Link to post
Share on other sites



Just trying to eliminate/clear-up something.

Is that 25% independent of the used control's. (same control will both work and fail.)

Or 25% of the used control's fail. (same control will always work or always fails.)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

At this point, the two places where are see failures are related (althouhg 75% of the time the scrip executes fine) are when I execute a make a call to WinMenuSelectItem. I may have others but for now those are the ones that fail some of the time.

Before I make the call to WinMenuSelectItem, I check to see if I have control of the window, call WinMenuSelectItem with the appropriate choices then wait until I can get control of one of the controls that appears as a result of the call to WinMenuSelectItem.

At this point I have added a loop to make sure the control appears and if not I try the WinMenuSelectItem again. After a number of failed attempts, I exit the script.

Relatively speaking, this is a fairly simple application. This is a standalong box, with no chance of other appliciation or users getting in the way. The results of the individual commands are simple. This shoudn't be difficult so I must be missing something obvious.

Share this post


Link to post
Share on other sites

Mmm, a WinMenu problem.

I don't think I can help here.

1) Its been a long time I did some coding with them.

2) I also did had some problem with them, but you already seems to have bypassed those timing problems.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Mmm, a WinMenu problem.

I don't think I can help here.

1) Its been a long time I did some coding with them.

2) I also did had some problem with them, but you already seems to have bypassed those timing problems.

It was just over night last night that I noticed the failures were coming on WinMenu. There are two places in the script where I use WinMenu and the script failed atleast once at each location.

Is there an issue with WinMenu and a locked workstation? The problem is that it seems to work some of the time.

Thanks for trying though. Hoefully someone else will have some insight.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0