WatiN 2.0 Beta:屏幕保护程序仍然无法工作
我编写了一个演示代码来测试 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.");
,这是故意的,但在指定位置保存屏幕截图没有实现。
感谢您的帮助:)
I have written a demo code to test the screensaver feature of WatiN.
But when I write the following piece of code intentionally to fail and save the screenshot, it just stops executing after the Assert.True ie where the test fails
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");
}
}
}
}
It is throwing exception at
Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
this step which was intentional but the Saving of screenshot at the specified location is not acheived.
Thanks for any help:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以为你在哪里使用 NUnit ???不管怎样,这就是你需要做的。
您没有完全正确地设置测试。
在您的应用程序中,转到 File->New->Project... 并添加“MbUnit V3 Test Project”(c# 版本)。在解决方案资源管理器中添加对 WatiN dll 的引用。
首先使用 [TestFixture] 属性为您的测试添加一个新类: -
添加任意数量的测试方法: -
如果您想为此类中的所有测试运行一些初始化/终结代码,您可以添加方法: -
如果您构建解决方案并打开测试视图窗口(测试->Windows->测试视图),您应该会看到新的测试方法。然后,您可以右键单击并“运行选择”或“调试选择”
这是代码的完整版本,HTH!
I thought you where using NUnit??? Anyhow, here's what you need to do.
You're not quite setting up your test correctly.
In your application go to File->New->Project... and add an "MbUnit V3 Test Project" (the c# version). In solution explorer add a reference to the WatiN dll.
First add a new class for your tests with the [TestFixture] attribute: -
Add as many test methods as you like: -
If you have some initialize/finalize code you want to run for ALL tests in this class you can add methods: -
If you build your solution and open up the Test View window (Test->Windows->Test View) you should see your new test methods. You can then right click and "Run Selection" or "Debug Selection"
Here's the full version of the code, HTH!