简体   繁体   English

UIAutomation和远程桌面连接

[英]UIAutomation and Remote Desktop Connections

I have an application that does some automation on an arbitrary Windows application. 我有一个应用程序在任意Windows应用程序上执行一些自动化。 I've been using Notepad to test it. 我一直在使用记事本来测试它。

During this automation, I have to invoke events from the code. 在这种自动化过程中,我必须从代​​码中调用事件。 I currently support two types of events since they seem to be the most common, InvokePattern and ExpandCollapsePattern . 我目前支持两种类型的事件,因为它们似乎是最常见的InvokePatternExpandCollapsePattern

I use a computer that I can remote desktop into to do the testing. 我使用可以远程桌面进入测试的计算机。 But it's weird. 但这很奇怪。 When I'm connected to the computer through Remote Desktop, the application works fine. 当我通过远程桌面连接到计算机时,应用程序正常工作。 When I disconnect from the computer, my code stops working for the ExpandCollapsePattern (InvokePattern works fine). 当我从计算机断开连接时,我的代码停止为ExpandCollapsePattern工作(InvokePattern工作正常)。 I get an InvalidOperationException. 我得到一个InvalidOperationException。

The documentation says that this should only be thrown if the node is marked as a LeafNode. 文档说只有在节点被标记为LeafNode时才会抛出此内容。 What makes Remote Desktop different that I'm getting the InvalidOperationException? 是什么让远程桌面与我获得InvalidOperationException不同?

Here is the code I currently have to perform the event. 这是我目前执行该事件的代码。

ExpandCollapseState state =
    patternMenu.Current.ExpandCollapseState;
if (state == ExpandCollapseState.Expanded)
    patternMenu.Collapse();
else if (state == ExpandCollapseState.PartiallyExpanded ||
         state == ExpandCollapseState.Collapsed)
    patternMenu.Expand();

patternMenu is an ExpandCollapsePattern gotten from the AutomationElement using GetCurrentPattern. patternMenu是使用GetCurrentPattern从AutomationElement获取的ExpandCollapsePattern。

The current value of ExpandCollapseState is "Collapsed" when I print out the value. 打印出值时,ExpandCollapseState的当前值为“Collapsed”。

EDIT: Any chance I can know why I got a downvote and how this is a bad question? 编辑:我有机会知道为什么我有一个downvote,这是一个坏问题? I'm genuinely confused of what's happening, as it only seems to fail when remote desktop is closed. 我对发生的事情感到非常困惑,因为当远程桌面关闭时它似乎只会失败。 If this is a really dumb question that I should know the answer to, I'd love an explanation and then a downvote. 如果这是一个非常愚蠢的问题,我应该知道答案,我会喜欢一个解释,然后是一个downvote。

The process that interacts with the desktop isn't a Windows service. 与桌面交互的进程不是Windows服务。 It's an application I start after I remote desktop into the computer. 这是我将远程桌面插入计算机后启动的应用程序。 Is it because I'm locking the desktop? 是因为我锁定了桌面吗?

I'm using "Terminal Server Client" on Ubuntu to log into the Windows machine. 我在Ubuntu上使用“终端服务器客户端”登录Windows机器。 Does pressing the close button on this application cause the desktop to lock? 按此应用程序上的关闭按钮会导致桌面锁定吗?

Generally speaking, you can't typically run UI Automation or similar on a non-interactive desktop. 一般来说,您通常无法在非交互式桌面上运行UI Automation或类似工具。 Non-interactive desktops have various limitations regarding input: there's no focused element, input can't be sent, so anything that depends on these will fail. 非交互式桌面在输入方面有各种限制:没有聚焦元素,无法发送输入,因此依赖于这些内容的任何内容都将失败。

Some functionality, such as sending windows messages, will work fine. 某些功能(如发送Windows消息)可以正常工作。 What might be happening here is that the InvokePattern functionality is implemented under the covers as messages, so still works; 这里可能发生的是InvokePattern功能作为消息在封面下实现,因此仍然有效; but the Expand/Collapse might be implemented in terms of input, which would fail. 但是扩展/折叠可能会根据输入实现,这会失败。

Not clear why, in your case, it fails when you close the client (that part is expected), but appears to work when the remote desktop locks itself - would it expect to behave the same in both cases. 不清楚为什么,在您的情况下,当您关闭客户端(该部分是预期的)时它会失败,但是当远程桌面锁定自身时似乎工作 - 它会在两种情况下都表现出相同的行为。

(Note that if the local Ubuntu desktop locks, all should be fine and still work, so long as the client still running. The remote client is still 'interactive' in that case, since it's got a live client attached to it, regardless of whether the client itself is running on an interactive or non-interactive desktop - the concepts may not even apply to a client running on another OS!) (请注意,如果本地 Ubuntu桌面锁定,只要客户端仍在运行,一切都应该没问题。在这种情况下,远程客户端仍然是“交互式的”,因为它有一个连接到它的实时客户端,无论客户端本身是在交互式还是非交互式桌面上运行 - 这些概念甚至可能不适用于在另一个操作系统上运行的客户端!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM