1

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?

5
  • How were these UI tests created? Coded UI? And what are you using for your CI server? Commented Mar 8, 2012 at 17:09
  • The UI tests just start our app and then use System.Windows.Forms.Cursor.Position and user32.dll to move and click the mouse. CI uses Pulse but that just starts the tests from command line. Commented Mar 8, 2012 at 17:16
  • Look into using an actual UI testing framework like Coded UI for your UI tests. How are you even verifying that the tests pass or fail? Commented Mar 8, 2012 at 17:42
  • It's MSTest. Looking into Coded UI I found this: msdn.microsoft.com/en-us/library/ee291332.aspx which seems to indicate I need to run as a process instead of a service. But I am not sure how to do that from the CI server. Commented Mar 8, 2012 at 18:45
  • Have a look at PsExec. It has the added benefit of letting you launch apps into specific sessions. Commented Mar 8, 2012 at 21:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.