1g網(wǎng)站空間多少錢百度一下網(wǎng)頁搜索
代碼示例
下面的代碼示例將講解如何使用Ranorex API來編寫代碼模塊,或者是使用用戶代碼來擴(kuò)展錄制的模塊。
在代碼中使用對(duì)象庫
使用對(duì)象庫等待UI元素
建立Adapter來訪問更多的屬性和方法
為對(duì)象庫元素建立一組Adapter
使用Validate類
強(qiáng)制一個(gè)測試用例失敗
設(shè)置automation speed
訪問測試用例和測試簇的上下文
高級(jí)代碼示例
如果做基于圖像的自動(dòng)化
如何查找和比較圖像
處理意外的對(duì)話框
在代碼中使用對(duì)象庫
C#
[TestModule(“D451F1D1-C347-4B58-939F-F6187642EB56”, ModuleType.UserCode, 1)]
public class UsingRepository : ITestModule
{
// Repository object to access UI elements 用來訪問UI元素的對(duì)象庫對(duì)象
MyFirstTestProjectRepository repo = MyFirstTestProjectRepository.Instance;
/// <summary>
/// Constructs a new instance. ?創(chuàng)建一個(gè)新實(shí)例
/// </summary>
public UsingRepository()
{
// Do not delete – a parameterless constructor is required! 不要?jiǎng)h,需要無參構(gòu)造器
}
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是對(duì)象庫中的文件夾
// the ‘Self’ property returns an object of type Ranorex.Form self用來返回對(duì)象
// Activates application 激活應(yīng)用
repo.MyApp.Self.Activate();
// Log ‘Active’ state 記錄狀態(tài)
Report.Info(repo.MyApp.Self.Active.ToString());
// Maximize, Minimize and Restore 最大化,最小化,復(fù)原大小
repo.MyApp.Self.Maximize();
repo.MyApp.Self.Minimize();
repo.MyApp.Self.Restore();
// Closes application 關(guān)閉應(yīng)用
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());
}
}
VB.NET
Public Class UsingRepository
Implements ITestModule
‘ Repository object to access UI elements
Private repo As MyFirstTestProjectRepository = MyFirstTestProjectRepository.Instance
”’ <summary>
”’ Constructs a new instance.
”’ </summary>
‘ Do not delete – a parameterless constructor is required!
Public Sub New()
End Sub
”’ <summary>
”’ Performs the playback of actions in this module.
”’ </summary>
”’ <remarks>You should not call this method directly, instead pass the module
”’ instance to the <see cref=”TestModuleRunner.Run(ITestModule)”> method
”’ that will in turn invoke this method.</see></remarks>
Private Sub ITestModule_Run() Implements ITestModule.Run
Mouse.DefaultMoveTime = 300
Keyboard.DefaultKeyPressTime = 100
Delay.SpeedFactor = 1.0
‘ Using Ranorex.Form adapter represented by ‘MyApp’
‘ ‘MyApp’ is used as a folder within the repository;
‘ the ‘Self’ property returns a Ranorex.Form object
‘ 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
repo.MyApp.GenderOption.[Select]()
‘ Accessing listitems of Ranorex.List adapter
‘ represented by ‘CategoryList’
Dim listItems As IList(Of Ranorex.ListItem) = repo.MyApp.CategoryList.Items
For Each item As Ranorex.ListItem In listItems
Report.Info(item.Text & ” is member of CategoryList”)
Next
‘ 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())
End Sub
End Class
?