处理意外出现的对话框

UI测试中常出现的一个问题是意外出现的对话框,例如KeePass里面的Update-Check对话框。

为了克服这个问题,你可以使用PopupWatcher类。

使用这个类,你可以为每一个可能在测试执行过程中弹出的对话框添加watch

在这些watch里面,你可以指定PopupWatcher需要关注的RanoreXPath或者是对象库里的项。一旦出现,那么将会触发一个处理方法,或者对象库的项会被点击。

 

C#

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(); }

 

VB.NET

Private Sub ITestModule_Run() Implements ITestModule.Run

' Create PopupWatcher Dim myPopupWatcher As New PopupWatcher()

' Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog myPopupWatcher.Watch("/form[@controlname='UpdateCheckForm']/button[@controlname='m_btnClose']", AddressOf 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()

End Sub

posted @ 2016-04-10 20:27  老夫子_22  阅读(167)  评论(0)    收藏  举报