monkey测试脚本.ps1
#aapt.exe adb.exe 设置为环境变量 #将脚本和apk包放在同一个文件夹 #.\monkeytest.ps1 -deviceid 串号 是monkey测试当前文件夹下所有apk #.\monkeytest.ps1 -deviceid 串号 -apk_list ("androbench-5.0.1.apk", "HD Video Player.apk") 是monkey测试当前文件夹下指定的apk #.\monkeytest.ps1 -deviceid 串号 -optNum 1 是monkey测试循环1次 Param( [string[]]$apk_list = $null, [string]$deviceid = "0123456789ABCDEF", [string]$apkdiristrue = "0", [string]$optNum = "1000000", [Int64]$allseconds = 50000 ) $scriptName = "monkeytest" $tempFile = "$scriptName-$deviceid" $PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition $CurrentyDir = $PSScriptRoot $apkdir1 = (Get-ChildItem $CurrentyDir| ?{$_.psiscontainer -eq $true}) $apkdir = "$CurrentyDir\$apkdir1" echo "Currentdir: "$CurrentyDir echo "" function deleteTmpFile { $FILE_PATH="$CurrentyDir\$tempFile-*.txt" $TRUE_FALSE=(Test-Path $FILE_PATH) if($TRUE_FALSE -eq "True") { remove-Item -Recurse -Force $FILE_PATH } } #获取包名 function getPackName([Object[]]$pathApk) { foreach($i in $pathApk){aapt d badging $LOCALAPKDir\$i|Select-String '^package: name'| out-string -width 4096 >> $CurrentyDir\$tempFile-package1.txt} gc $CurrentyDir\$tempFile-package1.txt|?{-not [String]::IsNullOrWhiteSpace($_)} | set-content $CurrentyDir\$tempFile-package_old.txt gc $CurrentyDir\$tempFile-package_old.txt |%{$_.split('=')[1]}|%{$_.split(' ')[0]} >> $CurrentyDir\$tempFile-package.txt } #testflow $start = Get-Date $startforM = Get-Date #删除中间文件 deleteTmpFile if( $apk_list -eq $null ){ if( $apkdiristrue -eq 0){ $pathApk = dir $CurrentyDir\*.apk -name $LOCALAPKDir = $CurrentyDir getPackName $pathApk }else { $pathApk = dir $apkdir\*.apk -name $LOCALAPKDir = $apkdir getPackName $pathApk } }else{ $pathApk = $apk_list getPackName $pathApk } function Invoke-TimeOutCommand-monkey() { $doit = "adb -s $deviceid shell monkey -p $line --throttle 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 300" $job = Start-Job -ScriptBlock { param($num) $numBlock = [Scriptblock]::Create($num) $numBlock.Invoke() } -ArgumentList $doit| Wait-Job -Timeout 50 if($job.State -ne 'Completed') { Write-Warning 'timeout' adb -s $deviceid shell pm clear $line adb -s $deviceid shell am force-stop $line $job | Stop-Job | Remove-Job return $null } else { return $job | Receive-Job } } for($i=1;$i -le $optNum;$i++) { $lines_pack = cat $CurrentyDir\$tempFile-package.txt foreach ($line in $lines_pack){ echo "$deviceid $line monkey test" Invoke-TimeOutCommand-monkey sleep 2 } $endforM = Get-Date $timespend = ($endforM - $startforM).TotalSeconds echo "now timespend is : $timespend----------------------------------------------------------------------" if( $timespend -gt $allseconds ){ echo "time END--------------------------------------------------" break } sleep 3 } #删除中间文件 deleteTmpFile #计算耗时 $end = Get-Date Write-Host -ForegroundColor Red ($deviceid + ' monkeytest ' + 'Total Runtime: ' + ($end - $start).TotalSeconds)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】