Ganesh S
Ganesh S

Reputation: 431

Application synchronization in pywinauto

How do I do application/object synchronization in pywinauto for my application? We moved for UFT to python+pywinauto. In UFT, there were random instances when our application under test used to be too busy to respond to actions or didn't respond immediately to an UI action like clicking a button due to some internal processing it was doing. We had set syncronization timeout default value to 60 seconds and UFT used to wait for the application to respond automatically and then perform the operation. How do I handle such situation in pywinauto ?

Upvotes: 1

Views: 1377

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 10000

The default timeout in pywinauto is 5 sec. It can be changed globally (not recommended!):

from pywinauto.timings import Timings
Timings.window_find_timeout = 60

Or you can do explicit waiting while specified control appears or disappears. It's described in more details in the docs: Waiting for Long Operations.

Example:

app.MainWindow.menu_select('File->Open')
app.OpenDialog.wait('ready', timeout=10)
app.OpenDialog.Edit.set_text('file name')
app.OpenDialog.Open.click()
app.OpenDialog.wait_not('visible', timeout=30)
app.ChangedMainWindowTitle.wait('ready', timeout=60)

[EDIT] One more powerful method:

# wait until CPU usage is lower than 2.5%
app.wait_cpu_usage_lower(threshold=2.5)

It will wait until CPU usage goes down for this particular process (it's NOT system wide CPU load). See the docs for more detailed params of this method.

Upvotes: 1

Related Questions