2020-10-30重复播放&脚本运行同时生成日志和截图python+appium

1.重复播放

from appium import webdriver
from time import sleep
import os,random
sleep(2)
desires_caps = {}
desires_caps['platformName'] = 'Android'
desires_caps['platformVersion'] = '8.1.0'
desires_caps['deviceName'] = '0000'
desires_caps['appPackage'] = 'com.desaysv_automotive.svmedia'
desires_caps['appActivity'] = 'com.desaysv_automotive.svmedia.activity.MainActivity'
desires_caps["automationName"] = 'uiautomator1'
desires_caps['noReset'] = True
desires_caps['newCommandTimeout']=240     //appium默认无操作时间为60s,这里改为240
driver = webdriver.Remote('http://localhost:4723/wd/hub',desires_caps)
videointerface = driver.find_element_by_id('com.desaysv_automotive.svmedia:id/media_video_fl')
sleep(1)
videointerface.click()
sleep(2)
for loop_time in range(100):
    driver.find_element_by_id('com.desaysv_automotive.svmedia:id/media_video_iv').click()
    print('This is the %s times to play video' % loop_time)
    sleep(120)                   //此处本应判断视频是否播完,但暂未实现,使用等待120s代替
    os.popen("adb shell input keyevent 4")    //用adb命令返回键
    sleep(1)
  

2.生成日志和截图
环境:pycharm或其他编辑器,appium

#    -*-    coding:    utf-8    -*-
from appium import webdriver
from time import sleep
import os,random
import threading,time
import subprocess

sleep(2)
desires_caps = {}
desires_caps['platformName'] = 'Android'
desires_caps['platformVersion'] = '8.1.0'
desires_caps['deviceName'] = '00001234'
desires_caps['appPackage'] = 'com.desaysv_automotive.svmedia'
desires_caps['appActivity'] = 'com.desaysv_automotive.svmedia.MainActivity'
desires_caps["automationName"] = 'uiautomator1'
desires_caps['noReset'] = True
desires_caps['newCommandTimeout']=240
driver = webdriver.Remote('http://localhost:4723/wd/hub',desires_caps)
def run01():
 for loop_time in range(250):
    print('This is the %s times to play video' % loop_time)
    driver.find_element_by_id('com.desaysv_automotive.svmedia:id/vedio_type_name').click()
    sleep(2)
    x = 455
    y = 560
    os.popen("adb shell input tap " + str(x) + " " + str(y))
    os.popen("adb shell input tap " + str(x) + " " + str(y))     //使用坐标进行定位并点击
    sleep(6)
    c = 200
    d = 256
    os.popen("adb shell input tap " + str(c) + " " + str(d))
    sleep(2)
    scrren()
    sleep(8)
def run02():
 for loop_time in range(250):
    print('This is the %s times to play video'% loop_time)
    driver.find_element_by_id('com.desaysv_automotive.svmedia:id/vedio_type_name').click()
    sleep(2)
    x = 455
    y = 560
    os.popen("adb shell input tap " + str(x) + " " + str(y))
    os.popen("adb shell input tap " + str(x) + " " + str(y))
    sleep(2)
    a = 383
    b = 499
    os.popen("adb shell input tap " + str(a) + " " + str(b))
    sleep(6)
    c = 200
    d = 256
    os.popen("adb shell input tap " + str(c) + " " + str(d))
    sleep(2)
    scrren()
    sleep(8)

def run03():
    for loop_time in range(250):
        print('This is the %s times to play video' % loop_time)
        driver.find_element_by_id('com.desaysv_automotive.svmedia:id/vedio_type_name').click()
        sleep(3)
        x = 1026
        y = 290
        os.popen("adb shell input tap "+ str(x) + " " + str(y))
        sleep(6)
        c = 200
        d = 256
        os.popen("adb shell input tap " + str(c) + " " + str(d))
        sleep(2)
        scrren()
        sleep(8)

def run04():
    for loop_time in range(250):
        print('This is the %s times to play video' % loop_time)
        driver.find_element_by_id('com.desaysv_automotive.svmedia:id/vedio_type_name').click()
        sleep(3)
        x = 1026
        y = 290
        os.popen("adb shell input tap " + str(x) + " " + str(y))
        sleep(2)
        a = 383
        b = 499
        os.popen("adb shell input tap " + str(a) + " " + str(b))
        sleep(6)
        c = 200
        d = 256
        os.popen("adb shell input tap " + str(c) + " " + str(d))
        sleep(2)
        scrren()
        sleep(8)


def logcat_start():                      //抓取日志
    current = os.getcwd()
    adblogcat_location = current        //日志位置
    adblogname = r"adb_log_" + time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".txt"              //日志名称
    os.system("cd %s && adb logcat >>%s 2>&1" % (adblogcat_location, adblogname))
    # cmd = 'adb logcat &>>%s 2>&1'%("D:\logcat\run01.txt")
    # os.system(cmd)
def logcat_close():
    cmd = 'adb logcat -c'
    os.system(cmd)
def scrren():
    screenname = r"screen"+ time.strftime("Y-%m-%d-%H_%M_%S",time.localtime(time.time())) + ".png"
    driver.get_screenshot_as_file(screenname)        //获取截图
def G6SATest01():                              //使用多线程实现脚本运行的同时,log文件生成
    threads = []
    t1 = threading.Thread(target=logcat_start)
    threads.append(t1)
    t2 = threading.Thread(target=run01)
    threads.append(t2)
    if __name__=='__main__':
      for t in threads:
	      t.start()
      for t in threads:
	      t.join()
    print("退出线程")

def G6SATest02():
    threads = []
    t1 = threading.Thread(target=logcat_start)
    threads.append(t1)
    t2 = threading.Thread(target=run02)
    threads.append(t2)
    if __name__=='__main__':
        for t in threads:
            t.start()
        for t in threads:
            t.join()
    print("退出线程")

def G6SATest03():
    threads = []
    t1 = threading.Thread(target=logcat_start)
    threads.append(t1)
    t2 = threading.Thread(target=run03)
    threads.append(t2)
    if __name__=='__main__':
        for t in threads:
            t.start()
        for t in threads:
            t.join()
    print("退出线程")

def G6SATest04():
    threads = []
    t1 = threading.Thread(target=logcat_start)
    threads.append(t1)
    t2 = threading.Thread(target=run04)
    threads.append(t2)
    if __name__ == '__main__':
        for t in threads:
            t.start()
        for t in threads:
            t.join()
    print("退出线程")

# G6SATest01()
# logcat_close()
G6SATest02()
# logcat_close()
G6SATest03()
# logcat_close()
G6SATest04()
# logcat_close()

问题:log文件过大

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值