简体   繁体   中英

C# GUI testing from Continuous Integration

I have a WPF application and a set of GUI unit tests. 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). If I tell the mouse to move and then check its position, it's still (0,0).

We have the service running with "Allow service to interact with desktop" checked, and Environment.UserInteractive is true.

Also, if I start a test run locally and then lock my screen, the mouse has the same behavior (position always 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.

Here is what I think is happening. Your service runs in Session 0, which is the non-interactive session. So the mouse effectively doesn't exist there.

When you lock your desktop, Windows switches to the WinLogon desktop and steals the mouse. Your application running on your normal desktop no long has a mouse to play with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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