【发布时间】:2011-10-17 21:03:55
【问题描述】:
我编写了一个演示代码来测试 WatiN 的屏幕保护功能。
但是当我故意编写以下代码失败并保存屏幕截图时,它只是在 Assert.True 之后停止执行,即测试失败
using System;
using WatiN.Core;
using Gallio.Framework;
using MbUnit.Framework;
using Gallio.Model;
namespace Screenshotwhentestfails
{
[TestFixture]
class Program
{
public IE ie = new IE();
[STAThread]
[Test]
static void Main(string[] args)
{
DemoCaptureOnFailure();
DisposeBrowser();
}
[Test]
[TearDown]
public static void DemoCaptureOnFailure()
{
IE ie = new IE();
using (TestLog.BeginSection("Go to Google, enter MbUnit as a search term and click I'm Feeling Lucky"))
{
ie.GoTo("http://www.google.com");
ie.TextField(Find.ByName("q")).TypeText("MbUnit");
ie.Button(Find.ByName("btnI")).Click();
}
// Of course this is ridiculous, we'll be on the MbUnit homepage...
Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
}
[TearDown]
public static void DisposeBrowser()
{
IE ie = new IE();
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
ie.CaptureWebPageToFile("C:\\Documents and Settings\\All Users\\Favorites.png");
}
}
}
}
它正在抛出异常
Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
这一步是故意的,但没有实现在指定位置保存屏幕截图。
感谢您的帮助:)
【问题讨论】:
标签: c# automated-tests watin