其他分享
首页 > 其他分享> > monkey测试脚本.ps1

monkey测试脚本.ps1

作者:互联网

#aapt.exe adb.exe 设置为环境变量
#将脚本和apk包放在同一个文件夹
#.\monkeytest.ps1 -deviceid "123"   是monkey测试当前文件夹下所有apk
#.\monkeytest.ps1 -deviceid "123"  -apk_list ("androbench-5.0.1.apk", "HD Video Player.apk") 是monkey测试当前文件夹下指定的apk


#命令行参数
Param(
[string[]]$apk_list = $null,
[string]$deviceid = "0123456789ABCDEF"
)

#获取日期时间
$start = Get-Date

#获取根目录
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition

$CurrentyDir = $PSScriptRoot
echo "Currentdir: "$CurrentyDir
echo ""

#存在则删除此文件
$FILE_PATH="$CurrentyDir\$deviceid-*.txt"
$TRUE_FALSE=(Test-Path $FILE_PATH)
if($TRUE_FALSE -eq "True")
{
remove-Item -Recurse -Force $FILE_PATH
}

#if判断
if( $apk_list -eq $null ){
#获取包名 foreach循环 按当前文件夹下所有apk获取包名
foreach($i in dir $CurrentyDir\*.apk -name){aapt d badging $CurrentyDir\$i|Select-String 'package: name' >> $CurrentyDir\$deviceid-package1.txt}
gc $CurrentyDir\$deviceid-package1.txt|?{-not [String]::IsNullOrWhiteSpace($_)} | set-content $CurrentyDir\$deviceid-package_old.txt
gc $CurrentyDir\$deviceid-package_old.txt |%{$_.split('=')[1]}|%{$_.split(' ')[0]} >> $CurrentyDir\$deviceid-package.txt

}else{
#获取包名 按命令行参数提供apk获取包名
foreach($i in $apk_list){aapt d badging $CurrentyDir\$i|Select-String 'package: name' >> $CurrentyDir\$deviceid-package1.txt}
gc $CurrentyDir\$deviceid-package1.txt|?{-not [String]::IsNullOrWhiteSpace($_)} | set-content $CurrentyDir\$deviceid-package_old.txt
gc $CurrentyDir\$deviceid-package_old.txt |%{$_.split('=')[1]}|%{$_.split(' ')[0]} >> $CurrentyDir\$deviceid-package.txt
}

#monkey测试
$lines_pack = cat $CurrentyDir\$deviceid-package.txt
foreach ($line in $lines_pack){echo "$line monkey test";adb -s $deviceid shell monkey -p $line --throttle 200 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 30000;sleep 1}
sleep 5

 

#3删除中间文件
$FILE_PATH="$CurrentyDir\$deviceid-*.txt"
$TRUE_FALSE=(Test-Path $FILE_PATH)
if($TRUE_FALSE -eq "True")
{
remove-Item -Recurse -Force $FILE_PATH
}

#计算耗时
$end = Get-Date
Write-Host -ForegroundColor Red ($deviceid + ' monkeytest ' + 'Total Runtime: ' + ($end - $start).TotalSeconds)

标签:txt,monkey,package,FILE,apk,CurrentyDir,deviceid,测试,ps1
来源: https://www.cnblogs.com/cwxkurenoki/p/15127261.html