pywinauto / SWAPY

not maintained any more (will be replaced by py_inspect)
https://github.com/pywinauto/py_inspect
271 stars 66 forks source link

Reuse `app` variable #63

Open moden-py opened 9 years ago

moden-py commented 9 years ago

Reuse app variable for one process owned different top level windows. One app may be used for all windows owned by one process. For instance:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()
window = app.Dialog
window.Wait('ready')
button = window.OK
button.Click()

app.Kill_()

Now the same actions code looks:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()

app2 = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
window = app2.Dialog
window.Wait('ready')
button = window.OK
button.Click()
button.Click()

app2.Kill_()
app.Kill_()

Restarting the same application is probably not the thing you expect.

moden-py commented 9 years ago

In case the second window opens after some action on the first one, you should refresh the objects tree to add new windows. Before fix "Reuse app" issue, a "safe refresh" should be applied. Now all the counters are reset after the object browser refresh.

moden-py commented 9 years ago

Depends on #66

GopinathB-Hexaware commented 6 years ago

i download the code and how to run manually