SWAPY
SWAPY copied to clipboard
Reuse `app` variable
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.
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.
Depends on #66
i download the code and how to run manually