0
我写了一个演示代码来测试WatiN的屏保功能。WatiN 2.0 Beta:屏保仍然无效
但是,当我写了下面的一段代码故意失败,并保存截图,它只是停止在测试失败
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.True即在执行 Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
这一步是故意的,但屏幕截图在指定位置的保存不成立。
感谢您的任何帮助:)
此外,在你的例子中,你知道你做三个独立的IE实例吗?一个在DemoCaptureOnFailure中,一个在DisposeBrowser中。 –