WatiN 测试弹出窗口

发布于 2024-12-21 05:00:49 字数 578 浏览 1 评论 0原文

我有一个应用程序,当您单击链接时会弹出一个窗口。我有一个 watin 测试,导航到该页面并单击链接以打开弹出窗口。这是我当前的代码:

 [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");
         }

如您所见,我尝试将弹出窗口附加到创建的名为 window 的浏览器。当我运行测试时,它只是停在弹出窗口上,并且从不在框中输入文本。我该如何让我的程序重新认识到它现在是在弹出窗口而不是原始窗口上运行?

编辑:我正在处理模态对话框。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风苍溪 2024-12-28 05:00:49

我认为 Find.ByUrl 尝试进行精确匹配,请尝试使用 Find.ByUrl(u => u.Contains("popuplinkurl.aspx"))

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

挽袖吟 2024-12-28 05:00:49

所以我已经解决了问题,问题是我使用的是模态对话框,并且它们的处理方式不同。我的新代码如下,以防有人陷入与我相同的位置。:)

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!");
        }

重要的几行是:

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

请注意,我使用的是 ClickNoWait() 而不仅仅是 Click,我不确定为什么这会产生差异,但确实如此!如果有人能解释一下那就太好了。

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

因为我正在处理模态对话框,所以您必须声明一个新的 HtmlDialog。另外,为了使用 Html 对话框,请确保包含 Watin.Core.DialogHandlers。我希望这对那里的人有帮助! :)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文