diff --git a/examples/get_winrar_info.py b/examples/get_winrar_info.py index 520e476..02fd963 100644 --- a/examples/get_winrar_info.py +++ b/examples/get_winrar_info.py @@ -1,17 +1,18 @@ """Automate WinRAR evaluation copy -We hit a few dialogs and save XML dump and +We hit a few dialogs and save XML dump and screenshot from each dialog. Specify a language at the command line: - 0 Czech - 1 German - 2 French - + 0 Czech + 1 German + 2 French + More then likely you will need to modify the apppath entry in the 't' dictionary to where you have extracted the WinRAR executables. """ +__revision__ = "$Revision$" import sys @@ -22,112 +23,112 @@ folders = ['wrar351cz', 'wrar351d', 'wrar351fr'] # translations for each language t = { - 'apppath' : ( - 'c:\.temp\wrar351fr\winrar.exe', - 'c:\.temp\wrar351d\winrar.exe', - 'c:\.temp\wrar351cz\winrar.exe' - ), + 'apppath' : ( + 'c:\.temp\wrar351fr\winrar.exe', + 'c:\.temp\wrar351d\winrar.exe', + 'c:\.temp\wrar351cz\winrar.exe' + ), - # Buy Licence Dialog - 'Buy Licence' : ( - "Acheter une licence pur winRAR", - "Bittekaufensieeine", - "Zakuptesiprosm"), - 'Close' : ( - "Fermer", - "Schleissen", - "Zavrit"), + # Buy Licence Dialog + 'Buy Licence' : ( + "Acheter une licence pur winRAR", + "Bittekaufensieeine", + "Zakuptesiprosm"), + 'Close' : ( + "Fermer", + "Schleissen", + "Zavrit"), - # Options->Configure menu items - "Options->Configure" : ( - "Options->Configuration", - "Optionen->Einstellungen", - "Moznosti->Nastaveni"), + # Options->Configure menu items + "Options->Configure" : ( + "Options->Configuration", + "Optionen->Einstellungen", + "Moznosti->Nastaveni"), - # Configure/Options dialog box - 'Configure' : ( - "Configuration", - "Einstellungen", - "Nastaveni"), + # Configure/Options dialog box + 'Configure' : ( + "Configuration", + "Einstellungen", + "Nastaveni"), - # personalise toolbar buttons button - 'Buttons' : ( - "Boutons", - "Schaltflachen", - "Vybrattlacitka"), + # personalise toolbar buttons button + 'Buttons' : ( + "Boutons", + "Schaltflachen", + "Vybrattlacitka"), - # Personalize toolbars dialog - 'PeronnaliseToolbars' : ( - "Peronnalisation de la barre doutils", - "Werkzeugleisteanpassen", - "Vybertlaciteknastrojovelisty"), - - # create profile button - 'CreateDefaultProfile' : ( - u"Creerleprofilpardéfault", - "Standardfestlegen", - "Vytvoritimplicitni"), - - # create profile dialog box title - 'ConfigureDefaultOptions' : ( - "Configurer les options de compre...", - "Standardkomprimierungs", - "Zmenaimplicitnichnast..."), - - # context menu's button - "ContextMenus" : ( - "Menus contextuels", - "Optionenimkontextmenu", - "Polozkykontextovehamenu"), - - # context menu's dialog - "contextMenuDlg" : ( - "Rubriques des menus contextuels", - "OptionenindenKontextmenus", - "Polozkykontextovehamenu"), - - # file->exit menu option - "File->Exit" : ( - "Fichier->Quitter", - "Datei->Beenden", - "Soubor->Konec"), + # Personalize toolbars dialog + 'PeronnaliseToolbars' : ( + "Peronnalisation de la barre doutils", + "Werkzeugleisteanpassen", + "Vybertlaciteknastrojovelisty"), + + # create profile button + 'CreateDefaultProfile' : ( + u"Creerleprofilpardéfault", + "Standardfestlegen", + "Vytvoritimplicitni"), + + # create profile dialog box title + 'ConfigureDefaultOptions' : ( + "Configurer les options de compre...", + "Standardkomprimierungs", + "Zmenaimplicitnichnast..."), + + # context menu's button + "ContextMenus" : ( + "Menus contextuels", + "Optionenimkontextmenu", + "Polozkykontextovehamenu"), + + # context menu's dialog + "contextMenuDlg" : ( + "Rubriques des menus contextuels", + "OptionenindenKontextmenus", + "Polozkykontextovehamenu"), + + # file->exit menu option + "File->Exit" : ( + "Fichier->Quitter", + "Datei->Beenden", + "Soubor->Konec"), } def get_winrar_dlgs(rar_dlg, x): - rar_dlg.MenuSelect(t["Options->Configure"][x]) - - optionsdlg = rar_dlg.app[t['Configure'][x]] - optionsdlg._write("Options_%d.xml"%x) - optionsdlg.CaptureAsImage().save("Options_%d.png"%x) - optionsdlg[t['Buttons'][x]].Click() - - contextMenuDlg = rar_dlg.app[t['PeronnaliseToolbars'][x]] - contextMenuDlg._write("PersonaliseToolbars_%d.xml"%x) - contextMenuDlg.CaptureAsImage().save("PersonaliseToolbars_%d.png"%x) - contextMenuDlg.OK.Click() + rar_dlg.MenuSelect(t["Options->Configure"][x]) + + optionsdlg = rar_dlg.app[t['Configure'][x]] + optionsdlg._write("Options_%d.xml"%x) + optionsdlg.CaptureAsImage().save("Options_%d.png"%x) + optionsdlg[t['Buttons'][x]].Click() + + contextMenuDlg = rar_dlg.app[t['PeronnaliseToolbars'][x]] + contextMenuDlg._write("PersonaliseToolbars_%d.xml"%x) + contextMenuDlg.CaptureAsImage().save("PersonaliseToolbars_%d.png"%x) + contextMenuDlg.OK.Click() + + optionsdlg.TabCtrl.Select(1) + optionsdlg[t['CreateDefaultProfile'][x]].Click() + + defaultOptionsDlg = rar_dlg.app[t['ConfigureDefaultOptions'][x]] + defaultOptionsDlg._write("DefaultOptions_%d.xml"%x) + defaultOptionsDlg.CaptureAsImage().save("DefaultOptions_%d.png"%x) + defaultOptionsDlg.OK.Click() + + optionsdlg.TabCtrl.Select(6) + optionsdlg[t['ContextMenus'][x]].Click() + + anotherMenuDlg = rar_dlg.app[t['contextMenuDlg'][x]] + anotherMenuDlg._write("2ndMenuDlg_%d.xml"%x) + anotherMenuDlg.CaptureAsImage().save("2ndMenuDlg_%d.png"%x) + + anotherMenuDlg.OK.Click() + + optionsdlg.OK.Click() + - optionsdlg.TabCtrl.Select(1) - optionsdlg[t['CreateDefaultProfile'][x]].Click() - - defaultOptionsDlg = rar_dlg.app[t['ConfigureDefaultOptions'][x]] - defaultOptionsDlg._write("DefaultOptions_%d.xml"%x) - defaultOptionsDlg.CaptureAsImage().save("DefaultOptions_%d.png"%x) - defaultOptionsDlg.OK.Click() - - optionsdlg.TabCtrl.Select(6) - optionsdlg[t['ContextMenus'][x]].Click() - - anotherMenuDlg = rar_dlg.app[t['contextMenuDlg'][x]] - anotherMenuDlg._write("2ndMenuDlg_%d.xml"%x) - anotherMenuDlg.CaptureAsImage().save("2ndMenuDlg_%d.png"%x) - - anotherMenuDlg.OK.Click() - - optionsdlg.OK.Click() - - # get the languages as an integer x = int(sys.argv[1]) @@ -148,4 +149,5 @@ rar_dlg = app._window(title_re = ".* - WinRAR.*") get_winrar_dlgs(rar_dlg, x) # exit WinRar +time.sleep(.5) rar_dlg.MenuSelect(t['File->Exit'][x]) diff --git a/examples/windowmediaplayer.py b/examples/windowmediaplayer.py index cbdd841..b75729a 100644 --- a/examples/windowmediaplayer.py +++ b/examples/windowmediaplayer.py @@ -1,70 +1,79 @@ # GUI Application automation and testing library # Copyright (C) 2006 Mark Mc Mahon # -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public License -# as published by the Free Software Foundation; either version 2.1 +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 # of the License, or (at your option) any later version. # -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the # Free Software Foundation, Inc., # 59 Temple Place, -# Suite 330, -# Boston, MA 02111-1307 USA +# Suite 330, +# Boston, MA 02111-1307 USA + +"Some automation of Windows Media player" + +__revision__ = "$Revision$" + #import os import time +import sys from pywinauto import application -from pywinauto import tests - - def WindowsMedia(): - - app = application.Application() - app._connect(path = ur"C:\Program Files\Windows Media Player\wmplayer.exe") - - app.WindowsMediaPlayer.MenuSelect("View->GoTo->Library") - app.WindowsMediaPlayer.MenuSelect("View->Choose Columns") - - for ctrl in app.ChooseColumns.Children: - print ctrl.Class - - - print "Is it checked already:", app.ChooseColumsn.ListView.IsChecked(1) - - # Check an Item in the listview - app.ChooseColumns.ListView.Check(1) - time.sleep(.5) - print "Shold be checked now:", app.ChooseColumsn.ListView.IsChecked(1) + app = application.Application() - # Uncheck it - app.ChooseColumns.ListView.UnCheck(1) - time.sleep(.5) - print "Should not be checked now:", app.ChooseColumsn.ListView.IsChecked(1) + try: + app._connect( + path = ur"C:\Program Files\Windows Media Player\wmplayer.exe") + except application.ProcessNotFoundError: + print "You must first start Windows Media "\ + "Player before running this script" + sys.exit() - # Check it again - app.ChooseColumns.ListView.Check(1) - time.sleep(.5) - - app.ChooseColumsn.Cancel.Click() + app.WindowsMediaPlayer.MenuSelect("View->GoTo->Library") + app.WindowsMediaPlayer.MenuSelect("View->Choose Columns") + + for ctrl in app.ChooseColumns.Children: + print ctrl.Class + + + print "Is it checked already:", app.ChooseColumsn.ListView.IsChecked(1) + + # Check an Item in the listview + app.ChooseColumns.ListView.Check(1) + time.sleep(.5) + print "Shold be checked now:", app.ChooseColumsn.ListView.IsChecked(1) + + # Uncheck it + app.ChooseColumns.ListView.UnCheck(1) + time.sleep(.5) + print "Should not be checked now:", app.ChooseColumsn.ListView.IsChecked(1) + + # Check it again + app.ChooseColumns.ListView.Check(1) + time.sleep(.5) + + app.ChooseColumsn.Cancel.Click() def Main(): - start = time.time() - - WindowsMedia() - - print "Total time taken:", time.time() - start + start = time.time() + + WindowsMedia() + + print "Total time taken:", time.time() - start if __name__ == "__main__": - Main() \ No newline at end of file + Main() \ No newline at end of file