当前位置:   article > 正文

Python+Appium自动化测试框架_appium python框架

appium python框架

3.5.1 Appium录制
在这里插入图片描述

从左往右依次:
select Element:选定元素可以进行操作
Swipe By Coordinates:滑动坐标
Tap By Coordinates:点击坐标点(点击对应坐标)
Back:返回
Refresh Source:刷新
Start Recoding:录制
Search for element:搜索元素
手写Xpath 格式://*[@属性=‘属性值’] 属性一般是text,能唯一定位元素即可
Cope XML Source to Clipboard:复制XML元素
Quit Session:退出会话

点击录制然后操作内容即可,录制完成后
在这里插入图片描述
在这里插入图片描述

pip install Appium-Python-client 安装下这个库,运行这代码就可以执行我们刚才录制的操作了。

3.5.2 Python 关键字驱动Appium
这里我们要知道一个概念,就是多线程,App自动化和Web自动化的区别在于App自动化需要启动一个服务器,这个时候我们就要使用多线程。创建一个线程来运行appium服务器。
库:threading
创建子线程

target:子线程执行的任务
args:子线程执行的任务所需要的参数,元组形式
th=threading.Thread(target=run_appium(),args=(appiumpath,))
th.start()启动线程
  • 1
  • 2
  • 3
  • 4

使用node启动Appium服务,导入os库

os.system(“node”+F:\Appium\resources\app\node_modules\appium\build\lib\main.js)

结束node进程:

>   os.system('taskkill /F /IM node.exe ')
  • 1

Appium元素的click方法,input方法与web元素相同,这里就不介绍了
我把启动appium的方法放在这,其余方法自己封装

class App:
    """APP关键字库"""
    def __init__(self):
        self.port="4723"
        self.driver:webdriver.Remote=None

    def runappium(self,appiumpath="F:\Appium",port='4723'):
        """
        多线程执行appium
        :param appiumpath:
        :param port:
        :return:
        """
        if appiumpath is None or appiumpath=='':
            appiumpath="F:\Appium"

        if port is None or port=="":
            port='4723'

        appiumpath+=r"F:\Appium\resources\app\node_modules\appium\build\lib\main.js --port"+port
        def run_appium(appium_path):

            os.system("node"+appium_path)
        #创建子进程执行appium服务器启动
        th=threading.Thread(target=run_appium(),args=(appiumpath,))
        th.start()
        #设置appium 启动服务等待
        time.sleep(5)
        print("appium服务启动成功")

    def runapp(self,conf:str=''):
        """通过配置启动app"""
        #把json字符串配置,处理为字典
        conf=json.loads(conf)
        #需要连接appium
        self.driver=webdriver.Remote("http://127.0.0.1:%s/wd/hub" %self.port,conf)

        #添加隐式等待
        self.driver.implicitly_wait(10)

    def killappium(self):
        """
        结束appium服务
        :return:
        """
        os.system('taskkill /F /IM node.exe ')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
'
运行

3.6 Airtest小程序自动化
使用airtest完成小程序自动化,可参考
https://ke.qq.com/webcourse/2585942/102691176#taid=9108685039564118&vid=5285890803294751874

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/844813
推荐阅读
相关标签
  

闽ICP备14008679号