zoukankan      html  css  js  c++  java
  • 自动化测试

    一、特点

    airtest识别图片可以,但是文字不太行

    poco识别文字比较好

    所以结合使用

    二、方法使用技巧

    看的见的文字:poco(text="")

    页面中存在多个相同的文本:poco(text="")[2],选取第三次出现的元素

    文字模糊匹配:poco(textMatches="xxx.*")/poco(textMatches=".*xxx*.")

    图片:Template(r"xx.png", record_pos=(0.001, -0.243), resolution=(1080, 1920)),第一个参数图片文件,第二个是录制位置,第三个是录制的分辨率

    注意:poco的相对选择不太好使,强烈建议优先使用text,其次是空间选择[]

    断言:assert_equal(poco(text="xx").exists(), True, "执行失败")

    单条测试报告:必须用这种方式,否则不生成html的截图

    if not cli_setup():
        auto_setup(__file__, logdir=log_file_path, devices=[
            "Android://127.0.0.1:5037/SJE5T17927004209?cap_method=JAVACAP"
        ])
    
    simple_report(__file__, logpath=log_file_path, output=log_file_path + "/log.html")

    聚合报告:结合unittest批量执行,使用BeautifulReport生成

    三、公共

    解决等待时间问题:每次需要等待元素出现,然后操作,重写操作方法如click(),添加等待元素出现的方法即可

    wait(v,timeout=None,interval=0.5,intervalfunc=None)
    参数:
    • v – 要等待出现的目标Template实例
    • timeout – 等待匹配的最大超时时长,默认为None即默认取 ST.FIND_TIMEOUT 的值
    • interval – 尝试查找匹配项的时间间隔(以秒为单位)
    • intervalfunc – 在首次尝试查找匹配失败后的回调函数

     滚动屏幕查找元素

    滚动查找元素,当找到元素后,滑动元素到页面中间。
    
    用法:poco_swipe_to(text=None, textMatches=None, poco=None)
    
    # 滚动查找元素
    def poco_swipe_to(text=None, textMatches=None, poco=None):
        find_ele = False
        find_element = None
        if poco is None:
            raise Exception("poco is None")
        if text or textMatches:
            swipe_time = 0
            snapshot(msg="开始滚动查找目标元素")
            if text:
                find_element = poco(text=text)
            elif textMatches:
                find_element = poco(textMatches=textMatches)
            while True:
                snapshot(msg="找到目标元素结果: " + str(find_element.exists()))
                if find_element.exists():
                    # 将元素滚动到屏幕中间
                    position1 = find_element.get_position()
                    x, y = position1
                    if y < 0.5:
                        # 元素在上半页面,向下滑动到中间
                        poco.swipe([0.5, 0.5], [0.5, 0.5+(0.5-y)], duration=2.0)
                    else:
                        poco.swipe([0.5, 0.5], [0.5, 0.5-(y-0.5)], duration=2.0)
                    snapshot(msg="滑动元素到页面中间: " + str(text) + str(textMatches) )
                    find_ele = True
                    break
                elif swipe_time < 30:
                    poco.swipe([0.5, 0.8], [0.5, 0.4], duration=2.0)
                    # poco.swipe((50, 800), (50, 200), duration=500)
                    swipe_time = swipe_time + 1
                else:
                    break
        return find_ele
    
    引用:https://blog.csdn.net/u011608531/article/details/105283799/

    selenium:

    模糊匹配连接中的文本:find_element_by_partial_link_text()
    模糊匹配任意文本:find_element_by_xpath("//a[contains(text(),'文本')]").get_attribute('href')
  • 相关阅读:
    JavaWeb 之 三层架构:软件设计架构
    JavaWeb 之 MVC 开发模式
    JavaWeb 之 JSTL 标签
    Java 之 JSP
    【LeetCode-动态规划】不同的二叉搜索树
    【深度学习】模型压缩
    【LeetCode-数学】两数相除
    【LeetCode-链表】删除链表的倒数第N个节点
    【LeetCode-链表】合并K个排序链表
    【LeetCode-链表】合并两个有序链表
  • 原文地址:https://www.cnblogs.com/zyh0430/p/14654562.html
Copyright © 2011-2022 走看看