How to data bind a Visual Studio 2013 Coded UI Test

Problem I need to run the same Coded UI Test with different data. Solution Data bind your Coded UI Test.  To data bind a test in Visual Studio you just need access to the data source and add attributes to the test. For this example we are going to use a simply CSV file.  So add a new text file to your project with a CSV extension. Create a comma delimited file of the desired data.  Make sure when you save it you first select “Advanced Save Options” from the File menu and select “Unicode (UTF-8 without signature) – Codepage 65001” before you save the file. Now right click on the item in Solution Explorer and select Properties. From the Properties window change the “Copy to Output Directory” to “Copy always”.   To your test you will need to add two attributes.  The first is the DeploymentItem attribute. This attribute takes a single string argument of the name of the CSV file. The second attribute is the DataSource attribute.  This attribute is where you define the class used to read the data, what table to read from and how the data should be accessed.  For a CSV file the first argument will be “Microsoft.VisualStudio.TestTools.DataSource.CSV” which identifies the correct class to use to load the CSV file.  Next we need to let the test know where to find the data with “|DataDirectory|\\data.csv”.  Then we have to identify the table to read the data from with “data#csv”. Finally we have to give it an access method “DataAccessMethod.Sequential”.  The final attribute will look like this: [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential)] With the attributes in place you can now use the DataRow property of the TestContext to access the columns in your CSV for example: TestContext.DataRow["FirstName"].ToString(); Good luck.

I keep getting error when I run tcm.exe

Problem: I keep getting the following error when I attempt to run tcm.exe from the command line: “A test run must be created with at least one test case.” Solution: Open MTM and check the status of the test case from the Test tab.  Make sure the test case state is not Error.  If it is reset it to active and try your command again.

Trackyon CUIT Helpers

Trackyon LLC CUIT Helpers The Coded UI Test (CUIT) Helpers from Trackyon LLC allows IIS Express or Visual Studio Development Server (Cassini Web server) to be started by your test.  This prevents Coded UI Test from beginning without a server running. Features: Start and Stop IIS Express Start and Stop Visual Studio Development Server (Cassini Web server) Usage: To start using the package verify the app.config file of your test project contains either the webDevPath and/or the iisExpressPath values added to your appSettings section. These values are used by the library to start the respective web server.  If you installed the package using nuget the keys were added for you with paths assuming you are running .NET 4.0 and on a 64 bit machine.  If you are not running .NET 40 or not on a 64 bit machine you will need to adjust the paths. <add key="webDevPath" value="C:\Program Files (x86)\Common Files\microsoft shared\DevServer\11.0\WebDev.WebServer40" /> <add key="iisExpressPath" value="C:\Program Files (x86)\IIS Express\iisexpress" /> Starting Visual Studio Development Server (Cassini Web server) You can use the static Start method of the WebDev class in the Trackyon.CUIT.Helpers namespace.  The Start method takes two parameters port and path. Port is the port you want the web server to use to host your application.  Path is the path to the project to load.  The WebDev class provides a helper method FindProjectFolder that given the TestContext and Project Name will determine the path for you at runtime so the path is not hard coded.  Hard coding the path would require all developers to map the project to the same location on their machines.  The example below would start the MyWebApp project of the currently loaded solution on port 8081. WebDev.Start(8081, WebDev.FindProjectFolder(TestContext, "MyWebApp")); Once the test run is complete simply call Close to stop the server.  Starting IIS Express The IISExpress class also provides a static Start method, however, this method only takes a single parameter sitename.  The site name must map to a site already configured in your applicationhost.config file.  The site would be configured in the applicationhost.config file if you have setup your project to use IIS Express from the Web section of the project properties.  This file can be located in one of the two following locations: %userprofile%\documents\iisexpress\config\applicationhost.config %userprofile%\my documents\iisexpress\config\applicationhost.config The example below would start the MyWebApp site in IIS Express. IISExpress.Start("MyWebApp"); Once the test run is complete simply call Close to stop the server. Known Issues The icons for the servers may stay in Notification Area after the server has been closed.  Simply hovering your mouse over the icons will make them disappear. The servers will close after the test is complete regardless if you call close or not. They are created as child processes of the test assembly and when the test are unloaded the process is terminated.

KB2870699 breaks Coded UI Test

Problem: All my Coded UI Test start failing because they can't find the controls.  Solution: Uninstall KB2870699 - MS13-069: Cumulative security update for Internet Explorer: September 10, 2013. Explanation: After my machine applied several windows updates all my Coded UI Test that were working before the updates all began to fail. The test were unable to perform actions because the controls were hidden.  Each test would fail with the following exception: Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException You can read more about the issue here: Further Information After I uninstalled the update and rebooted my machine all my test began to run again.

More fun with CUIT

Problem: I have a CUIT that does not run as fast as I would like. Solution: Use the Coded UI Test Editor in Feature Pack 2 to adjust the actions recorded. Explanation:

What to do when my CUIT thows a PlaybackFailureException

Updated (Oct 11, 2011) Problem: I have a textbox that has a maximum length of five characters. I want to record a Data Driven CUIT to test that you cannot type in more than five characters.  However, when I attempt to set the textbox to a six character value the CUIT throws a PlaybackFailureException. Solution: Simply set Playback.PlaybackSettings.SkipSetPropertyVerification = true; before the call that throws the PlaybackFailureException and return it to false after. Explanation: After setting a property of any UI control, the record and playback engine performs a verification step to make sure that the set succeeded and the UI control now has the value it attempted to set it to. For example if you have a text box that only allows 5 characters and you attempt to set it to 6 characters the engine will throw a PlaybackFailureException. If you are trying to test that if I actually type 123456 that the value is 12345 you will have to set Playback.PlaybackSettings.SkipSetPropertyVerification = true; before your test attempts to fill in the value.

CUIT Demo of Feature Pack 2 Coded UI Test Editor

Problem: I have a Coded UI Test that is failing on Playback. Solution: Use the Coded UI Test Editor in Feature Pack 2 to adjust the UI Map and add actions to your test. Explanation: I felt a write up would be too hard to follow so I recorded a video instead which you can watch below. In this video we are going to cover a few features of the Coded UI Test Editor available in Feature Pack 2 for Visual Studio 2010. The Coded UI Test Editor greatly improves an automation engineers experience working with Coded UI Test. The features we are going to demonstrate today are splitting actions into separate methods, renaming methods and locating UI controls in a running application. Many coded UI demos show you the happy path scenario where everything works perfectly.  While helping clients implement Coded UI Test in the real world you quickly realize that the happy path can be hard to stay on.  The goal of this web cast is to show a recording that does not work as recorded and techniques we can use to adjust the recording to yield the desired results.