C# 在Ranorex中如何处理弹出窗口

C# 在Ranorex中如何处理弹出窗口,c#,forms,popup,ranorex,C#,Forms,Popup,Ranorex,在ranorex中,我有一个关于使用条件语句的快速问题,或者任何处理现金抽屉弹出窗口的建议。每当我启动我们的应用程序时,都会有一个登录屏幕,但不是每次都有,所以当有弹出窗口时,我该如何处理该弹出窗口 这是需要单击的两个必填字段 Username field: /form[@title='Windows Security']/?/?/element[@instance='0']/text[@class='Edit'] Password field: /form[@title='Wind

在ranorex中,我有一个关于使用条件语句的快速问题,或者任何处理现金抽屉弹出窗口的建议。每当我启动我们的应用程序时,都会有一个登录屏幕,但不是每次都有,所以当有弹出窗口时,我该如何处理该弹出窗口

这是需要单击的两个必填字段

 Username field:  /form[@title='Windows Security']/?/?/element[@instance='0']/text[@class='Edit']
 Password field:    /form[@title='Windows Security']/?/?/element[@instance='1']/text[@class='Edit']

/form[@title='Windows Security']/?/?/element[@instance='2']/button[@text='OK']
我该怎么处理?使用if-then-else语句?如果是这样,我该怎么做

另外,在我登录后,会出现现金抽屉初始化弹出窗口,这是一整天的一次

/dom[@domain='crs.pre.kofile.com']//input[#'cashdrawerinitialize-btn']   
这是当弹出窗口出现时我需要单击的按钮。请让我知道


感谢您的登录弹出窗口,我建议您使用中所述的Ranorex操作表中的可选操作,或者使用检查项目是否存在的

如果决定使用用户代码方法,可以使用以下行

if(repo.App.Form.UsernameInfo.Exists(duration))
{
    //Do your steps here
}
else
{
    //What to do, when the first popup is not here?
}
请不要忘记使用存储库项目的Info对象


对于第二个弹出窗口,您可以使用Ranorex代码示例中所述的Ranorex PopuvWatcher类(对不起,我现在只允许发布链接)

UI测试中的一个常见问题是出现意外对话框,例如KeePass中的更新检查对话框

要解决此问题,可以使用PopuwWatcher类。使用这个类,您可以为测试执行期间可能弹出的每个对话框添加监视。在这些监视中,您可以指定一个RanoreXPath或PopuwWatcher应该关注的存储库项,以及一个应该触发的方法或应该单击的存储库项

void ITestModule.Run()
{
// Create PopupWatcher
PopupWatcher myPopupWatcher = new PopupWatcher();
// Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog
myPopupWatcher.Watch("/form[@controlname='UpdateCheckForm']/button[@controlname='m_btnClose']", CloseUpdateCheckDialog);
// Add a Watch using the info object of a button and triggering the Method CloseUpdateCheckDialog
// myPopupWatcher.Watch(repo.UpdateCheckDialog.btCloseInfo, CloseUpdateCheckDialog);
// Add a Watch using the info object of the dialog and the info object of the button to click
// myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog.SelfInfo, repo.UpdateCheckDialog.btCloseInfo);
// Add a Watch using a repository folder object and the info object of the button to click
// myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog, repo.UpdateCheckDialog.btCloseInfo);
// Start PopupWatcher
myPopupWatcher.Start();
}
public static void CloseUpdateCheckDialog(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
myElement.As<ranorex.button>().Click();
}
public static void CloseUpdateCheckDialog(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)
{
myElement.As<ranorex.button>().Click();
}

此外,我建议您首先确认/验证一个元素是否存在(当弹出窗口存在时和不存在时),这样您就可以更快地检查弹出窗口,而不必每次查找时都等待整个持续时间。
var watcher = new PopupWatcher();
//provide there two elements WatchAndClick(RepoItemInfo, RepoItemInfo);
watcher.WatchAndClick(RepoItemInfoFindElement, RepoItemInfoClickElement);
watcher.Start();
//some work
watcher.Stop();