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中。 –