唉 !我还以为是线程调度的问题呢,结果竟然是执行命令行的调用方法有问题
def monkeyCmd(): os.system("adb shell monkey " + '-p ' + package_name + " -v -v -v -s " + str( seed) + " --ignore-crashes --ignore-timeouts --ignore-security-exceptions --kill-process-after-error --pct-trackball 0 --pct-nav 0 --pct-anyevent 0 --pct-flip 0 --pct-pinchzoom 0 --pct-syskeys 0 --throttle 300 " + test_times + " > monkeyTest.txt") # 启动一个线程运行Money命令 def monkeyRun(): threading.Thread(target=monkeyCmd()) #启动一个运行money 命令 print('启动一个线程开始monkey')
threading.Thread(target=monkeyCmd()) 启动一个Monkey命令后,代码没有继续向后运行,而是等待adb shell命令行中的内容执行完毕再继续
解决办法:
os.system("adb shell monkey " + '-p ' + package_name + " -v -v -v -s " + str(
seed) + " --ignore-crashes --ignore-timeouts --ignore-security-exceptions --kill-process-after-error --pct-trackball 0 --pct-nav 0 --pct-anyevent 0 --pct-flip 0 --pct-pinchzoom 0 --pct-syskeys 0 --throttle 300 " + test_times + " > monkeyTest.txt")
修改为
os.popen("adb shell monkey " + '-p ' + package_name + " -v -v -v -s " + str(修改后代码能继续向下执行而不用等待 adb shell命令执行结束后再往下执行
seed) + " --ignore-crashes --ignore-timeouts --ignore-security-exceptions --kill-process-after-error --pct-trackball 0 --pct-nav 0 --pct-anyevent 0 --pct-flip 0 --pct-pinchzoom 0 --pct-syskeys 0 --throttle 300 " + test_times + " > monkeyTest.txt")