WatiN 测试弹出窗口
我有一个应用程序,当您单击链接时会弹出一个窗口。我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 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"))
所以我已经解决了问题,问题是我使用的是模态对话框,并且它们的处理方式不同。我的新代码如下,以防有人陷入与我相同的位置。:)
重要的几行是:
请注意,我使用的是 ClickNoWait() 而不仅仅是 Click,我不确定为什么这会产生差异,但确实如此!如果有人能解释一下那就太好了。
因为我正在处理模态对话框,所以您必须声明一个新的 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. :)
The important lines are:
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.
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! :)