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文件过大