How to use the uiautomation.Logger function in uiautomation

To help you get started, we’ve selected a few uiautomation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()

    wiresharkWindow.SetActive(waitTime=0.1)
    wiresharkWindow.Maximize()
    auto.Logger.ColorfullyWriteLine('Press F1 to stop', auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4, ClassName='PacketList', Name='Packet list')
    rect = tree.BoundingRectangle
    tree.Click(y=50, waitTime=0.1)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_devicemanager.py View on Github external
cmdTransformPattern.Resize(sw // 2, sh * 3 // 4)
    subprocess.Popen('mmc.exe devmgmt.msc')
    mmcWindow = auto.WindowControl(searchDepth = 1, ClassName = 'MMCMainFrame')
    mmcTransformPattern = mmcWindow.GetTransformPattern()
    mmcTransformPattern.Move(0, 0)
    mmcTransformPattern.Resize(sw // 2, sh * 3 // 4)
    tree = mmcWindow.TreeControl()
    for item, depth in auto.WalkControl(tree, includeTop=True):
        if isinstance(item, auto.TreeItemControl):  #or item.ControlType == auto.ControlType.TreeItemControl
            item.GetSelectionItemPattern().Select(waitTime=0.05)
            pattern = item.GetExpandCollapsePattern()
            if pattern.ExpandCollapseState == auto.ExpandCollapseState.Collapsed:
                pattern.Expand(waitTime=0.05)
            auto.Logger.WriteLine(' ' * (depth - 1) * 4 + item.Name, auto.ConsoleColor.Green)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll by SetScrollPercent')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime=1)
    treeScrollPattern = tree.GetScrollPattern()
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 0)
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 100)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to top by SendKeys Ctrl+Home')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime = 1)
    tree.SendKeys('{Ctrl}{Home}', waitTime = 1)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to bottom by SendKeys Ctrl+End')
        cmdWindow.SetActive(waitTime = 1)
    mmcWindow.SetActive(waitTime = 1)
    tree.SendKeys('{Ctrl}{End}', waitTime = 1)
    if cmdWindow:
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_notepad.py View on Github external
def testNotepadEN():
    consoleWindow = auto.GetConsoleWindow()
    consoleWindow.SetActive()
    auto.Logger.ColorfullyWriteLine('\nI will open Notepad and automate it. Please wait for a while.')
    time.sleep(2)
    auto.ShowDesktop()
    subprocess.Popen('notepad')
    #search notepad window, if searchFromControl is None, search from RootControl
    #searchDepth = 1 makes searching faster, only searches RootControl's children, not children's children
    window = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad', RegexName = '.* - Notepad')
    #if window.Exists(maxSearchSeconds = 3): #check before using it
    if auto.WaitForExist(window, 3):
        auto.Logger.WriteLine("Notepad exists now")
    else:
        auto.Logger.WriteLine("Notepad does not exist after 3 seconds", auto.ConsoleColor.Yellow)
    screenWidth, screenHeight = auto.GetScreenSize()
    window.MoveWindow(screenWidth // 4, screenHeight // 4, screenWidth // 2, screenHeight // 2)
    window.SetActive()
    edit = auto.EditControl(searchFromControl = window)  #or edit = window.EditControl()
    edit.Click(waitTime = 0)
    edit.GetValuePattern().SetValue('hi你好')
    edit.SendKeys('{Ctrl}{End}{Enter}下面开始演示{! 4}{ENTER}', 0.2, 0)
    edit.SendKeys(text)
    edit.SendKeys('{Enter 3}0123456789{Enter}', waitTime = 0)
    edit.SendKeys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{Enter}', waitTime = 0)
    edit.SendKeys('abcdefghijklmnopqrstuvwxyz{Enter}', waitTime = 0)
    edit.SendKeys('`~!@#$%^&*()-_=+{Enter}', waitTime = 0)
    edit.SendKeys('[]{{}{}}\\|;:\'\",<.>/?{Enter}{Ctrl}a')
    window.CaptureToImage('Notepad.png')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
packet.Info = info
                            if info.find(payloadStr) >= 0:
                                packet = copy.copy(packet)
                                startIndex = info.find('Seq=')
                                if startIndex > 0:
                                    endIndex = info.find(' ', startIndex)
                                    packet.Seq = int(info[startIndex+4:endIndex].rstrip(','))
                                startIndex = info.find('Time=', startIndex)
                                if startIndex > 0:
                                    endIndex = startIndex + 5 + 1
                                    while str.isdigit(info[startIndex+5:endIndex]) and endIndex <= len(info):
                                        packet.TimeStamp = int(info[startIndex+5:endIndex])
                                        endIndex += 1
                                    if packet.No >= beginNo:
                                        packets.append(packet)
                                        automation.Logger.WriteLine('No: {0[No]:<10}, Time: {0[Time]:<10}, Protocol: {0[Protocol]:<6}, Length: {0[Length]:<6}, Info: {0[Info]:<10},'.format(packet.__dict__))
                    index = (index + 1) % len(headers)
    AnalyzePackets(packets, sampleRate, showLost)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / collapse_tree_item_under_cursor.py View on Github external
def HotKeyFunc(stopEvent: 'Event', argv: list):
    args = [sys.executable, __file__] + argv
    cmd = ' '.join('"{}"'.format(arg) for arg in args)
    auto.Logger.WriteLine('call {}'.format(cmd))
    p = subprocess.Popen(cmd)
    while True:
        if None != p.poll():
            break
        if stopEvent.is_set():
            childProcesses = [pro for pro in psutil.process_iter() if pro.ppid == p.pid or pro.pid == p.pid]
            for pro in childProcesses:
                auto.Logger.WriteLine('kill process: {}, {}'.format(pro.pid, pro.cmdline()), auto.ConsoleColor.Yellow)
                p.kill()
            break
        stopEvent.wait(0.05)
    auto.Logger.WriteLine('HotKeyFunc exit')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
parser.add_argument('-b', '--begin', type = int, dest = 'beginNo', default = 0,
                      help = 'begin no')
    parser.add_argument('-n', '--num', type = int, dest = 'maxPacket', default = 0xFFFFFFFF,
                      help = 'read packets count')
    parser.add_argument('-l', '--lostseq', action='store_true', default = False,
                          help = 'show lost seq')
    args = parser.parse_args()
    cmdWindow = automation.GetConsoleWindow()
    if cmdWindow:  #if run by a debugger, maybe no console window
        cmdWindow.SetTopmost()
    if 0 == args.sampleRate:
        args.sampleRate = int(input('please input sample rate(e.g. 8000 for Audio, 90000 for Video): '))
        if args.sampleRate == 90000:
            automation.Logger.SetLogFile('@analyze_video_result.txt')
        else:
            automation.Logger.SetLogFile('@analyze_audio_result.txt')
        automation.Logger.DeleteLog()
    if 0 == args.payload:
        args.payload = int(input('please input playload type(e.g. 97 for Audio, 96 for Video): '))
    if args.file:
        AnalyzeCsvFile(args.file, args.sampleRate, args.payload, args.beginNo, args.maxPacket, args.lostseq)
    else:
        AnalyzeUI(args.sampleRate, args.payload, args.beginNo, args.maxPacket, args.lostseq)
    if cmdWindow:
        cmdWindow.SetActive()
    input('press enter to exit')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_firefox.py View on Github external
newTab = tab.TabItemControl(SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    newTab.Click()
    starButton = firefoxWindow.ButtonControl(Name = 'Star this repository')
    if starButton.Exists(5):
        automation.GetConsoleWindow().SetActive()
        automation.Logger.WriteLine('Star Python-UIAutomation-for-Windows after 2 seconds', automation.ConsoleColor.Yellow)
        time.sleep(2)
        firefoxWindow.SetActive()
        time.sleep(1)
        starButton.Click()
        time.sleep(2)
    else:
        unstarButton = firefoxWindow.ButtonControl(Name = 'Unstar this repository')
        if unstarButton.Exists(0, 0):
            automation.GetConsoleWindow().SetActive()
            automation.Logger.WriteLine('Thank you. You have starred.', automation.ConsoleColor.Yellow)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
help = 'begin no')
    parser.add_argument('-n', '--num', type = int, dest = 'maxPacket', default = 0xFFFFFFFF,
                      help = 'read packets count')
    parser.add_argument('-l', '--lostseq', action='store_true', default = False,
                          help = 'show lost seq')
    args = parser.parse_args()
    cmdWindow = automation.GetConsoleWindow()
    if cmdWindow:  #if run by a debugger, maybe no console window
        cmdWindow.SetTopmost()
    if 0 == args.sampleRate:
        args.sampleRate = int(input('please input sample rate(e.g. 8000 for Audio, 90000 for Video): '))
        if args.sampleRate == 90000:
            automation.Logger.SetLogFile('@analyze_video_result.txt')
        else:
            automation.Logger.SetLogFile('@analyze_audio_result.txt')
        automation.Logger.DeleteLog()
    if 0 == args.payload:
        args.payload = int(input('please input playload type(e.g. 97 for Audio, 96 for Video): '))
    if args.file:
        AnalyzeCsvFile(args.file, args.sampleRate, args.payload, args.beginNo, args.maxPacket, args.lostseq)
    else:
        AnalyzeUI(args.sampleRate, args.payload, args.beginNo, args.maxPacket, args.lostseq)
    if cmdWindow:
        cmdWindow.SetActive()
    input('press enter to exit')
github yinkaisheng / Python-UIAutomation-for-Windows / automation.py View on Github external
def usage():
    Logger.ColorfulWrite("""usage
-h      show command help
-t      delay time, default 3 seconds, begin to enumerate after Value seconds, this must be an integer
        you can delay a few seconds and make a window active so automation can enumerate the active window
-d      enumerate tree depth, this must be an integer, if it is null, enumerate the whole tree
-r      enumerate from root:desktop window, if it is null, enumerate from foreground window
-f      enumerate from focused control, if it is null, enumerate from foreground window
-c      enumerate the control under cursor, if depth is < 0, enumerate from its ancestor up to depth
-a      show ancestors of the control under cursor
-n      show control full name
-m      show more properties

if UnicodeError or LookupError occurred when printing,
try to change the active code page of console window by using chcp or see the log file @AutomationLog.txt
chcp, get current active code page
chcp 936, set active code page to gbk
chcp 65001, set active code page to utf-8