Validate类用来检查UI元素的值,不过也可以在代码中用来对非UI相关的对象进行简单的比较。与简单的IF语句相比,validate类中的方法会在成功或者失败的时候自动记录消息到report文件中。
C#
// Validate for Existence
// Using ‘Info’ objects for validation
// Throws a Ranorex.ValidationException if validation
// fails. Automatically reports success or failed message
// to log file
Validate.Exists(repo.SaveDialog.ButtonOKInfo);
// Validates the existence of the repository item,
// but does not throw any exception
bool exists = Validate.Exists(repo.SaveDialog.ButtonOKInfo,”Check Object ‘{0}'”,false);
// Check whether an application form exists using a RanoreXPath
Validate.Exists(“/form[@controlname=’formVipApplication’]”);
// Check whether an application does not exists
// for the time specified as timeout for the given repository item
Validate.NotExists(repo.MyApp.SelfInfo);
// Validate ‘Enabled’ attribute of button ‘Delete’
Validate.Attribute(repo.MyApp.Buttons.ButtonDeleteInfo,”Enabled”,false);
VB.NET
‘ Validate for Existence
‘ Using ‘Info’ objects for validation
‘ Throws a Ranorex.ValidationException if validation
‘ fails. Automatically reports success or failed message
‘ to log file
Validate.Exists(repo.SaveDialog.ButtonOKInfo)
‘ Validates the existence of the repository item,
‘ but does not throw any exception
Dim exists As Boolean = Validate.Exists(repo.SaveDialog.ButtonOKInfo,”Check Object ‘{0}'”,false)
‘ Check whether an application form exists using a RanoreXPath
Validate.Exists(“/form[@controlname=’formVipApplication’]”)
‘ Check whether an application does not exists
‘ for the time specified as timeout for the given repository item
Validate.NotExists(repo.MyApp.SelfInfo)
‘ Validate ‘Enabled’ attribute of button ‘Delete’
Validate.Attribute(repo.MyApp.Buttons.ButtonDeleteInfo,”Enabled”,false)
注意:所有的Validate类的方法都允许万一失败的情况下不抛异常。上面用到的代码片段仅仅使用了很少的几个验证的方法,关于更多Ranorex.Valiate类的细节可以参看API文档。