Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waiting for a application window: pywinauto.timings.WaitUntilPasses in Python

I am trying to use waituntilpasses in pywinauto to give an application time to open a new window. I have used SWAPY to identify the window details.

For the sake of testing I manually open the sub-window, so the WaitUntilPasses should see this immediatly, it however does not.

The syntax appears OK as I can find and print the output of find_windows, as below:

xx = pywinauto.findwindows.find_windows(
    title=u'Choose template', class_name='#32770')[0]
print (xx)

This gives a response of 789646

However in my WaitUntilPasses command:

pywinauto.timings.WaitUntilPasses(
    20, 0.5, 
    (pywinauto.findwindows.find_windows(
        title=u'Choose template', class_name='#32770')[0]
    )
)

It always times out. I cannot see the issue with the syntax, and have tried every permutation I can think of. Any tips would be greatly appreciated.

like image 304
user2811072 Avatar asked Sep 24 '13 13:09

user2811072


1 Answers

pywinauto.timings.WaitUntilPasses waits a function in the third parameter, but not a value of a function execution(in your case).

A fix - convert your checking in lambda function:

pywinauto.timings.WaitUntilPasses(20, 0.5, lambda: pywinauto.findwindows.find_windows(title=u'Choose template', class_name='#32770')[0])

But I favor if you put the checking in a separate function:

def check():
    return pywinauto.findwindows.find_windows(title=u'Choose template', class_name='#32770')[0]

pywinauto.timings.WaitUntilPasses(20, 0.5, check) #Important: 'check' without brackets
like image 153
SWAPYAutomation Avatar answered Oct 12 '22 10:10

SWAPYAutomation