Qt Windows自定义GUI界面自动化测试——uiautomatio通过树节点属性定位控件
Qt Windows自定义GUI界面自动化测试提示点击链接跳转其他相关文章Windows自定义GUI界面自动化测试框架选择autoituiautomatio基本使用uiautomatio通过树节点属性定位控件uiautomatio通过树节点属性定位控件Qt Windows自定义GUI界面自动化测试前言一、实现方式inspect.exeuiautomation.py窗口相关二、使用步骤1.引入库2.读入数据总结前言前面我们已经对与windows GUI应用自动化测试工具进行了大致介绍并选用python搭建uiautomation的方式实现Qt应用程序的自动化测试通过inspect.exe进行附注获取窗口界面控件及各个属性。进行了简单的界面控件操作我们发现通过调用uiautomation不管是获取item还是button都需要一个控件名或者IdName、uiautomationId等参数但是稍微复杂一点的Qt项目都涉及到许多自定义控件来封装自定义的样式或实现方法这就使得uiautomation无法匹配到特定的类型或通过其名称寻找到指定控件考虑到直接控制鼠标到固定坐标点进行操作无法应对某些多变的响应情况所以选用控件父子节点关系来选中到唯一指定的控件。需要注意的是某些界面中的控件存在动态显影效果这会使得uiautomation无法实时获取对应的控件和位置在史记操作中我们应该对此类控件的查找进行慎重考虑。一、实现方式inspect.exe快捷键功能CtrlShiftF6父节点CtrlShiftF7第一个子节点CtrlShiftF8下一个子节点CtrlShiftF9下一个相邻节点CtrlShiftF5上一个相邻节点标记边框通过快捷键可以查看控件的关系也可以通过查询窗口左侧的工程树直接查看uiautomation.py获取节点相关函数及使用。此处建议先浏览def WalkTree(函数属性一下相关操作原理。下面是WalkTree()对应源码实现。defWalkTree(top,getChildren:Callable[[TreeNode],List[TreeNode]]None,getFirstChild:Callable[[TreeNode],TreeNode]None,getNextSibling:Callable[[TreeNode],TreeNode]None,yieldCondition:Callable[[TreeNode,int],bool]None,includeTop:boolFalse,maxDepth:int0xFFFFFFFF):ifmaxDepth0:returndepth0ifgetChildren:ifincludeTop:ifnotyieldConditionoryieldCondition(top,0):yieldtop,0,0childrengetChildren(top)childList[children]whiledepth0:# or while childList:lastItemschildList[-1]iflastItems:ifnotyieldConditionoryieldCondition(lastItems[0],depth1):yieldlastItems[0],depth1,len(lastItems)-1ifdepth1maxDepth:childrengetChildren(lastItems[0])ifchildren:depth1childList.append(children)dellastItems[0]else:delchildList[depth]depth-1elifgetFirstChildandgetNextSibling:ifincludeTop:ifnotyieldConditionoryieldCondition(top,0):yieldtop,0childgetFirstChild(top)childList[child]whiledepth0:# or while childList:lastItemchildList[-1]iflastItem:ifnotyieldConditionoryieldCondition(lastItem,depth1):yieldlastItem,depth1childgetNextSibling(lastItem)childList[depth]childifdepth1maxDepth:childgetFirstChild(lastItem)ifchild:depth1childList.append(child)else:delchildList[depth]depth-1函数说明不使用递归算法遍历树。top: 初始节点.getChildren: 返回子节点listList[TreeNode].getFirstChild: 返回第一个子节点TreeNode.getNextSibling: 返回下一个邻节点TreeNode.yieldCondition: 迭代条件includeTop: 是否从top节点开始迭代maxDepth: int, 遍历深度.如果getChildren有效则忽略getFirstChild和getNextSibling迭代3 items元组treeNodedepth在当前深度中保留子项计数。如果getChildren无效则使用getFirstChild和getNextSibling迭代2 items元组treeNodedepth。如果yieldCondition不为None则只生成迭代条件treeNode:treeNodedepth:int-bool返回True的树节点。代码如下示例defGetDirChildren(dir_):ifos.path.isdir(dir_):return[os.path.join(dir_,it)foritinos.listdir(dir_)]forit,depth,leftCountinWalkTree(D:\\,getChildrenGetDirChildren):print(it,depth,leftCount)窗口相关classWindowPattern():defClose(self,waitTime:floatOPERATION_WAIT_TIME)-bool:defIsModal(self)-bool:defIsTopmost(self)-bool:defWindowInteractionState(self)-int:#窗口交互状态classControl():defIsEnabled(self)-bool:defIsKeyboardFocusable(self)-bool:defGetAncestorControl(self,condition:Callable[[Control,int],bool])-Control:defGetParentControl(self)-Control:defGetFirstChildControl(self)-Control:defGetLastChildControl(self)-Control:defGetNextSiblingControl(self)-Control:defGetPreviousSiblingControl(self)-Control:defGetSiblingControl(self,condition:Callable[[Control],bool],forward:boolTrue)-Control:defGetChildren(self)-List[Control]:defGetPosition(self,ratioX:float0.5,ratioY:float0.5)-Tuple[int,int]:defMoveCursorToMyCenter(self,simulateMove:boolTrue)-Tuple[int,int]:defClick(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,simulateMove:boolTrue,waitTime:floatOPERATION_WAIT_TIME)-None:defMiddleClick(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,simulateMove:boolTrue,waitTime:floatOPERATION_WAIT_TIME)-None:defRightClick(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,simulateMove:boolTrue,waitTime:floatOPERATION_WAIT_TIME)-None:defDoubleClick(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,simulateMove:boolTrue,waitTime:floatOPERATION_WAIT_TIME)-None:defRightDragDrop(self,x1:int,y1:int,x2:int,y2:int,moveSpeed:float1,waitTime:floatOPERATION_WAIT_TIME)-None:defWheelDown(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,wheelTimes:int1,interval:float0.05,waitTime:floatOPERATION_WAIT_TIME)-None:defWheelUp(self,x:intNone,y:intNone,ratioX:float0.5,ratioY:float0.5,wheelTimes:int1,interval:float0.05,waitTime:floatOPERATION_WAIT_TIME)-None:二、使用步骤1.引入库代码如下示例import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import warnings warnings.filterwarnings(ignore)import ssl ssl._create_default_https_contextssl._create_unverified_context2.读入数据代码如下示例datapd.read_csv(https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv)print(data.head())该处使用的url网络请求的数据。总结提示这里对文章进行总结例如以上就是今天要讲的内容本文仅仅简单介绍了pandas的使用而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2483273.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!