2

Can we use Microsoft.VisualStudio.TestTools.UITesting.Mouse for automation purpose in a program (Is it possible to use it with our normal application cording. Not for the testing. )

I want to automate some mouse movements in my program. Like we are doing in Microsoft UI automation. I am not going to create a test project.

If this is possible please advice me.

Is mouse simulation is possible with UI automation?

EDIT
Since this is (Microsoft.VisualStudio.TestTools.UITesting.Mouse) used for coded UI testing I want to know is it possible to use in normal programming purpose. Because this Mouse class has some of useful methods which I need.

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
New Developer
  • 3,245
  • 10
  • 41
  • 78

2 Answers2

2

It may be technically possible to use it from an application. I believe all you need to do is make sure you call Playback.Initialize before using the Mouse class. However, I believe the license for VS will not allow you to redistribute the required dlls with your application.

UI Automation does not have facilities for low level input simulation.

I've use the TestApi project with some success to automate mouse and keyboard input when UI Automation and the Coded UI api's could not be used. It is easy to accomplish moving and clicking the mouse with the the Mouse class there:

using Microsoft.Test.Input;
using System.Drawing;

Mouse.MoveTo(new Point(100, 200));
Mouse.Click(MouseButton.Left);
Mike Zboray
  • 39,828
  • 3
  • 90
  • 122
  • Your answer is perfectly ok. I need another advice from you. When I tried to do this in .net 3.5, it says "The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft'", What assemble I need to add? – New Developer Dec 05 '12 at 09:38
  • @NewDeveloper Probably Microsoft.VisualStudio.TestTools.UITesting.dll which is in visual studio's install directory. Sommething like `C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies`. – Mike Zboray Dec 05 '12 at 17:07
1

Setting the mouse location is as simple as this :

System.Windows.Forms.Cursor.Position = new Point(x, y);

You can also send click messages through the message loop using some pinvoke calls.

I used this answer some time ago.

EDIT

As I thought, you wouldn't be able to distribute your application with the Coded UI libraries without an additional license :

How to run Coded UI Tests without Visual Studio 2010 Premium

Community
  • 1
  • 1
Kevin Coulombe
  • 1,517
  • 1
  • 17
  • 35
  • 1
    I want to know is it possible to use Microsoft.VisualStudio.TestTools.UITesting.Mouse in programming. Because this normally use for testing. – New Developer Dec 05 '12 at 07:30
  • 1
    We had some problems with deploying test code on our continuous integration server without installing Visual Studio on it. Unless I am wrong, these libraries are licensed with Visual Studio Premium and up only. You probably don't have the right to deploy it. http://msdn.microsoft.com/en-us/library/dd286726.aspx – Kevin Coulombe Dec 05 '12 at 07:39