WatiN 2.0 Beta:屏幕保护程序仍然无法工作

发布于 2024-12-10 00:08:16 字数 1648 浏览 0 评论 0原文

我编写了一个演示代码来测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-12-17 00:08:16

我以为你在哪里使用 NUnit ???不管怎样,这就是你需要做的。

您没有完全正确地设置测试。

在您的应用程序中,转到 File->New->Project... 并添加“MbUnit V3 Test Project”(c# 版本)。在解决方案资源管理器中添加对 WatiN dll 的引用。

首先使用 [TestFixture] 属性为您的测试添加一个新类: -

[TestFixture]
public class ScreenshotTest

添加任意数量的测试方法: -

[Test]
public void DoScreenshotTest()

如果您想为此类中的所有测试运行一些初始化/终结代码,您可以添加方法: -

[SetUp]
public void DoTestSetup()

[TearDown]
public void DoTestTeardown()

如果您构建解决方案并打开测试视图窗口(测试->Windows->测试视图),您应该会看到新的测试方法。然后,您可以右键单击并“运行选择”或“调试选择”

这是代码的完整版本,HTH!

[TestFixture]
public class ScreenshotTest
{
    private IE ie;

    [SetUp]
    public void DoTestSetup()
    {
        ie = new IE();
    }

    [TearDown]
    public void DoTestTeardown()
    {
        if (ie != null)
        {
            if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
                ie.CaptureWebPageToFile(@"C:\Documents and Settings\All Users\Favorites.png");

            ie.Close();
            ie.Dispose();
            ie = null;
        }
    }

    [Test]
    public void DoScreenshotTest()
    {
        Assert.IsNotNull(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();
        }

        Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
    }
}

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: -

[TestFixture]
public class ScreenshotTest

Add as many test methods as you like: -

[Test]
public void DoScreenshotTest()

If you have some initialize/finalize code you want to run for ALL tests in this class you can add methods: -

[SetUp]
public void DoTestSetup()

[TearDown]
public void DoTestTeardown()

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!

[TestFixture]
public class ScreenshotTest
{
    private IE ie;

    [SetUp]
    public void DoTestSetup()
    {
        ie = new IE();
    }

    [TearDown]
    public void DoTestTeardown()
    {
        if (ie != null)
        {
            if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
                ie.CaptureWebPageToFile(@"C:\Documents and Settings\All Users\Favorites.png");

            ie.Close();
            ie.Dispose();
            ie = null;
        }
    }

    [Test]
    public void DoScreenshotTest()
    {
        Assert.IsNotNull(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();
        }

        Assert.IsTrue(ie.ContainsText("NUnit"), "Expected to find NUnit on the page.");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文