2016-03-02 105 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