2016-03-02 68 views

回答

0

我一直在为这个问题苦苦挣扎。在微软博客上有一些可悲的回答,就像你应该重新安装visual studio来解决这个问题一样。最终设法通过以下解决方案来解决此问题。希望这会对其他人有所帮助。下面的方法不仅可以生成所有迭代的报告,还可以帮助我们根据特定日期某个特定方法在特定时间的所有迭代的要求获取文件夹中的日志。

步骤1

定义的目录或共享位置和几个变量

namespace CodedUITestProject1 
{ 
    [CodedUITest] 
    public class CodedUITest1 
    { 
     int currentIteration =0; 
     public static string ProjectName = Assembly.GetCallingAssembly().GetName().Name; 
     public static string sFileName = string.Concat(@"C:\Results\", ProjectName + '\\' + DateTime.Today.ToString("dd_MMM_yyyy"), '\\', DateTime.Now.ToString("ddMMMhhmmtt")+ "_", "Result"); 
     public static Dictionary<string, string> ResultsKey = new Dictionary<string, string>(); 
     public CodedUITest1() 
     { 
      if (!Directory.Exists(sFileName)) 
      { 
       Directory.CreateDirectory(sFileName); 
      } 
     } 
    } 
} 

步骤2

声明字典中每个TestMethod的作为遵循

[TestMethod] 

     public void CodedUITestMethod2() 
     { 
      ResultsKey.Add(MethodInfo.GetCurrentMethod().Name, Directory.GetCurrentDirectory()); 
     } 

步骤3

在TestCleanup()中,添加以下代码

[TestCleanup()] 
     public void MyTestCleanup() 
     { 
      Dictionary<string, string>.KeyCollection keyColl = ResultsKey.Keys; 
      foreach (KeyValuePair<string, string> kvp in ResultsKey) 
      { 
       UIMap.ResultsGen(kvp.Value, sFileName, kvp.Key); 
      } 
      ResultsKey.Clear(); 
     } 

步骤4

定义),其在TestCleanup(使用的ResultsGen功能

public static void ResultsGen(string SourceFilePath, string DestinationFilePath, string FileName) 
     { 
      if (FileName != null) 
      { 
       SourceFilePath = Regex.Split(SourceFilePath, "Out")[0] + "In"; 
       DirectoryInfo DirInfo = new DirectoryInfo(SourceFilePath); 
       string finam = ""; 
       foreach (var fi in DirInfo.EnumerateFiles("*.html", SearchOption.AllDirectories)) 
       { 
        finam = finam + fi.Directory + '\\' + fi.Name; 
       } 
       currentIterationValue = currentIteration + 1; 
       File.Copy(finam, DestinationFilePath + '\\' + FileName + "_Iteration"+ currentIterationValue + ".html"); 
       File.Delete(finam); 
      } 
0

发生这种情况是因为每次新迭代r取消先前的UITestActionLog文件被覆盖。导致只保留最终副本。

,其中该文件的路径 - 你的项目中文件夹下的TestReuslts

你在我的情况的了解路径 - d:\ **项目** TestResults \ krakhil \在\ 0eee82c0-3cb9- 42fd-96fe-7314ae4b5fd5 \ KRAKHIL-LT \ UITestAction.html

因此,我所做的是 - 我在CleanUp中添加了一行代码(因为我的每次迭代都在最后通过此方法进行操作。根据您的需要)

string FileSourcePath = (TestContext.TestResultsDirectory + "\\UITestActionLog.html").Replace(@"\\", @"\"); 
      File.Copy(FileSourcePath, FileSourcePath.Replace("UITestActionLog.html", "UITestActionLog" + ReportFileNo++ + ".html")); 

这里最后我会得到所有的UITestActionLog * .html,其中*将是迭代否 - 我为此使用了一个静态变量。如果你想要你可以写一行来删除UITestActionLog.html - 因为你已经有了一个迭代号。

File.Delete(FileSourcePath); // use this at the end of all iterations only