分类:2.1 Ranorex用户指南

对象库每个项和文件夹都会提供一个由<objectname>Info表示的附加对象。它可以用来访问相应对象的属性,使用它不会直接访问对象,从而避免抛出异常。这个info对象主要用来检查某项的路径是否有效。和该项的超时设置组合,你可以来用它来等待某些元素的出现,例如对话框,文本值和web内容。

C#

// Use the ‘Info’ object to check existence of the  使用Info对象来检查SaveDialog是否存在
// ‘SaveDialog’ item; Method ‘Exists’ uses the timeout  方法Exists会用到对象库中的超时设置
// specified for the ‘SaveDialog’ in the repository
Report.Info(“Exists = ” + repo.SaveDialog.SelfInfo.Exists().ToString());

// Use the ‘Info’ object to check existence of the
// ‘TextOnline’ item which uses the following RXPath:
// statusbar/text[@accessiblename=’Online’]
// This way you can wait with the timeout specified for
// the item within the repository for the text ‘Online’
bool statusTextConnected = repo.MyApp.TextOnlineInfo.Exists();

// Using ‘Info’ objects for validation  如果验证失败,Info对象会抛出异常
// 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, 使用false参数,避免抛出异常
// but does not throw any exception
Validate.Exists(repo.SaveDialog.ButtonOKInfo,”Check Object ‘{0}'”,false);

Read More

C#

[TestModule(“D451F1D1-C347-4B58-939F-F6187642EB56”, ModuleType.UserCode, 1)]
public class UsingRepository : ITestModule
{
// Repository object to access UI elements 用来访问UI元素的对象库对象
MyFirstTestProjectRepository repo = MyFirstTestProjectRepository.Instance;

/// <summary>
/// Constructs a new instance.  创建一个新实例
/// </summary>
public UsingRepository()
{
// Do not delete – a parameterless constructor is required! 不要删,需要无参构造器
}

void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;

// Using Ranorex.Form adapter represented by ‘MyApp’  用Ranorex.Form adapter来表示MyApp
// ‘MyApp’ is used as a folder within the repository;  MyApp是对象库中的文件夹
// the ‘Self’ property returns an object of type Ranorex.Form self用来返回对象

// Activates application 激活应用
repo.MyApp.Self.Activate();
// Log ‘Active’ state 记录状态
Report.Info(repo.MyApp.Self.Active.ToString());
// Maximize, Minimize and Restore 最大化,最小化,复原大小
repo.MyApp.Self.Maximize();
repo.MyApp.Self.Minimize();
repo.MyApp.Self.Restore();
// Closes application 关闭应用
repo.MyApp.Self.Close();

// Using Ranorex.Button adapter represented by ‘ButtonAdd’
// Read and log value of ‘Text’ attribute
Report.Info(repo.MyApp.Buttons.ButtonAdd.Text);

// Press button 按下按钮
repo.MyApp.Buttons.ButtonAdd.Press();
// Read and log value of ‘Enabled’ attribute 读取并记录属性
Report.Info(repo.MyApp.Buttons.ButtonAdd.Enabled.ToString());

// Using Ranorex.RadioButton adapter
// represented by ‘GenderOption’

// Select radio button 选择radio button
repo.MyApp.GenderOption.Select();

// Accessing listitems of Ranorex.List adapter
// represented by ‘CategoryList’
IList<ranorex.listitem> listItems = repo.MyApp.CategoryList.Items;
foreach ( Ranorex.ListItem item in listItems )
{
Report.Info(item.Text + ” is member of CategoryList”);
}

// Using Ranorex.MenuItem to open ‘File’ menu
repo.MyApp.MenuItemFile.Select();
// Selecting sub menu item ‘Connect’
repo.FileMenu.Connect.Select();
// Read and log ‘Enabled’ state of menu item ‘Connect’
Report.Info(repo.FileMenu.Connect.Enabled.ToString());
}
}

Read More