简体   繁体   English

ASP .NET MVC WatiN失败断言

[英]Asp .Net MVC WatiN failing assert

So I just got a hold of WatiN and wanted to do some automated acceptance tests. 因此,我只是掌握了WatiN,想做一些自动化的验收测试。 I've got resharper, as well as Nunit and WatiN using NuGet manager. 我已经使用了NuGet管理器,还有Nunit和WatiN,也很抢手。 Changed the reference Interop.SHDocVw property of Embed Interop to false so everything works fine, the browser shows up, writes text in a box(kinda fast so I only see the end result and no the typing which I don't know if it's possible to slow it down), clicks a button, etc.. Well... fine until I add an Assert in the end of my Test. 将Embed Interop的引用Interop.SHDocVw属性更改为false,以便一切正常,浏览器显示,将文本写在框中(有点快,所以我只能看到最终结果,而没有键入,我不知道是否可能降低速度),单击按钮等。好吧,直到在测试结束时添加断言为止。 It fails. 它失败。 It kinda looks like the browser is closing before the test finishes. 看起来浏览器在测试完成之前已关闭。 I've used the WaitForComplete() method but it looks like it doesn't do anything. 我已经使用了WaitForComplete()方法,但是看起来它什么也没做。 Is there a way to fix that? 有办法解决吗?

using System.Threading;
using NUnit.Framework;
using WatiN.Core;

namespace Testy
{
    [TestFixture]
    [Apartment(ApartmentState.STA)]
    public class UnitTest2
    {
        [Test]
        public void SearchForWatiNOnGoogle()
        {
            using (var browser = new IE("google.com"))
            {
                browser.TextField(Find.ByName("q")).TypeText("WatiN");
                browser.Button(Find.ByName("btnG")).Click();
                Assert.IsTrue(browser.ContainsText("WatiN"));
            }
        }
    }
}

And this is what I tried but with no better results. 这是我尝试过的,但没有更好的结果。

[Test]
        public void SearchForWatiNOnGoogle()
        {
            using (var browser = new IE("google.com"))
            {
                browser.TextField(Find.ByName("q")).TypeText("WatiN");
                browser.WaitForComplete(4000);
                browser.Button(Find.ByName("btnG")).Click();
                browser.WaitForComplete(4000);
                Assert.IsTrue(browser.ContainsText("WatiN"));
                browser.Close();
            }
        }

Try to set the autoclose to false ie 尝试将自动关闭设置为false

browser.AutoClose = false;

however - that project hasn't been active in years. 但是-该项目几年来一直没有开展。 What about the functionality built right into Visual Studio for this for UI Automation ? 在Visual Studio中为此UI自动化内置的功能如何?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM