• appium(1)-获取APPdriver封装


    lib目录下面:

    lib/GetDriver.py   (启动APP)

    # -*- coding: utf-8 -*-
    '''
    Created on 2019/11/6
    
    @author: 01372445
    '''
    
    from appium import webdriver
    from time import sleep
    import ReadConfig
    import GetDeviceInfo
    
    def getdriver():
        readcf = ReadConfig.ReadConfig()
        url = readcf.getitemvalue("device","url")
        platformName = readcf.getitemvalue("device", "platformName")
        automationName = readcf.getitemvalue("device", "automationName")
        appPackage = readcf.getitemvalue("device", "appPackage")
        appActivity = readcf.getitemvalue("device", "appActivity")
    
        device = GetDeviceInfo.GetDeviceInfo()
        deviceName = device.GetDeviceName()
    
        u"启动app接口"
        desired_caps = {}
        desired_caps['platformName'] = platformName
        desired_caps['deviceName'] = deviceName
        desired_caps['automationName'] = automationName
        desired_caps['appPackage'] = appPackage
        desired_caps['appActivity'] = appActivity
        desired_caps['resetKeyboard'] = 'true'
        desired_caps['unicodeKeyboard'] = 'true'
        desired_caps['noReset'] = True # appium1.6以后的版本需要这个设置才可以保存app的登录状态
        driver = webdriver.Remote(command_executor = url, desired_capabilities = desired_caps)
        return driver
    
    
    if __name__ == '__main__':
        a=getdriver()

    lib/ReadConfig.py   (读取相关的配置)

    # -*- coding: utf-8 -*-
    '''
    Created on 2019/11/6
    
    '''
    import  configparser
    import os
    
    class ReadConfig():
        def __init__(self):
            self.currentdir = os.getcwd()
            self.configfilepath = str(self.currentdir) + "config.ini"
            self.cf = configparser.ConfigParser()
            self.cf.read(self.configfilepath)
    
        def getitemvalue(self,section,item):
            itemvalue=self.cf.get(section,item)
            return itemvalue
    
    
    if __name__ == '__main__':
        a=ReadConfig()
        b=a.getitemvalue("email","username")
        print b

    lib/config.ini   (相关的配置)

    [device]
    platformName = android
    automationName = uiautomator2
    appPackage = xxx
    appActivity = xxx
    url = http://127.0.0.1:4723/wd/hub
    
    
    [email]
    smtpserver = xxx
    username =xxx
    password =xxx
    sender = xxx
    receiver = xxx
    
    [cmd]
    openAppium = node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js
    stopAppium = pkill node
    startServer = adb statr-server
    closeServer = adb kill-server
    checkPhone = adb get-state
    devicename = adb devices
    devicevesion= adb shell getprop ro.build.version.release

    public/GetDeviceInfo.py    (获取设备的相关信息)

    # -*- coding: utf-8 -*-
    '''
    Created on 2019/11/6
    
    @author: 01372445
    '''
    
    import ReadConfig
    import os
    import re
    
    class GetDeviceInfo():
        def __init__(self):
            self.readcf = ReadConfig.ReadConfig()
            self.namecmd = self.readcf.getitemvalue("cmd", "devicename")
            self.vesioncmd = self.readcf.getitemvalue("cmd", "devicevesion")
    
        def GetDeviceName(self):
            r = os.popen(self.namecmd)
            text = r.readlines()
            if len(text)==3:
                devicename = text[1].split()[0]
                print "devicename is",devicename
                return devicename
            elif len(text) > 3:
                print "该电脑连接了多台设备,请连接一台设备"
    
            else:
                print "无设备连接,请连接一台设备"
    
    
    
        def GetDevicePlatformVersion(self):
            r = os.popen(self.vesioncmd)
            text = r.read()
            version = str(text)
            print "设备的版本号:",version
            return version
    
    if __name__ == '__main__':
        a=GetDeviceInfo()
        a.GetDeviceName()
        a.GetDevicePlatformVersion()
  • 相关阅读:
    《PHP
    2018/06/11 数据库设计规范
    RequireJs 与 SeaJs的相同之处与区别
    null 与 undefinded
    page 分页
    fullPage的使用
    touch事件(寻找触摸点 e.changedTouches)
    t添加最佳视口
    随鼠标动的炫彩小球
    随机小球
  • 原文地址:https://www.cnblogs.com/dmtz/p/11807480.html
Copyright © 2020-2023  润新知