8

在 Visual Studio 2012 中运行我的 Coded UI 测试后,我希望将测试结果记录到 HTML 文件中。遵循教程后,我能够实现这一目标。

不幸的是,每个测试都有自己的 HTML 报告..\TestResults\<Test Run Folder>\In\<Individual Test Log Folder>\<PC Name>\UITestActionLog.html,目前我有 3 个不同的单独测试,每个测试都有自己的文件夹..\TestResults\<Test Run Folder>\In\

每个生成的 HTML 文件如下所示:

在此处输入图像描述

我想要的是将所有 3 个 HTML 文件合并为一个,而不仅仅是

> 测试一

就像

>测试一

>测试2

>测试3

有没有办法通过一些配置选项自动执行此操作,或者我是否坚持编写程序来自己合并所有 HTML 文件?

4

2 回答 2

3

我自己想出了一个解决方案,编写了一个程序来<div class="g">从每个 HTML 日志中获取节点并将它们组合成一个 HTML 文件。奇迹般有效。

于 2013-06-24T19:03:35.273 回答
2

我也写了我自己的解决方案。在使用 HTML 敏捷包一个小时后,发现它有时会与 HTML5 嵌入图像(例如“>”、“<”)发生冲突。

我只是编写了一个解析 html 的控制台应用程序,并合并为 1:

cmd ActionLogBuilder inputfile's.html outputfile.html

(它非常原始,但有效)

static void Main(string[] args)
{
    bool only2 = false;
    StringBuilder outputFile = new StringBuilder();
    if (args.Length == 2)
    {             
        try
        {
            System.IO.File.Delete(args[1]);
        }
        catch
        {
            Console.WriteLine("No file to delete");
        }

        System.IO.File.Move(args[0], args[1]);
        only2 = true;               
    }
    int endArg = args.Length;
    Console.WriteLine(endArg.ToString());
    int c = 0;                  
    if(!only2)
    {
        foreach (string a in args)
        {
            if (c == (endArg - 1))
            {
                System.IO.TextWriter w = new System.IO.StreamWriter(a);
                w.Write(outputFile);
                w.Flush();
                w.Close();
                break;
            }
            else
            {
                if (c == 0)
                {
                    using (StreamReader sr = new StreamReader(a))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string grabLine = sr.ReadLine();
                            if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
                            {
                                outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
                            }
                            else
                            {
                                if (!grabLine.Contains("</body>") | !grabLine.Contains("</html>"))
                                {
                                    outputFile.AppendLine(grabLine);
                                }
                            }
                        }
                    }
                }
                if (c != 0 && c != (endArg - 2))
                {
                    bool notYet = false;
                    using (StreamReader sr = new StreamReader(a))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string grabLine = sr.ReadLine();


                            if (grabLine.Contains("<body>"))
                            {
                                notYet = true;
                            }
                            if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
                            {
                                outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
                            }
                            else
                            {
                                if (notYet)
                                {
                                    if (!grabLine.Contains("</body>") | !grabLine.Contains("</html>"))
                                    {
                                        outputFile.AppendLine(grabLine);
                                    }
                                }
                            }
                        }
                    }
                }
                if (c == (endArg - 2))
                {
                    bool notYet = false;
                    using (StreamReader sr = new StreamReader(a))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string grabLine = sr.ReadLine();
                            if (grabLine.Contains("<body>"))
                            {
                                notYet = true;
                            }
                            if (notYet)
                            {
                                if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
                                {
                                    outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
                                }
                                else
                                {
                                    outputFile.AppendLine(grabLine);
                                }
                            }
                        }
                    }
                }
            }
            c++;
        }
    }
}
于 2013-10-20T15:13:00.640 回答