get_winrar_info.py :  » GUI » Python-Win32-GUI-Automation » pywinauto-0.4.0 » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Python Win32 GUI Automation 
Python Win32 GUI Automation » pywinauto 0.4.0 » examples » get_winrar_info.py
"""Automate WinRAR evaluation copy

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

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

from pywinauto.application import Application
import time

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'
    ),

    # Buy Licence Dialog
    'Buy Licence' : (
        "Acheter une licence pur winRAR",
        "Bittekaufensieeine",
        "Zakuptesiprosmlicenci WinRARu"),
    'Close' : (
        "Fermer",
        "Schleissen",
        "Zavrit"),

    # Options->Configure menu items
    "Options->Configure" : (
        "Options->Configuration",
        "Optionen->Einstellungen",
        "Moznosti->Nastaveni"),

    # Configure/Options dialog box
    'Configure' : (
        "Configuration",
        "Einstellungen",
        "Nastaveni"),

    # personalise toolbar buttons button
    'Buttons' : (
        "Boutons",
        "Schaltflachen",
        "Vybrattlacitka"),

    # Personalize toolbars dialog
    'PeronnaliseToolbars' : (
        "Peronnalisation de la barre doutils",
        "Werkzeugleisteanpassen",
        "Vybertlaciteknastrojovelisty"),

    # create profile button
    'CreateDefaultProfile' : (
        u"Creerleprofilpardfault",
        "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, app, lang):
    rar_dlg.MenuSelect(t["Options->Configure"][lang])

    optionsdlg = app[t['Configure'][lang]]

    optionsdlg.WriteToXML("Options_%d.xml"%lang)

    optionsdlg.CaptureAsImage().save("Options_%d.png"%lang)
    optionsdlg[t['Buttons'][lang]].Click()

    contextMenuDlg = app[t['PeronnaliseToolbars'][lang]]
    contextMenuDlg.WriteToXML("PersonaliseToolbars_%d.xml"%lang)
    contextMenuDlg.CaptureAsImage().save("PersonaliseToolbars_%d.png"%lang)
    contextMenuDlg.OK.Click()

    optionsdlg.TabCtrl.Select(1)
    optionsdlg[t['CreateDefaultProfile'][lang]].Click()

    defaultOptionsDlg = app[t['ConfigureDefaultOptions'][lang]]
    defaultOptionsDlg.WriteToXML("DefaultOptions_%d.xml"%lang)
    defaultOptionsDlg.CaptureAsImage().save("DefaultOptions_%d.png"%lang)
    defaultOptionsDlg.OK.Click()

    optionsdlg.TabCtrl.Select(6)
    optionsdlg[t['ContextMenus'][lang]].Click()

    anotherMenuDlg = app[t['contextMenuDlg'][lang]]
    anotherMenuDlg.WriteToXML("2ndMenuDlg_%d.xml"%lang)
    anotherMenuDlg.CaptureAsImage().save("2ndMenuDlg_%d.png"%lang)

    anotherMenuDlg.OK.Click()

    optionsdlg.OK.Click()


# get the languages as an integer
langs = [int(arg) for arg in sys.argv[1:]]

for lang in langs:
    # start the application
    app = Application().start_(t['apppath'][lang])

    # we have to wait for the Licence Dialog to open
    time.sleep(2)

    # close the Buy licence dialog box
    licence_dlg = app[t['Buy Licence'][lang]]
    licence_dlg[t['Close'][lang]].Click()

    # find the WinRar main dialog
    rar_dlg = app.window_(title_re = ".* - WinRAR.*")

    # dump and capture some dialogs
    get_winrar_dlgs(rar_dlg, app,  lang)

    # exit WinRar
    time.sleep(.5)
    rar_dlg.MenuSelect(t['File->Exit'][lang])
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.