WatiN testing of a popup

2019-05-30 16:07发布

I have an application that brings up a popup window when you click a link. I have a watin test that naviates to the page and clicks a link to open the popup. This is my current code:

 [Test]
 public void TestCommentBoxInput()
        {

                window.GoTo("mylocalurl");
                window.Link(Find.ById("popuplink.aspx")).Click();
                IE iepopup_1 = IE.AttachTo<IE>(Find.ByUrl("popuplinkurl.aspx"));
                iepopup_1.TextField(Find.ById("txtComments")).TypeText("Commenttest");
         }

As you can see I tried attatching the popup window to the created browser called window. When I run my test it just stops at the popup window and never enters text in the box. How do I go about making my program regonize that it is now to be operating on the popup and not the original window?

EDIT: I am dealing with a Modal Dialog.

2条回答
Luminary・发光体
2楼-- · 2019-05-30 16:44

So I have figured out the problem, the problem was I was using a Modal dialog and they are handled differently. My new code is as follows in case anyone is stuck in the same position I was in. :)

public void TestCommentBox()
        {
            window.GoTo("mylocalurl");
            window.Link(Find.ById("popuplink.aspx")).ClickNoWait();
            HtmlDialog dialog = window.HtmlDialog(Find.ByTitle("TestPopup"));
            dialog.TextField(Find.ById("Txtcomments")).TypeText("Commmenttest!");
        }

The important lines are:

window.Link(Find.ById("popuplink.aspx")).ClickNoWait();

Notice that I am using ClickNoWait() and not just Click, I am unsure as to why this makes the difference, but it does! If someone could explain that that would be great.

HtmlDialog dialog = window.HtmlDialog(Find.ByTitle("TestPopup"));

Because I am dealing with a Modal dialog you have to declare a new HtmlDialog. Also in order to use Html dialog make sure you include Watin.Core.DialogHandlers. I hope this is helpful to someone out there! :)

查看更多
姐就是有狂的资本
3楼-- · 2019-05-30 17:10

I think the Find.ByUrl try to do a exact match, try with a Find.ByUrl(u => u.Contains("popuplinkurl.aspx"))

查看更多
登录 后发表回答