• python自动化:通过uiautomator2实现云测


    该代码还存在优化的地方,后续优化方向:结合unittest、ddt、内反射搭建自动化测试框架

    实现代码如下:

    #通过u2实现云测
    import threading
    import uiautomator2 as u2
    import os,time
    from xctest_app.xc_tools.get_screenshot import *
    from xctest_app.xc_tools.get_aapt import *
    from xctest_app.xc_tools.get_devices import *
    class u2test:
        #设备的连接、软件的安装等前置操作
        def get_aapp(self,udid,path,pack_name):
            self.d=u2.connect(udid)
            os.system(f'adb -s {udid} install -r {path}')
            time.sleep(3)
            self.d.app_start(pack_name)
            s=self.d.session(pack_name,'True')
            return s
        #app中元素点击、断言等操作
        def get_capp(self,s):
            s.implicitly_wait(200)
            s.xpath('//*[@text="我"]').click()
            s.xpath('//*[@text="登录/注册"]').click()
            s.xpath('//android.widget.ListView/android.view.View[2]').click()
            s.xpath('//*[@resource-id="account"]').click()
            s.send_keys("13524490259", clear=True)
            s.xpath('//*[@resource-id="password"]').click()
            s.send_keys("123456", clear=True)
            s.xpath('//*[@resource-id="btn"]').click()
            s.xpath('//*[@text="我"]').click()
            r = s(text='13524490259').get_text()
            if r == '13524490259':
                print('登陆成功')
            else:
                print('登陆失败')
            #截图
            screenshot().get_ss(s)
        #总操作
        def get_appapp(self,udid,path,pack_name):
            s=self.get_aapp(udid,path,pack_name)
            self.get_capp(s)
            os.system(f'adb -s {udid} uninstall {pack_name}')
    
    if __name__ == '__main__':
        a=u2test()
        #调用封装的方法获取设备的udid
        b=devices().get_devices()
        #用封装的方法获取app的主包名
        c=packagename_activity().get_packagename('./xc_apk/wangyiyunyinyue.apk')[0]
        for i in b:
            threading.Thread(target=u2test().get_appapp,args=(i,'./xc_apk/wangyiyunyinyue.apk',c)).start()
  • 相关阅读:
    vue 侦听器
    vue 计算属性
    typeof 运算符
    constructor 属性
    立即执行函数与闭包
    计算属性缓存 vs 方法
    JavaScrip备课
    winform 实现对usb热拔插的监听
    c# async await的使用方式及为啥要用它
    .net5与之前的版本GetBytes长度变化
  • 原文地址:https://www.cnblogs.com/badbadboyyx/p/12132441.html
Copyright © 2020-2023  润新知