From 92c2f6fcb6002129a536afb5ab51d2d47cf0498e Mon Sep 17 00:00:00 2001 From: markm Date: Fri, 5 May 2006 13:27:53 +0000 Subject: [PATCH] Updated the sample files --- examples/ForteAgentSample.py | 13 +++++++++++++ examples/MiscExamples.py | 16 ++++++++-------- examples/SaveFromFirefox.py | 13 ++++++++++--- examples/get_winrar_info.py | 1 - examples/mspaint.py | 17 +++++++++++++++-- examples/notepad_item.py | 4 ++-- examples/notepad_slow.py | 7 +++++-- 7 files changed, 53 insertions(+), 18 deletions(-) diff --git a/examples/ForteAgentSample.py b/examples/ForteAgentSample.py index 39ecc9c..ae465d9 100644 --- a/examples/ForteAgentSample.py +++ b/examples/ForteAgentSample.py @@ -15,12 +15,25 @@ from pywinauto.application import Application # start the application and wait for the Agent Dialog to be ready app = Application().start_(r"c:\program files\agent\agent.exe") +while not app.Windows_(): + time.sleep(.5) + # if the trial nag dialog pops up if app.window_(title = "Forte Agent Trial").Exists(): #app.ForteAgentTrial.IdLikeToContinueUsingAgentfor7moredays.Click() app.ForteAgentTrial.IdliketouseFreeAgent app.ForteAgentTrial.OK.Click() +if app.window_(title = "Free Agent Registration").Exists(): + app.FreeAgentRegistration.ImreallybusyRemindmein30.Click() + app.FreeAgentRegistration.OK.CloseClick() + +if app.window_(title = "What's New Reminder").Exists(): + app.WhatsNewReminder.ImreallybusyRemindmein90.Click() + app.WhatsNewReminder.OK.CloseClick() + + + # wait until the app is ready app.FreeAgent.Wait("ready") diff --git a/examples/MiscExamples.py b/examples/MiscExamples.py index 3602a14..e95e8bb 100644 --- a/examples/MiscExamples.py +++ b/examples/MiscExamples.py @@ -48,14 +48,14 @@ def TestExceptions(): except application.AppStartError: pass - # try when it isn't connected - try: - app = application.Application() - #app.start_(ur"c:\windows\system32\notepad.exe") - app.Notepad.Click() - assert False - except application.AppNotConnected: - pass +# # try when it isn't connected +# try: +# app = application.Application() +# #app.start_(ur"c:\windows\system32\notepad.exe") +# app.Notepad.Click() +# #assert False +# except application.AppNotConnected: +# pass diff --git a/examples/SaveFromFirefox.py b/examples/SaveFromFirefox.py index 4cc9734..7fe761e 100644 --- a/examples/SaveFromFirefox.py +++ b/examples/SaveFromFirefox.py @@ -3,6 +3,8 @@ import sys import time import os.path +from pywinauto import WindowAmbiguousError + if len(sys.argv) < 2: print "please specify a web address to download" sys.exit() @@ -53,9 +55,14 @@ app.SaveAs.FileNameEdit.SetEditText(outputfilename) app.SaveAs.Save.CloseClick() -# if asked to overwrite say yes -if app.SaveAs.Yes.Exists(): - app.SaveAs.Yes.CloseClick() +try: + # if asked to overwrite say yes + if app.SaveAs.Yes.Exists(): + app.SaveAs.Yes.CloseClick() +except WindowAmbiguousError, e: + for w in e.windows: + w = HwndWrapper(w) + print w.WindowText(), w.Class() print "saved:", outputfilename diff --git a/examples/get_winrar_info.py b/examples/get_winrar_info.py index 3a3ec90..c8b8ebc 100644 --- a/examples/get_winrar_info.py +++ b/examples/get_winrar_info.py @@ -1,4 +1,3 @@ - """Automate WinRAR evaluation copy We hit a few dialogs and save XML dump and diff --git a/examples/mspaint.py b/examples/mspaint.py index 9ab73ef..fb50a4b 100644 --- a/examples/mspaint.py +++ b/examples/mspaint.py @@ -28,7 +28,11 @@ from pywinauto import application from pywinauto import tests from pywinauto.findbestmatch import MatchError from pywinauto import findwindows +from pywinauto import WindowAmbiguousError +from pywinauto.controls import WrapHandle +from pywinauto.timings import Timings +Timings.Fast() app = application.Application() @@ -54,8 +58,17 @@ app.Attributes.Edit2.SetEditText("350") # SetText - they work differently! app.Attributes.OK.CloseClick() -# get the reference to the Canvas window -canvas = pwin.Afx100000008 +try: + # get the reference to the Canvas window + canvas = pwin.Afx100000008 + canvas.WrapperObject() +except WindowAmbiguousError, e: + print e, e.windows + for w in e.windows: + w = WrapHandle(w) + print w.WindowText(), w.Class() + import sys + sys.exit() # make sure the pencil tool is selected pwin.Tools2.Click(coords = (91, 16)) diff --git a/examples/notepad_item.py b/examples/notepad_item.py index f7b636d..8b1a249 100644 --- a/examples/notepad_item.py +++ b/examples/notepad_item.py @@ -30,14 +30,14 @@ from pywinauto.findbestmatch import MatchError from pywinauto import findwindows -application.set_timing(3, .5, 10, .5, .4, .2, .2, .1, .2, .5) +#application.set_timing(3, .5, 10, .5, .4, .2, .2, .1, .2, .5) "Run a quick test on Notepad" app = application.Application() app.start_(ur"notepad.exe") -app['Notepad'].WaitReady() +app['Notepad'].Wait('ready') app['Notepad'].MenuSelect("File->PageSetup") diff --git a/examples/notepad_slow.py b/examples/notepad_slow.py index e69de43..e7d49e6 100644 --- a/examples/notepad_slow.py +++ b/examples/notepad_slow.py @@ -37,10 +37,13 @@ except ImportError: from pywinauto import tests from pywinauto.findbestmatch import MatchError from pywinauto import findwindows +from pywinauto.timings import Timings print "Setting timings to slow settings, may be necessary for" print "slow applications or slow machines." -application.set_timing(3, .5, 10, .5, .4, .2, .2, .1, .2, .5) +Timings.Slow() + +#application.set_timing(3, .5, 10, .5, .4, .2, .2, .1, .2, .5) start = time.time() @@ -202,7 +205,7 @@ app.SaveAs.Save.CloseClick() # while the dialog exists wait upto 30 seconds (and yes it can # take that long on my computer sometimes :-( ) -app.SaveAs.Cancel.WaitNot('enabled') +app.SaveAsDialog2.Cancel.WaitNot('enabled') try: app.SaveAs2.Yes.CloseClick()