这个框架跟我有点像,哈哈
@ycwdaaaa 请问下你们测试用的请求数据和预期结果数据是手工准备维护的,还是自动生成的,特别是预期结果怎么自动生成
https://testerhome.com/topics/6878 看我这个是不是你想要的
咦,有小钱钱赚,看来不能只看不发
import time
import subprocess
import threading
import uiautomator as ui
class AppInitDeal(object):
def __init__(self,device=None,apk_path=None,app_packagename=None):
self.device = device
self.apk_path = apk_path
self.app_packagename = app_packagename
def ui_operate(self):
'对于apk在安装、卸载和执行case初始化时操作各种提示,暂定安装过程5秒'
d = ui.Device(self.device)
time_interval = 0
start_time = time.time()
while time_interval<10:
text_names=['安装','确定']#有其他需要的操作可扩展进来
for text_name in text_names:
time.sleep(1)
if d(text=text_name).exists:
d(text=text_name).click()
print("%s click sucess" % text_name)
break
time_interval= int(time.time()-start_time)
print('安装过程10秒')
def install_app(self):
'安装apk,多设备连入时需指定设备'
if self.device is None:
args = "adb install -r {0}".format(self.apk_path)
else:
args = "adb -s {0} install -r {1}".format(self.device,self.apk_path)
if self.apk_path is None:
return print('apk_path must be passed')
with subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True) as p1:
p1.wait()
stdout_result = p1.stdout.read()
if 'Success' in str(stdout_result):
print("{0} install sucess".format(self.apk_path))
elif 'Failure' in str(stdout_result):
print('{0} install fail'.format(self.apk_path))
def unstall_app(self):
'卸载apk,多设备连入时需指定设备'
if self.device is None:
args = "adb uninstall {0}".format(self.app_packagename)
else:
args = "adb -s {0} uninstall {1}".format(self.device, self.app_packagename)
if self.app_packagename is None:
return print('app_packagename must be passed')
with subprocess.Popen(args,stdout=subprocess.PIPE,shell=True) as p1:
p1.wait()
stdout_result = p1.stdout.read()
if 'Success' in str(stdout_result):
print("{0} uninstall sucess".format(self.app_packagename))
elif 'Failure' in str(stdout_result):
print('{0} uninstall fail'.format(self.app_packagename))
def app_init_ui_operate(self):
'多线程处理'
Thread_list=[]
fun_list = [self.install_app,self.ui_operate]
for fun in fun_list:
t = threading.Thread(target=fun)
t.setDaemon(True)
Thread_list.append(t)
t.start()
[thread.join() for thread in Thread_list]
pp = AppInitDeal(device="953cb9d0",apk_path=r"D:\360Downloads\Apk\9.0.1.073001.apk")
pp.app_init_ui_operate()
脚本单独能运行,但是放在 appium 的 case 里 setup 里脚本执行后,报错
A new session could not be created. (Original error: UiAutomator quit before it successfully launched)
appium 日志:
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
看日志自己去杀掉了进程,大神门这个何解