使用 Appium 驱动处理自己 UI 的 Win32 c++ 应用程序

问题描述

我们有一个 win32 windows 应用程序,它创建窗口并(主要)处理自己的 UI。

它通过使用 RegisterClass 向 windows 注册 windows 类并使用 CreateWindowEx 创建 windows 来实现这一点。

然后我们处理 Windows 消息并控制 WndProc 方法中的所有交互,例如使用 WM_PAINT 将事物绘制到屏幕上并处理 WM_MBUTTONDOWN 等。

我可以很高兴地使用 Appium 和 WinAppDriver 来启动和关闭应用程序,但(不出所料)它没有报告任何应用程序源或元素树供我定位和自动化。

下面是我的应用程序在 appium 桌面打开并在检查器中查看的示例。

Example of my application opened by appium desktop and viewed in the inspector

是否可以在我的应用程序中编写一些代码,告知 Appium(以及任何其他与此相关的辅助工具)我的应用程序包含哪些内容,以便最终我自己处理 webdriver 命令?

更新:

如果我在 Appium 检查器中使用复制到 xml 到剪贴板,则源可用。有了这些知识,我可以定位窗口知道的项目(例如关闭交叉和两个编辑框),而不是我自己绘制和处理的项目(例如确定和取消)。我不知道为什么 App Source 没有出现在 Appium 中。

以下示例来源:

<?xml version="1.0" encoding="utf-16"?>
<Window AcceleratorKey=""
        AccessKey=""
        AutomationId=""
        ClassName="WFL32WNDCLASS"
        FrameworkId="Win32"
        HasKeyboardFocus="False"
        HelpText=""
        IsContentElement="True"
        IsControlElement="True"
        IsEnabled="True"
        IsKeyboardFocusable="True"
        IsOffscreen="False"
        IsPassword="False"
        IsrequiredForForm="False"
        ItemStatus=""
        ItemType=""
        LocalizedControlType="window"
        Name="User Login"
        Orientation="None"
        ProcessId="21356"
        RuntimeId="42.1181526"
        x="0"
        y="0"
        width="402"
        height="255"
        CanMaximize="False"
        CanMinimize="True"
        IsModal="False"
        WindowVisualState="normal"
        WindowInteractionState="ReadyForUserInteraction"
        IsTopmost="False"
        CanRotate="False"
        CanResize="False"
        CanMove="True"
        IsAvailable="True">
    <Edit AcceleratorKey=""
            AccessKey=""
            AutomationId="55"
            ClassName="Edit"
            FrameworkId="Win32"
            HasKeyboardFocus="False"
            HelpText=""
            IsContentElement="True"
            IsControlElement="True"
            IsEnabled="True"
            IsKeyboardFocusable="True"
            IsOffscreen="False"
            IsPassword="False"
            IsrequiredForForm="False"
            ItemStatus=""
            ItemType=""
            LocalizedControlType="edit"
            Name=""
            Orientation="None"
            ProcessId="21356"
            RuntimeId="42.984996"
            x="78"
            y="139"
            width="254"
            height="13" />
    <Edit AcceleratorKey=""
            AccessKey=""
            AutomationId="55"
            ClassName="Edit"
            FrameworkId="Win32"
            HasKeyboardFocus="True"
            HelpText=""
            IsContentElement="True"
            IsControlElement="True"
            IsEnabled="True"
            IsKeyboardFocusable="True"
            IsOffscreen="False"
            IsPassword="True"
            IsrequiredForForm="False"
            ItemStatus=""
            ItemType=""
            LocalizedControlType="edit"
            Name=""
            Orientation="None"
            ProcessId="21356"
            RuntimeId="42.3212740"
            x="78"
            y="160"
            width="254"
            height="13" />
    <TitleBar AcceleratorKey=""
                AutomationId=""
                ClassName=""
                FrameworkId=""
                HasKeyboardFocus="False"
                IsContentElement="False"
                IsControlElement="True"
                IsEnabled="True"
                IsKeyboardFocusable="True"
                IsOffscreen="False"
                IsPassword="False"
                IsrequiredForForm="False"
                ItemStatus=""
                ItemType=""
                LocalizedControlType="title bar"
                Orientation="None"
                ProcessId="21356"
                RuntimeId="42.1181526.3.-2147483647.1181526.-2.0"
                x="0"
                y="3"
                width="402"
                height="28">
        <Button AcceleratorKey=""
                AutomationId=""
                ClassName=""
                FrameworkId=""
                HasKeyboardFocus="False"
                IsContentElement="False"
                IsControlElement="True"
                IsEnabled="True"
                IsKeyboardFocusable="False"
                IsOffscreen="True"
                IsPassword="False"
                IsrequiredForForm="False"
                ItemStatus=""
                ItemType=""
                LocalizedControlType="button"
                Name="Minimize"
                Orientation="None"
                ProcessId="21356"
                RuntimeId="42.1181526.3.-2147483647.1181526.-2.2"
                x="-34"
                y="-26"
                width="0"
                height="0" />
        <Button AcceleratorKey=""
                AutomationId=""
                ClassName=""
                FrameworkId=""
                HasKeyboardFocus="False"
                IsContentElement="False"
                IsControlElement="True"
                IsEnabled="False"
                IsKeyboardFocusable="False"
                IsOffscreen="True"
                IsPassword="False"
                IsrequiredForForm="False"
                ItemStatus=""
                ItemType=""
                LocalizedControlType="button"
                Name="Maximize"
                Orientation="None"
                ProcessId="21356"
                RuntimeId="42.1181526.3.-2147483647.1181526.-2.3"
                x="-34"
                y="-26"
                width="0"
                height="0" />
        <Button AcceleratorKey=""
                AutomationId=""
                ClassName=""
                FrameworkId=""
                HasKeyboardFocus="False"
                IsContentElement="False"
                IsControlElement="True"
                IsEnabled="True"
                IsKeyboardFocusable="False"
                IsOffscreen="False"
                IsPassword="False"
                IsrequiredForForm="False"
                ItemStatus=""
                ItemType=""
                LocalizedControlType="button"
                Name="Close"
                Orientation="None"
                ProcessId="21356"
                RuntimeId="42.1181526.3.-2147483647.1181526.-2.5"
                x="381"
                y="7"
                width="21"
                height="21" />
    </TitleBar>
</Window>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)