DCSIMG
Running CodedUI Test From Another Application - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

Running CodedUI Test From Another Application

Running CodedUI Test From Another Application

As Coded UI Testing become a very powerful and easy UI Testing there is lots of questions regarding using it in various ways, for example : how can I run CodedUI Test from WinForm application???

So the answer is very easy:

Step 1

Create new WinForm application, and add reference to the below assemblies:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\

  • Microsoft.VisualStudio.TestTools.UITesting.dll
  • Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\image

  • Microsoft.VisualStudio.TestTools.UITest.CodeGeneration.dll
  • Microsoft.VisualStudio.TestTools.UITest.Framework.dll
  • Microsoft.VisualStudio.TestTools.UITest.Playback.dll

Make sure you change Winform target framework to full 4.0 and not 4 Client Profile.

Step 2

Add the code calling your test project and executing you Test method.

TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();
coded.CodedUITestMethod1();
Here you will see your CodedUI throws an error - Object reference not set to an instance of an object.
This is because you must run: Playback.Initialize(); before you starting your Test.
So the code should look like that:
Playback.Initialize();
TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();
coded.CodedUITestMethod1();
Playback.Cleanup();
And you’re Done!!!
image
Enjoy.

Comments

Twitter Trackbacks for Running CodedUI Test From Another Application - Shai Raiten [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Running CodedUI Test From Another Application - Shai Raiten         [microsoft.co.il]        on Topsy.com

# July 15, 2010 4:00 PM

Pia said:

Can I use the same to run a CUIT on a machine that does not have Visual Studio 2010? Rather I tried doing it, but get an exception- UITestControlNotFoundException, when actually I can see the control there.

# August 18, 2010 4:00 PM

sun said:

thanks very much

# October 6, 2010 1:13 PM

Shai Raiten said:

How To: Run Coded UI Tests From Command Line One of my previous posts about Coded UI I showed how to

# October 30, 2010 8:59 PM

daniel said:

I am getting the error when I try this example.

Microsoft.VisualStudio.TestTools.UITest.Extension.InvalidUITestExtensionPackageException: The following package failed to load:

D:\ChangeControl\Application\ScrptToolV2\CodedUILauncher\CodedUILauncher\bin\Debug\Microsoft.VisualStudio.TestTools.UITest.Extension.IE.dll

. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

# November 19, 2010 9:43 PM

TFS – Get Coded UI Test Results When Called From Another Application | Dark Storm Designs said:

Pingback from  TFS – Get Coded UI Test Results When Called From Another Application | Dark Storm Designs

# January 3, 2011 4:57 PM

Alon said:

I've build an app that runs coded ui tests via reflection. It works, however, it seems like TestContext is not initialized in that way.

Do you know how I can initialize it so it would function as usual?

Thanks.

# June 1, 2011 3:12 PM

Krishna Chaduvula said:

Can you please provide a sample Windows form that invokes the coded UI tests. I am getting a lot of errors while trying to run the tests.

My Steps:

Created Coded UI Tests

Created a Windows App targeting framework 4 as you specified

My Code in a button click event looks something like this

Playback.Initialize()

Dim Personal As New PersonalInformation()

Personal.PersonalInformationTests()

Playback.Cleanup()

# June 27, 2011 10:34 PM

Govind said:

I've installed the trial version of VS2010 Ultimate Edition but there was no 'Microsoft Visual Studio 10.0' folder in 'C:\Program Files'. There was only 'Microsoft Visual Studio 9.0' and it didn't contain any of the 5 DLLs mentioned in the Public/PrivateAssemblies folders.

Will the DLLs come only with a registered version?

Thanks.

# July 7, 2011 12:42 PM

shair said:

Hi Govind,

Are you using 64bit operation system?

If so, please look under Program File (x86)

# July 11, 2011 7:44 PM

Bogdan said:

Anybody has any ideea on this error?

Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform '' on the control. Additional Details: The control details were not specified. ---> System.Runtime.InteropServices.COMException:

Retrieving the COM class factory for component with CLSID {6DA215C2-D80D-42F2-A514-B44A16DCBAAA} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

  at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.InitPlayback()

  at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()

  --- End of inner exception stack trace ---

  at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)

  at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, IPlaybackContext context)

  at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()

# July 14, 2011 12:05 PM

Tony Tonev said:

I had to also add references to "Microsoft.VisualStudio.TestTools.UITest.Extension.IE" and "Microsoft.VisualStudio.TestTools.UITest.Extension.Uia" but otherwise, works great, thanks!

# July 27, 2011 10:54 PM

Tony Tonev said:

Yes, Bogdan, I'm getting the same exact error. Have you managed to resolve it? If so, please post the details.

Thanks,

Tony

# July 29, 2011 12:52 AM

shair said:

Hi,

Please make sure your Application sets to Framework 4.0 and not Client Profile.

Thanks

# July 29, 2011 8:21 AM

Prashanth said:

Hi,

I'm not able to add my testproject to the windows form application.I added my testproject to the solution and added reference of the same.Intellisense works fine before building the project, but application is throwing a error "are you missing any (testproject) assembly reference", once i build the application. Should i add any other reference??

# August 2, 2011 12:46 PM

VIshesh said:

Hi,

Thanks for this info, I have created the exe by using steps told by you.

1 more question...... Can I run this exe in other machine which don't have Visual Studio

# September 15, 2011 12:12 PM

Abhishek said:

Hi Shai,

Now I can run Coded UI thru windows form with the click of a button. Thanks for your help!!!

Now I have created an exe and trying to run the Coded UI thru an exe. On running the exe, the form is opening and after clicking the button (which calls the coded UI) it is throwing an exception error.

i.e.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

File name: 'Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Please help.

Thank you in Advance.

Regards

Abhishek

# October 11, 2011 6:57 PM

PIyush Sharma said:

Can you plz told the Namespace to call

because my solution has two projects

one is for CUIT

and

Secound is for Winform having a button (My Coded ui test)

when we paste your code : -

Playback.Initialize();

TestProject.CodedUITest1 coded = new TestProject.CodedUITest1();

coded.CodedUITestMethod1();

Playback.Cleanup();

they didnot identify the objects of Coded ui test project .. I paste this code on Click event of button

than it means they can't recognize .. will you pl help

# November 5, 2011 12:24 PM

ATE said:

Hello, first of all ... how can i call the CUIT mehtods ..

I add all 5 refrences ... but playback.initlize is not found in hint

on total nothing is work ... i done only at add refences to all dlls

# November 30, 2011 12:29 PM

Igal said:

I've some form with controls I'm practice on it .

the trigger for the UI test for this form is located on the form itself (link label). when I'm firing the Link Clicked event , the

Playback.Initialize();

test.CodedUITestMethod1();

Playback.Cleanup();

code should run, but actually happens is that my forms hangs (no exception), is this due to cross threading issue ?

# February 17, 2012 1:25 AM

MikeB said:

I'm having a problem with "Object reference not set to an instance of an object." exception on TestContect.DataRow.

I am using Playback.Initialize(); as suggested but still get that exception.

any ideas?

thank you

# March 6, 2012 7:09 PM

Laurie said:

Hello,

Thank you for your code.  I'm having trouble getting it to work.  I'm getting an error "Broswer not supported"  I added the line Playback.Initialize(), but that didn't change the result.

Do you have any ideas?

Thanks!

# March 17, 2012 5:12 AM

shair said:

Hi,

What type of browser you're running your coded ui testing on?

Thanks

# March 30, 2012 8:38 AM

Eric Bauersachs said:

Great info! I had to include Microsoft.VisualStudio.TestTools.UITest.Extension.IE and Microsoft.VisualStudio.TestTools.UITest.Extension.Uia, (two additional private assemblies) as well, but now my standalone Console Playback test tool works.

# June 18, 2012 1:21 PM

Markus said:

Thanks alot! I finally got this to work, thanks to this blog. :)

# August 20, 2012 11:57 AM

Lilit Yenokyan said:

Thank you! Great post, helped me A LOT, especially about including the necessary references and calling Playback.Initialize method before executing test methods.

# October 5, 2012 2:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: