在Visual Studio中CodedUI執行測試生成UITestActionLog.html文件,爲什麼產生uiTestActionlog.html文件只有最後一次迭代?這是否可以歸因於先前生成的報告的重寫?在CodedUI測試與多次迭代,只有最後一次迭代
0
A
回答
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
相關問題
- 1. 迭代器只能迭代一次嗎?
- 2. 多次迭代
- 3. 在另一次迭代內迭代?
- 4. tf.while_loop僅考慮最後一次迭代
- 5. 在每次迭代完成後再次迭代函數
- 6. 迭代層次
- 7. 只顯示循環的最後一次迭代
- 8. 迭代與每次測驗的Jquery
- 9. Java Bubble排序迭代只有兩次
- 10. ()循環迭代多少次?
- 11. Python文檔:多次迭代?
- 12. 只執行DOM迭代一次
- 13. 嵌套while循環只迭代一次
- 14. 嵌套for循環只迭代一次
- 15. 檢測循環中的最後一次迭代
- 16. 迭代在環中特定的代碼只有一次
- 17. 每次迭代只有一次調用方法
- 18. 尋找一個優雅的方式來`time.sleep()`每次迭代後,除了最後一次迭代
- 19. PHP - 迭代兩次泛型迭代
- 20. 迭代斯卡拉列表和治療最後一次迭代的不同
- 21. TFS即使在第二次迭代失敗時也會通過多次迭代的自動化測試
- 22. 重複一次迭代
- 23. 循環第一次迭代
- 24. Matplotlib.animation.FuncAnimation一次迭代列表
- 25. 循環在一次迭代後停止所有代碼
- 26. PHP foreach循環代碼更改的最後一次迭代
- 27. 第一次迭代後咖啡崩潰?
- 28. for循環一次迭代後墜毀
- 29. 環路退出後一次迭代
- 30. Collection.unmodifiableMap迭代次序