1: public class LogTestcaseExecutor: TestcaseExecutor
2: {
3: private readonly string _testPath;
4: private StringBuilder _log;
5:
6: public LogTestcaseExecutor(string testPath)
7: : base()
8: {
9: _testPath = testPath;
10: _log = new StringBuilder();
11: }
12:
13: protected override void OnTestcaseExecuted(TestcaseExecutionEventArgs e)
14: {
15: string tableRow = @"
16: <tr style='"background-color:{2};"">
17: <td>{0}</td>
18: <td>{1}</td>
19: </tr>
20: ";
21: _log.AppendFormat(tableRow,
22: e.WebTestName,
23: (e.Exception == null) ? " " : e.Exception.Message,
24: (e.Passed) ? "green" : "red");
25:
26: base.OnTestcaseExecuted(e);
27: }
28:
29: protected override void OnTestRunFinished(TestRunFinishedEventArgs e)
30: {
31: string log = @"
32: <html>
33: <body>
34: <table style='"width:100%;border-style: solid;border-width: 1px;"">
35: <tr>
36: <td>Testcase</td><td>Error</td>
37: </tr>
38: {0}
39: </table>
40: </body>
41: </html>";
42:
43: File.WriteAllText(Path.Combine(_testPath, "RunLog.htm"), String.Format(log, _log.ToString()));
44:
45: base.OnTestRunFinished(e);
46: }
47: }