接口文档

Submodules

tuia.qpathparser module

QPath解析器

QPath是一个用于定位各个平台的UI控件(除Web控件)的查询语言。

  • QPath语法定义如下:

    QPath ::= Seperator QPath Seperator UIObjectLocator
    UIObjectLocator ::= UIObjectProperty PropertyConnector UIObjectLocator
    UIObjectProperty ::= UIProperty 
                        | RelationProperty 
                        | IndexProperty
                        | UITypeProperty 
    UIProperty ::= PropertyName Operator Literal
    RelationProperty ::= MaxDepthIdentifier EqualOperator Literal
    IndexProperty ::= InstanceIdentifier EqualOperator Literal
    UITypeProperty ::= UITypeIdentifier EqualOperator StringLiteral
    MaxDepthIdentifier := "MaxDepth"
    InstanceIdentifier ::= "Instance"
    UITypeIdentifier := "UIType"
    Operator ::= EqualOperator | MatchOperator
    PropertyConnector ::= "&&"
    Seperator ::= "/"
    EqualOperator ::= "="  #精确匹配
    MatchOperator ::= "~="  #使用正则进行模糊匹配
    PropertyName  ::= "[a-zA-Z_]*"
    Literal := StringLiteral
              | IntegerLiteral
              | BooleanLiteral
    StringLiteral ::= ""[a-zA-Z_]*""
    IntegerLiteral ::= "[0-9]*"
    BooleanLiteral := "True" | "False" | "true" | "false"
    
  • 需要注意的是,QPath的属性名都是大小写无关的。

  • 简单举例如下:

    / ClassName='TxGuiFoundation' && Caption~='QQ\d+' / name='mainpanel'
    
class tuia.qpathparser.Literal(value, lexpos)

基类:object

QPath属性常量值

class tuia.qpathparser.Operator(value, lexpos)

基类:object

QPath操作符

class tuia.qpathparser.PropertyName(value, lexpos)

基类:object

QPath属性名

class tuia.qpathparser.QPathLexer

基类:object

QPath词法解析器

bad_match = '~[^=*]'
bad_octal_constant = '0[0-7]*[89]'
boolean_constant = '(True)|(False)|(true)|(false)'
decimal_constant = '(0)|([1-9][0-9]*)'
escape_sequence_1 = '(?<=\\\\)"'
escape_sequence_2 = "(?<=\\\\)'"
hex_constant = '0[xX][0-9a-fA-F]+'
hex_digits = '[0-9a-fA-F]+'
hex_prefix = '0[xX]'
input(qpath_string)

词法分析输入

参数:qpath_string (str) -- QPath字符串
octal_constant = '0[0-7]+'
string_char_1 = '([^"]|(?<=\\\\)")'
string_char_2 = "([^']|(?<=\\\\)')"
string_literal = '("([^"]|(?<=\\\\)")*")|(\'([^\']|(?<=\\\\)\')*\')'
string_literal_1 = '"([^"]|(?<=\\\\)")*"'
string_literal_2 = "'([^']|(?<=\\\\)')*'"
t_AND = '(&&)|(&)'
t_BAD_MATCH(t)
t_BOOL_CONST(t)
t_EQUAL = '='
t_INT_CONST_DEC(t)
t_INT_CONST_HEX(t)
t_INT_CONST_OCT(t)
t_MATCH = '~='
t_MINUS = '-'
t_PROPERTY = '[a-zA-Z_][0-9a-zA-Z_]*'
t_SEPERATOR = '/'
t_STRING_LITERAL(t)
t_error(t)
t_ignore = '\t '
token()

解析并返回一个Token

tokens = ['SEPERATOR', 'EQUAL', 'MATCH', 'AND', 'BOOL_CONST', 'STRING_LITERAL', 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'PROPERTY', 'MINUS']
class tuia.qpathparser.QPathParser(verbose=False)

基类:object

QPath语法解析器

QPath解析器解析QPath后会生成两个结构:

1. QPath结构列表:每一个UIObjectLocator用一个字典表示 其中字典的键值为属性名,对应的值为一个长度为2的列表,第一个元素为操作符号, 目前为字符串'='或'~=',第二个元素为属性值

2. QPath词法位置信息:和解析后的结构对应,每一个UIObjectLocator用一个字典表示 其中字典的键值为属性名,对应的指为一个长度为3的列表,第一个元素为属性名的 词法位置,第二个元素为操作符的词法位置,第三个元素为属性值的词法位置

比如以下的QPath:

/ ClassName="TxGuiFoundation" && Caption1~='QQ\d+' && Instance=-1 / UIType='GF' && name='mainpanel' && MaxDepth=10

解析后得到的结构列表为:

[{'Caption1': ['~=', 'QQ\d+'],
  'ClassName': ['=', 'TxGuiFoundation'],
  'Instance': ['=', -1]},
 {'MaxDepth': ['=', 10], 
  'UIType': ['=', 'GF'], 
  'name': ['=', 'mainpanel']}]

解析后得到的词法位置信息表为:

[{'CAPTION1': [33, 41, 43],
  'CLASSNAME': [2, 11, 12],
  'INSTANCE': [54, 62, 63]},
 {'MAXDEPTH': [103, 111, 112], 
  'NAME': [83, 87, 88], 
  'UITYPE': [68, 74, 75]}]

使用方法示例:

qp ="""/ ClassName="TxGuiFoundation" && Caption1~='QQ\d+' && Instance='-1' / UIType='GF' && name='mainpanel' && MaxDepth='10'"""
parser = QPathParser()
qpath_struct, lex_info = parser.parse(qp)
INT_TYPE_PROPNAMES = ['INSTANCE', 'MAXDEPTH']
p_error(p)

处理错误

p_int_const(p)

int_const : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | MINUS int_const

p_object_locator(p)

object_locator : prop | object_locator AND prop

p_operator(p)

operator : EQUAL | MATCH

p_prop(p)

prop : prop_name operator prop_value

p_prop_name(p)

prop_name : PROPERTY

p_prop_value(p)

prop_value : STRING_LITERAL | BOOL_CONST | int_const

p_qpath(p)

qpath : SEPERATOR qpath_content

p_qpath_content(p)

qpath_content : | object_locator | qpath_content SEPERATOR object_locator

parse(qpath_string)

返回解析后的结果

参数:qpath_string (string) -- QPath字符串
返回:list, list - 解析后结构, 词法位置信息
exception tuia.qpathparser.QPathSyntaxError(qpath_string, err_msg, lexpos)

基类:exceptions.Exception

QPath语法错误

class tuia.qpathparser.UIObjectLocator(properties)

基类:object

QPath Locator

append(prop)

增加一个属性

参数:prop (UIObjectProperty) -- 属性
dumps()

序列化

返回:list
format()

格式化字符串

返回:str
class tuia.qpathparser.UIObjectProperty(name, operator, value)

基类:object

QPath属性

format()

格式化字符串

返回:str

tuia.qpathparser module

异常模块定义

exception tuia.exceptions.ControlAmbiguousError

基类:exceptions.Exception

找到多个控件

exception tuia.exceptions.ControlExpiredError

基类:exceptions.Exception

控件失效错误

exception tuia.exceptions.ControlNotFoundError

基类:exceptions.Exception

控件没有找到

exception tuia.exceptions.TimeoutError

基类:exceptions.Exception

超时异常

Module contents

Tuia:Tencent UI Automation Framework