1
votes

I am new to Coded UI Project. I recorded simple steps that interact with Calculator application. While running the test within Test Explorer works fine whereas while running the test from another Console Project throws error. I read from a question thread that

Playback.Initialize();
//Call Coded UI test Method
Playback.Cleanup(); 

the above is the format to call any coded ui test method from other project types viz., Console or Windows. I included below dll references as well.

Microsoft.VisualStudio.QualityTools.UnitTestFramework
Microsoft.VisualStudio.TestTools.UITest.Common
Microsoft.VisualStudio.TestTools.UITest.Extension
Microsoft.VisualStudio.TestTools.UITest.Extension.IE
Microsoft.VisualStudio.TestTools.UITest.Framework
Microsoft.VisualStudio.TestTools.UITest.Logging
Microsoft.VisualStudio.TestTools.UITest.Playback
Microsoft.VisualStudio.TestTools.UITest.UITesting

I am getting Type.Initialization.Exception while executing Playback.Initialize() method. I am using Visual Studio 2013.

Here is the complete exception information

An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.VisualStudio.TestTools.UITesting.dll

Additional information: The type initializer for 'Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities' threw an exception.

{"The type initializer for 'Microsoft.VisualStudio.TestTools.UITest.Extension.UITestUtilities' threw an exception."}
2
What is the entire exception message, what have tried so far to find the fault and what have you found out? - AdrianHHH
@Rasool Mohammed, please explain what you're trying to achieve by running the test from console project? - Arun M
Hello @AdrianHHH I updated my question with complete Exception Information. If you could need more information, please share your mail ID, so that I can send my solution workspace to you. - Rasool Mohammed
Hello @ArunM In our organization we have an in-house Automation Framework built on top of STAF with the help of C#. I need to write Automation Test cases using Coded UI and have to call the test case execution from another console or class library project. This is my need. Please let me you if you need any other information. - Rasool Mohammed

2 Answers

1
votes

I just had the same Trouble in Visual Studio 2015. The inner Reference said that Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility could not be found.

Adding it atleast fixes this Exception.

0
votes

Coded UI scripts can not drive/execute by Console project.

You should run CodedUI scripts or project from Unit Test or Coded UI test project only.

You should run coded UI Scripts (project) from either Unit Test project or Coded UI Test project. If you are using Unit Test Project then You need to Add the following references-

  • Microsoft.VisualStudio.QualityTools.CodedUITestFramework

  • Microsoft.VisualStudio.QualityTools.UnitTestFramework

  • Microsoft.VisualStudio.QualityTools.UItest.Common

  • Microsoft.VisualStudio.QualityTools.UITest.Extension

because to run the coded UI test or execute coded UI scripts, we required Coded UI Test runner. Also CodedUi specific Test attribute are only known to CodedUI Libraries. so you must choose any Testing framework but add the above reference to execute the CodedUI scripts.