当前位置: 首页 > news >正文

自动化测试工具Ranorex Studio(四十三)-RANOREXPATH编辑器5

代码示例
下面的代码示例将讲解如何使用Ranorex API来编写代码模块,或者是使用用户代码来扩展录制的模块。
在代码中使用对象库
使用对象库等待UI元素
建立Adapter来访问更多的属性和方法
为对象库元素建立一组Adapter
使用Validate类
强制一个测试用例失败
设置automation speed
访问测试用例和测试簇的上下文
高级代码示例
如果做基于图像的自动化
如何查找和比较图像
处理意外的对话框

在代码中使用对象库

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

http://www.lryc.cn/news/492774.html

相关文章:

  • 超高流量多级缓存架构设计!
  • 数据结构(Java)—— ArrayList
  • 实习冲刺第三十三天
  • Uniapp开发下拉刷新功能onPullDownRefresh/onReachBottom
  • 什么是 C++ 中的函数对象?函数对象与普通函数有什么区别?如何定义和使用函数对象?
  • PointNet++论文复现
  • 【VUE】el-table表格内输入框或者其他控件规则校验实现
  • django开发中html继承模板样式
  • MT6769/MTK6769核心板规格参数_联发科安卓主板开发板方案
  • 鸿蒙进阶篇-状态管理之@Provide与@Consume
  • java集合及源码
  • GraphRAG访问模式和知识图谱建模
  • TCP/IP协议攻击与防范
  • Java基于 SpringBoot+Vue的口腔管理平台(附源码+lw+部署)
  • 11.26深度学习_神经网络-数据处理
  • 【人工智能】Python常用库-TensorFlow常用方法教程
  • 微信小程序按字母顺序渲染城市 功能实现详细讲解
  • 23省赛区块链应用与维护(房屋租凭【下】)
  • 数据结构-图-领接表存储
  • 快速入门web安全
  • rabbitMq两种消费应答失败处理方式
  • Qt C++(一) 5.12安装+运行第一个项目
  • 【RISC-V CPU Debug 专栏 1 -- RISC-V debug 规范】
  • 使用Gradle编译前端的项目
  • 网络爬虫——常见问题与调试技巧
  • 【AI绘画】Midjourney进阶:色调详解(下)
  • springboot+redis+lua实现分布式锁
  • 【Petri网导论学习笔记】Petri网导论入门学习(十一) —— 3.3 变迁发生序列与Petri网语言
  • docker-compose文件的简介及使用
  • [护网杯 2018]easy_tornado