Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a Win Form Application which would accept user input and when the user hits OK, it calls a Coded UI Test. The Winform is in Project A and Coded UI Test is in Project B. The Project B is added as a reference in Project A. The issue is that when the Winform application calls the Coded UI Test method, the playback is not initialized. Since it is not initialized, none of the coded ui test methods work. I tried searching for this on various forums and unable to find a proper solution for it. I am working on VS2012. References to Coded UI dlls are also added.

The references to Project A are mentioned below and CopyLocal is set to True:
c:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\
Microsoft.VisualStudio.TestTools.UITesting.dll
Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll

C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\
Microsoft.VisualStudio.TestTools.UITest.CodeGeneration.dll
Microsoft.VisualStudio.TestTools.UITest.Framework.dll
Microsoft.VisualStudio.TestTools.UITest.Playback.dll

The references to Project B are the same but all are from C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\Reference Assemblies\ and CopyLocal is set to False

If I set CopyLocal to False for Project A, then the test fails to start since it cannot locate those dlls in the project folder.

The code to handle my objective is mentioned below:

namespace WinFormtest
{
public class WinFormTestClass
{
// Call the Coded UI Test in the order --> namespace.class.CodedUITestMethod
test.codeduiclass.codeduitestmethod();
}
}


Program.cs that gets created when creating a new project has the following content. Tried initializing Coded UI test here as well but it did not work:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UITesting;

namespace DMServerInstaller
{
static class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!Playback.IsInitialized)
{
Playback.Initialize();
}
Application.Run(new Form());
}
}
}

// Below is the snippet of the coded UI test class
public class ServerTests
{
[TestInitialize]
public void TestInitialize()
{
if (Playback.IsInitialized)
{
Playback.Cleanup();
}
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
if (!Playback.IsInitialized)
{
Playback.Initialize();
}
}

[TestCleanup]
public void TestCleanup()
{
PreviousTestOutcome = TestContext.CurrentTestOutcome;
Log.Debug("Entering TestTeardown");
// If an assertion say cheese. Validate if this is required as CUI automatically takes screenshot on failures too.
if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)
{
Camera.TakePicture(TestContext);
Playback.Wait(1000);
}
Log.Debug("Exiting TestTeardown");
}

[TestMethod]
public static void codeduitestmethod();
{
// Some statements here
}

}

Request you to help me in this regard as early as possible. Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900