WatiN testing of a popup

随声附和 提交于 2019-12-08 07:07:09

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8523142/watin-testing-of-a-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!