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

Use UI Automation To Test Your Code follow this steps using link

  1. Create a Coded UI Test project.
  2. Add a coded UI test file.
  3. Record a sequence of actions.
  4. Verify the values in UI fields such as text boxes.
  5. View the generated test code.
  6. Add more actions and assertions.
  7. Run the test.

The TestContext object within a Coded UI test has a number of members with Directory in their name allowing access to various directories while the test is running. Hence the complex Directory.GetParent ... should not be necessary.

This answer has some notes on how to data drive Coded UI tests.

There are several ways of deploying files for a test. They include:

  1. Adding the file to the solution and setting its properties for deployment, as shown here.
  2. The .testsettings file has a Deployment section.
  3. The .testsettings file has a Setup and cleanup scripts section that allows batch files (etc) to be called.
  4. An attribute in the source code. This method is mentioned in the question.

Something from these deployment methods should allow your file to be copied as required for your tests.

  • Thanks for the answer, but if you see my question. Solution 1: of you I have already implemented; Solution 2: I have mentioned that I used .testSettings file but still not working, these XML files are not part of TestMethod, so DeploymentItem attribute can't be used with them. – Dhiman Dec 23 '15 at 14:16

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.