【发布时间】:2016-01-24 02:04:19
【问题描述】:
你们中有人知道对测试失败和异常进行截图的可能解决方案吗?
我在TearDown() 中添加了以下代码,但结果它也会对通过的测试进行截图,所以这不是最好的解决方案:
DateTime time = DateTime.Now;
string dateToday = "_date_" + time.ToString("yyyy-MM-dd") + "_time_" + time.ToString("HH-mm-ss");
Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile((settings.filePathForScreenShots + "Exception" + dateToday + ".png"), System.Drawing.Imaging.ImageFormat.Png);
我已经找到了这个想法:http://yizeng.me/2014/02/08/take-a-screenshot-on-exception-with-selenium-csharp-eventfiringwebdriver/,使用WebDriverExceptionEventArgs,但由于某些原因,它也制作了一些随机截图,没有任何合理的解释。
我发现的其他想法是针对 Java 而不是针对我与 Selenium 一起使用的 NUnit,因此它们毫无用处。
【问题讨论】:
标签: c# .net unit-testing selenium nunit