# -*- coding: utf-8 -*-
from appium import webdriver
from time import sleep
import os
import threading, time
import unittest
#
from threading import Thread, Lock
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'] = 500
driver = webdriver.Remote('http://localhost:4723/wd/hub', desires_caps)
# run01 realizes that playing the first video 2s in the video list, then click the "next" button in the video playing
# interface, cut to the second video, play 6s, click UI to appear the progress bar, and then loop for 3 times every
# 2s screenshot
def run01():
for loop_time in range(1):
print('This is the %s times to play video of run01' % Test01time)
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)
for screen_time in range(3):
print("time:%s" % screen_time)
c = 200
d = 256
os.popen("adb shell input tap " + str(c) + " " + str(d))
screenname = fr"di1{Test01time}{screen_time}ci" + time.strftime("Y-%m-%d-%H_%M_%S",
time.localtime(time.time())) + ".png"
driver.get_screenshot_as_file(screenname)
sleep(2)
# run02 implements that playing the first video 2s in the video list, then click the "next" button on the play page
# to switch to the next video, play 2s, seek to the middle of the progress bar, play 6s, click the play page to
# appear in the progress bar and loop 3 times every 2s screenshot
def run02():
for loop_time in range(1):
print('This is the %s times to play video of run02' % 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)
for screen_time in range(3):
print("time:%s" % screen_time)
c = 200
d = 256
os.popen("adb shell input tap " + str(c) + " " + str(d))
screenname = fr"di2{Test02time}{screen_time}ci" + time.strftime("Y-%m-%d-%H_%M_%S",
time.localtime(time.time())) + ".png"
driver.get_screenshot_as_file(screenname)
sleep(2)
# run03 implements that playing the first video 3s in the video list,then click the second video in the video list,
# play 6s, click the play page to appear in the progress bar and loop 3 times every 2s screenshot
def run03():
for loop_time in range(1):
print('This is the %s times to play video of run03' % 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)
for screen_time in range(3):
print("time:%s" % screen_time)
c = 200
d = 256
os.popen("adb shell input tap " + str(c) + " " + str(d))
screenname = fr"di3{Test03time}{screen_time}ci" + time.strftime("Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
driver.get_screenshot_as_file(screenname)
sleep(2)
# run04 implements that playing the first video 3s in the video list, then click the second video in the video list,
# play 2s, seek to the middle of the progress bar,play 6s ,click the play page to appear in the progress bar and loop
# 3 times every 2s screenshot
def run04():
for loop_time in range(1):
print('This is the %s times to play video of run04' % 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
for screen_time in range(3):
print("time:%s" % screen_time)
os.popen("adb shell input tap " + str(c) + " " + str(d))
sleep(2)
screenname = fr"di4{Test04time}{screen_time}ci" + time.strftime("Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
driver.get_screenshot_as_file(screenname)
#logcat
def logcat_start01():
current = os.getcwd()
adblogcat_location = current
adblogname = r"adb_log_01" + f"{Test01time}" + 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_start02():
current = os.getcwd()
adblogcat_location = current
adblogname = r"adb_log_02" + f"{Test02time}" + 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))
def logcat_start03():
current = os.getcwd()
adblogcat_location = current
adblogname = r"adb_log_03" + f"{Test03time}" + 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))
def logcat_start04():
current = os.getcwd()
adblogcat_location = current
adblogname = r"adb_log_04" + f"{Test04time}" + 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))
#
# def logcat_close():
# cmd = 'adb logcat -c'
# os.system(cmd)
#screenshots
def scrren():
screenname = r"screen" + time.strftime("Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
driver.get_screenshot_as_file(screenname)
#Create the thread and run logcat_start and run01 and loop
class Testcase(unittest.TestCase):
def G6SATest01(self):
global Test01time
for Test01time in range(3):
threads = []
threads.append(threading.Thread(target=logcat_start01))
threads.append(threading.Thread(target=run01))
print(threads)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True) # 加了这个是说明 主线程 执行完了 子线程也停止(无论是否执行完毕)
t.start()
t.join()
def G6SATest02(self):
global Test02time
for Test02time in range(3):
threads = []
threads.append(threading.Thread(target=logcat_start02))
threads.append(threading.Thread(target=run02))
print(threads)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
def G6SATest03(self):
global Test03time
for Test03time in range(3):
threads = []
threads.append(threading.Thread(target=logcat_start03))
threads.append(threading.Thread(target=run03))
print(threads)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
def G6SATest04(self):
global Test04time
for Test04time in range(3):
threads = []
threads.append(threading.Thread(target=logcat_start04))
threads.append(threading.Thread(target=run04))
print(threads)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
# thread = []
# t1 = threading.Thread(target=logcat_start)
# thread.append(t1)
# t2 = threading.Thread(target=run04)
# thread.append(t2)
# if __name__ == '__main__':
# for t in thread:
# t.start()
# for t in thread:
# t.join()
# print("退出线程")
# def suite():
# suite = unittest.TestSuite()
# suite.addTests([Testcase("testG6SATest03"), Testcase("testG6SATest04")])
# return suite
#
#
# if __name__ == '__main__':
# runner = unittest.TextTestRunner(verbosity=2)
# runner.run(suite())
#
if __name__ == '__main__':
suite = unittest.TestSuite() # 创建测试套件
suite.addTest(Testcase("G6SATest01"))
suite.addTest(Testcase("G6SATest02"))
suite.addTest(Testcase("G6SATest03")) # 添加测试用例
suite.addTest(Testcase("G6SATest04"))
runner = unittest.TextTestRunner()
runner.run(suite)
G6SA复现bug步骤,并截图输出对应日志
最新推荐文章于 2023-04-03 14:22:49 发布