I have some Coded UI test cases which are using external files e.g. XML files that contains the Element Name and ID to be located over a page. This XML file is used by Test Cases (under TestMethod attribute) for finding a Field with its Name and ID (e.g. TextBox) and then setting its value. This input value is being provided by the CSV file (so I have used the DDT approach of Coded UI and deployed these CSV files using the Deployment Item Attribute). For locating XML files I have used the below logic
Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName.ToString() + "\\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + "\\Elements\\" + str_fileName
I had to use this, because during run time Coded UI creates a temporary directory something like this
username_machinename 2015-12-16 14_46_38 and tries to find the XML file here, but since they are not under Deployment Attribute, so they are never copied. By using the above logic I was able to locate them in Build folder (Debug/Release) and then test cases were working fine.
But since yesterday I have moved all my test cases to TFS and this above logic is no more working. Because, now Coded UI tries to find these XML Files inside Temp Folder at location
C:\Users\username\AppData\Local\Temp\WebTests\Elements\GlobalActionElements.xml, while it should look for them inside Debug Folder. Actually, after I moved to TFS, the location provided by my code is of Temp Folder not of Debug Folder.
I have tried using the TestSettings File, but with that too it goes to same Temp location and test cases are not working.
It only works in one case, when I use the Runsettings file, but there I have to provide the Absolute path for the TestResults folder, else that too doesn't work. I don't want to use the absolute path, as going forward it may change and then someone has to update it manually.
All XML files have already been marked with Copy to output directory = Copy Always and Build Action = Content