简体   繁体   English

持续集成的C#GUI测试

[英]C# GUI testing from Continuous Integration

I have a WPF application and a set of GUI unit tests. 我有一个WPF应用程序和一组GUI单元测试。 These tests load the application and then move the mouse and click on things. 这些测试将加载应用程序,然后移动鼠标并单击内容。 This works fine if I run it while I'm logged in. 如果我在登录时运行它,则效果很好。

However, when the tests are running on our continuous integration server, the mouse always reports its position as (0,0). 但是,当测试在我们的持续集成服务器上运行时,鼠标始终将其位置报告为(0,0)。 If I tell the mouse to move and then check its position, it's still (0,0). 如果我告诉鼠标移动然后检查其位置,则它仍然是(0,0)。

We have the service running with "Allow service to interact with desktop" checked, and Environment.UserInteractive is true. 我们选中了“允许服务与桌面交互”运行的服务,并且Environment.UserInteractive为true。

Also, if I start a test run locally and then lock my screen, the mouse has the same behavior (position always 0,0). 另外,如果我在本地启动测试运行然后锁定屏幕,则鼠标具有相同的行为(位置始终为0,0)。

How can I use the mouse while running as a service? 服务运行时如何使用鼠标?

I think this article can shed some light on why your application isn't getting the mouse position you are expecting. 我认为本文可以阐明为什么您的应用程序没有达到您期望的鼠标位置。 I assume you are running your tests on Vista and Later. 我假设您正在Vista和更高版本上运行测试。

Here is what I think is happening. 我认为这是正在发生的事情。 Your service runs in Session 0, which is the non-interactive session. 您的服务在会话0(非交互式会话)中运行。 So the mouse effectively doesn't exist there. 因此,鼠标实际上在那里不存在。

When you lock your desktop, Windows switches to the WinLogon desktop and steals the mouse. 当您锁定桌面时,Windows将切换到WinLogon桌面并窃取鼠标。 Your application running on your normal desktop no long has a mouse to play with. 在普通桌面上运行的应用程序不再需要使用鼠标。

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

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