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.

How to change your default language in Visual Studio

Problem: I want to change my default languge in Visual Studio. Solution: Select Tools / Import and Export Settings... Select Reset all settings Click Next > I suggest backing up your current settings just in case you want them back. Select the default Language setup you want to use Click Finish To verify click File/New Project.  Your desired language is selected by default.

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.

How to set the “default” configuration for a project.

Being a Process Consultant specializing in TFS I teach many companies how to use Team Build.  When you create a new build definition you have the option to set “Configurations to Build”. However, if you leave that value blank the build will build the “default” configuration. The questions I am inevitability ask are “what is the default configuration” and “how do we set the default configuration”?  Well in this post I will show you where it is stored and how to update it for typical Visual Studio 2012 project. Visual Studio projects are msbuild scripts and because of that we can set properties in the actual project files that are going to be sent to msbuild to be compiled.  To change the default configuration you we need to load the project file as xml which is the file format of msbuild.  With the project open in Visual Studio simply right click on the desired project and select “Unload Project” from the context menu.  Once the project is unloaded right click on it again and select “Edit [Project Name]” and Visual Studio will open the file as an xml file we can edit.  Search the file for a “Configuration” element in a property group (it is normally the first group).  It should look similar to this: <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>   This is the line responsible for setting the default configuration of your build.  Simply change “Debug” to the desired default configuration, save the file then right click on project file in Solution Explorer and select “Reload Project”.  After you check in your changes an queue a new build it will be built using this configuration if the “Configurations to Build” is blank in the build definition.

I can't access app.config from my web test plug in

Problem:  I want to read the connection strings from my app.config of my Web Test Project but it never loads.  Solution:  Use the Configuration Manager OpenMappedExeConfiguration call to load the app.config file.  Code:  // Map the new configuration file.ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();configFileMap.ExeConfigFilename =   System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name + ".config"; // Get the mapped configuration filevar config = ConfigurationManager.OpenMappedExeConfiguration(   configFileMap, ConfigurationUserLevel.None); Explanation: The app.config of the test project is not loaded for web or load tests, because they are run in the same application domain as the test process (either vstesthost.exe or qtagent.exe), so they will load their config files instead. Therefore, we simply load the configuration file ourselves. Loading a configuration file is a two phased process.  First we build a ExcConfigurationFileMap object and set the name of our configuration file to be loaded. Then we open that file with a call to OpenMappedExeConfiguration method of the ConfigurationManager class. I am not a fan of hard coded values so we are going to get the name of the assembly using reflection and simply concatenate ".config" to the end of it.  Calling System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name will return the name of the assembly. After calling OpenMappedExeConfiguration you can use the returned object to access the connection strings or any other data from the app.config.

I don't trust 2012 Auto merge but it does it automatically.

Problem: I would like a chance to review the changes before having Visual Studio 2012 automerge my files. Solution: Disable the "Attempt to automatically resolve conflicts when they are generated. Explanation: When Visual Studio 2012 is installed it defaults with this option set. If you uncheck this box Visual Studio behaves as it did in the 2010 version.  You are presented the Conflict Resolution window with options to AutoMerge, Merge Changes In Merge Tool, Take Server Version or Keep Local Version.