Mac下的UI自动化测试 (三)
2015-07-16 11:20
507 查看
使用sikuli进行UI自动化测试固然是方便很多,不用一切都使用AppleScript那烦人的语法,只要界面的UI没有变化,结构的变化不会影响到基于sikuli的自动化,但是基于AppleScript的就会受到影响。
而且使用图像识别进行自动化,会比使用脚本实现的自动化更接近于真实的手动测试,毕竟人就是通过人眼来识别控件的,所以控件在UI上的变化都会影响到sikuli自动化,而对于BVT级别的自动化,重点还是关注与基本功能是否正常,对控件在UI上的变化还是不那么敏感为好。
在我实现一个产品的BVT自动化的时候,需要操作某些视频的缩略图进行上传到云端,和从云端下载下来的测试,其中大量依赖于其测试素材缩略图的识别,而产品在测试过程中发现了一个缩略图不能正常产生的bug,而这个bug势必会影响到我们其他BVT功能的测试。为了不使得这个bug block我们其他基本功能的验证,我采用的是使用AppleScript获取其测试素材在library中的坐标,然后使用一个工具cliclick来对获取到的坐标进行鼠标左右键的单击和双击等操作。
下面是官网上对这个模拟鼠标和键盘操作的小工具的介绍:
“Cliclick” is short for “Command-Line Interface Click”. It is a a tiny shell/Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates. Moreover, it lets you move the mouse, get the current mouse coordinates, press modifier keys etc.
首先,使用AppleScript获取这个素材的坐标,(由于一个缩略图的操作焦点应该是其正中央的位置,所以在下面的脚本中要进行一次计算,将中间点的坐标输出):
在python中,先调用上面的脚本获取坐标,再根据需要的操作使用cliclick的不同参数实现:
在这里,python充当的就是一个胶水的作用,将AppleScript的输出用在工具cliclick上,并返回结果。
而且使用图像识别进行自动化,会比使用脚本实现的自动化更接近于真实的手动测试,毕竟人就是通过人眼来识别控件的,所以控件在UI上的变化都会影响到sikuli自动化,而对于BVT级别的自动化,重点还是关注与基本功能是否正常,对控件在UI上的变化还是不那么敏感为好。
在我实现一个产品的BVT自动化的时候,需要操作某些视频的缩略图进行上传到云端,和从云端下载下来的测试,其中大量依赖于其测试素材缩略图的识别,而产品在测试过程中发现了一个缩略图不能正常产生的bug,而这个bug势必会影响到我们其他BVT功能的测试。为了不使得这个bug block我们其他基本功能的验证,我采用的是使用AppleScript获取其测试素材在library中的坐标,然后使用一个工具cliclick来对获取到的坐标进行鼠标左右键的单击和双击等操作。
下面是官网上对这个模拟鼠标和键盘操作的小工具的介绍:
“Cliclick” is short for “Command-Line Interface Click”. It is a a tiny shell/Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates. Moreover, it lets you move the mouse, get the current mouse coordinates, press modifier keys etc.
首先,使用AppleScript获取这个素材的坐标,(由于一个缩略图的操作焦点应该是其正中央的位置,所以在下面的脚本中要进行一次计算,将中间点的坐标输出):
on run argv set clip_name to item 1 of argv tell application "RealTimes" activate end tell tell application "System Events" tell process "RealTimes" tell UI element 0 of scroll area 0 of group 0 of splitter group 0 of splitter group 0 of window 0 tell (1st image whose title is clip_name) set p to position set s to size set x to ((item 1 of p) + (item 1 of s) / 2) set y to ((item 2 of p) + (item 2 of s) / 2) set output to ("" & x & "," & y) do shell script "echo " & quoted form of output end tell end tell end tell end tell end run
在python中,先调用上面的脚本获取坐标,再根据需要的操作使用cliclick的不同参数实现:
def click_item_by_cliclick(name): command = cliclick_path + " c:{0}" _run_for_cliclick(name, command) def double_click_item_by_cliclick(name): command = cliclick_path + " dc:{0}" _run_for_cliclick(name, command) def right_click_item_by_cliclick(name): command = cliclick_path + " kd:ctrl c:{0} ku:ctrl" _run_for_cliclick(name, command) def check_exist_by_cliclick(name): try: run_apple_script("get_clip_position_in_library.applescript", name) except Exception: return False return True def _run_for_cliclick(name, command): co = run_apple_script("get_clip_position_in_library.applescript", name).strip().rstrip('\n') time.sleep(1) command = command.format(co) ret = exec_command(command) if ret[0] != 0: raise Exception(ret[1]) def multiple_select_by_cliclick(names): command = " kd:cmd" for name in names: command += " c:" + run_apple_script("get_clip_position_in_library.applescript", name).strip().rstrip('\n') command += " ku:cmd" command = cliclick_path + command ret = exec_command(command) if ret[0] != 0: return False return True
在这里,python充当的就是一个胶水的作用,将AppleScript的输出用在工具cliclick上,并返回结果。
相关文章推荐
- JS生成UUID
- kqueue示例
- Null value was assigned to a property of primitive type setter of cn.itcast.oa.domain.Forum.topicCount
- Win10 Build 10240改进汇总:浏览器性能提升
- [Poj2478]Farey Sequence
- 设置UITableViewCell背景色
- UICollectionview实现类似UITableview的sectionheader悬浮代码
- 奇异值分解(We Recommend a Singular Value Decomposition)
- Connection is read-only. Queries leading to data modification are not allowed
- AdapterView与Adapter(五) --AsyncQueryHandler
- Libgdx之封装简单的脚本机制
- Daikon Forge GUI Library(dfgui)之OnDragStart、OnDragEnd、OnDragDrop
- Timer更新UI的方法
- ios上 更改 状态栏(UIStatusBar)
- Android UI学习 - GridView和ImageView的使用
- SAPUI5-List
- Android 模仿C# WPF的Dispatcher的UI同步调用
- UITextView不可编辑——被userInteractionEnabled坑了
- UE3到UE4过渡的指导
- ios 关于UITextField 和UILabel