当前位置:网站首页>Katalon中控件的参数化
Katalon中控件的参数化
2022-07-04 03:47:00 【春天的菠菜】
背景:
在Katalon中,我们通过Spy抓取的控件,保存在Object Repository中,其中的定位的属性是固定的
如果把这些固定的定位属性参数化呢,一种方式是直接通过Xpath路径,创建Test Object,另外一种
方法是把,获取到的控件定位属性参数化
如何进行参数化呢?
定位属性参数化:
所谓控件定位属性参数化,就是当这个控件运行的时候,动态给定位属性参数具体的值,如text
用一个实际的例子来看
假设APP启动的时候有一个引导界面,其中需要我们从六个兴趣标签中点击选择
通过Spy Mobile,我们可以看到这几个兴趣标签,但无法通过resource-id来区分,因为resource-id都一样
但Text是不一样的,那么我们就是需要把这个Text进行参数化,在运行的时候,给不同的Text值,从而选择
不同的控件
捕获到的控件如下,其中一共有六个控件,其中resource-id其实都是一样的
如果我们要把其中的text修改为动态的属性
此时我们需要把text的vlaue修改为 ${textname}
此时表示这个属性为动态的
并且关联的动态变量的名字为testname
在testcase中的命令中选择使用这个控件,此时打开Test Object Input
在这个Test Object选择中,下面有一个“Variables"
在这个Variables中可以创建一个变量,同时指定变量的值
指定的变量名,需要和Object Repository中,控件属性中指定的变量名要一致,即设置为"testname"
此时切换到Scripts中,可以看到详细的命令
Mobile.tap(findTestObject('tag_label', [('textname') : '军事知识']), 0)
当然这个动态的变量,可以支持文本,数字,或者Katalon中的变量,全局变量等
如可以在Variables中,添加了一个变量,如叫label
此时,命令就变成了
Mobile.tap(findTestObject('tag_label', [('textname') : label]), 0)
通过这种方式,我们可以在运行的时候,参数化控件的定位属性
那么,在一开始六个相似的Text控件,我们可以在Object Repository,只保留一个
而不需要创建六个相似的控件,但只是Text属性不同
如果依次点击,可以通过传递不同的Text的值来分别动态定位
在脚本中,可能就是这样的
Mobile.tap(findTestObject('tag_label', [('textname') : '军事知识']), 0)
Mobile.tap(findTestObject('tag_label', [('textname') : '史前巨兽']), 0)
Mobile.tap(findTestObject('tag_label', [('textname') : '动物天地']), 0)
Mobile.tap(findTestObject('tag_label', [('textname') : '恐龙世界']), 0)
如果有多个动态的属性,其实是一样的
如添加resource-id也同样变成了动态的属性
那么命令如下:
Mobile.tap(findTestObject('tag_label', [('textname') : '军事知识', ('resouceid') : 'com.mxr.dreambook:id/tv_tag']), 0)
这部分的内容,Katalon的帮助中有说明
可以参考
https://docs.katalon.com/katalon-studio/docs/manage-test-object.html#test-objects-in-scripting-view
定位序列:
现在还是思考这个六个相似的TextView,已经实现通过Text属性来动态定位,但如果要循环点击这六个标签
我们必须先创建一个数值,类似['军事知识','恐龙世界','动物世界'],然后通过循环来遍历
但如果Text的内容修改了,则会失效,并且通过文本数组来遍历有些笨重
我们想是否可以通过序列来遍历呢?
一开始观察的时候,想到是否可以通过instance的属性
因为这六个不同的TextView,其中的instance的属性分别是3,4,5,6,...
实际尝试后发现通过instance无法定位,因为instance属性是无法生效的,
我们在xpath中,如果定位到多个,是可以通过[i]来区分
此时可以在Object Repository中,修改那个控件的定位方式为xpath
Xpath属性为
(//*[@class = 'android.widget.TextView' and @resource-id = 'com.mxr.dreambook:id/tv_tag'])[${index}]
其中,我们把这个index作为一个动态的参数,类似之前的方法
在脚本中,我们就可以通过1到6的循环来循环点击这个标签
//选择六个兴趣标签
for (def i : (1..6)) {
Mobile.tap(findTestObject('4Dapp/flashpage/tagselect/tag_Text', [('index') : i]), 5)
}
这样就实现了动态的循环
这部分的实现,可以参考Katalon的说明
https://docs.katalon.com/katalon-studio/docs/parameterize-webmobile-test-object-properties.html
参考项目
Katalon官方参考项目
边栏推荐
- Development of digital collection trading platform development of digital collection platform
- Future源碼一觀-JUC系列
- How to dynamically cache components in Vue multi-level route nesting
- 1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
- 基于PHP的轻量企业销售管理系统
- 投资深度思考
- 【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
- PostgreSQL users cannot create table configurations by themselves
- Katalon框架测试web(二十一)获取元素属性断言
- [paddleseg source code reading] paddleseg calculates Miou
猜你喜欢
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
用于TCP协议交互的TCPClientDemo
Summary of Chinese remainder theorem
[paddleseg source code reading] paddleseg custom data class
选择排序与冒泡排序模板
pytest多进程/多线程执行测试用例
'2'>' 10'==true? How does JS perform implicit type conversion?
Monitoring - Prometheus introduction
What kind of experience is it when the Institute earns 20000 yuan a month!
SQL语句加强练习(MySQL8.0为例)
随机推荐
Zigzag scan
三年进账35.31亿,这个江西老表要IPO了
[paddleseg source code reading] paddleseg calculation dice
Graduation summary
Tcpclientdemo for TCP protocol interaction
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
@Scheduled scheduled tasks
Nbear introduction and use diagram
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
Webhook triggers Jenkins for sonar detection
Defensive programming skills
Storage of MySQL database
渗透实战-SQLServer提权
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Consul of distributed service registration discovery and unified configuration management
PostgreSQL users cannot create table configurations by themselves
Slurm view node configuration information
Katalon framework tests web (XXI) to obtain element attribute assertions
“软硬皆施”,助力建成新型云计算数据中心
新型数据中心,助力加快构建以数据为关键要素的数字经济