在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. 多维foreach数组只返回最后一次迭代
- 5. tf.while_loop仅考虑最后一次迭代
- 6. 最后一次迭代返回undefined
- 7. 迭代HashMap的值只有一次
- 8. 在每次迭代完成后再次迭代函数
- 9. 如何返回值每次迭代?我能只有最后一次迭代值发送到我的分贝
- 10. 下一次迭代
- 11. Jaydata .forEach只迭代50次
- 12. 在多次迭代之间重复1次迭代后暂停CSS3动画
- 13. 迭代在第一次迭代后退出
- 14. 迭代层次
- 15. 每次迭代
- 16. 函数调用只取最后一次迭代
- 17. 只显示循环的最后一次迭代
- 18. 数据库只保存最后一次迭代,laravel 5.4
- 19. WMEncoder在一次迭代后抛出OutOfMemoryException
- 20. 迭代与每次测验的Jquery
- 21. Java Bubble排序迭代只有两次
- 22. Python文档:多次迭代?
- 23. 多次迭代的性能
- 24. ()循环迭代多少次?
- 25. 检测循环中的最后一次迭代
- 26. 嵌套while循环只迭代一次
- 27. ajax只执行第一次迭代
- 28. 嵌套for循环只迭代一次
- 29. 只执行DOM迭代一次
- 30. 迭代在环中特定的代码只有一次