{"id":1253,"date":"2023-03-18T09:45:02","date_gmt":"2023-03-18T01:45:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1253"},"modified":"2023-04-29T09:29:02","modified_gmt":"2023-04-29T01:29:02","slug":"usage-of-android-monkey","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/usage-of-android-monkey\/","title":{"rendered":"Android Monkey\u7684\u4f7f\u7528"},"content":{"rendered":"<h2>\u4ec0\u4e48\u662f Monkey<\/h2>\n<p>Monkey \u662f\u4e00\u4e2a Android \u81ea\u52a8\u5316\u6d4b\u8bd5\u5c0f\u5de5\u5177\u3002\u4e3b\u8981\u7528\u4e8eAndroid \u7684\u538b\u529b\u6d4b\u8bd5\uff0c\u4e3b\u8981\u76ee\u7684\u5c31\u662f\u4e3a\u4e86\u6d4b\u8bd5 App \u662f\u5426\u4f1aCrash\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>Monkey \u7279\u70b9<\/h2>\n<p>\u987e\u540d\u601d\u4e49\uff0cMonkey\u5c31\u662f\u7334\u5b50\uff0cMonkey\u6d4b\u8bd5\uff0c\u5c31\u50cf\u4e00\u53ea\u7334\u5b50\uff0c\u5728\u7535\u8111\u9762\u524d\uff0c\u4e71\u6572\u952e\u76d8\u5728\u6d4b\u8bd5\u3002\u7334\u5b50\u4ec0\u4e48\u90fd\u4e0d\u61c2\uff0c\u53ea\u77e5\u9053\u4e71\u6572\u3002\u901a\u8fc7Monkey\u7a0b\u5e8f\u6a21\u62df\u7528\u6237\u89e6\u6478\u5c4f\u5e55\u3001\u6ed1\u52a8Trackball\u3001\u6309\u952e\u7b49\u64cd\u4f5c\u6765\u5bf9\u8bbe\u5907\u4e0a\u7684\u7a0b\u5e8f\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5\uff0c\u68c0\u6d4b\u7a0b\u5e8f\u591a\u4e45\u7684\u65f6\u95f4\u4f1a\u53d1\u751f\u5f02\u5e38\u3002<\/p>\n<h2>Monkey\u7a0b\u5e8f\u4ecb\u7ecd<\/h2>\n<p>Monkey \u7a0b\u5e8f\u662f\u7531 Android \u7cfb\u7edf\u81ea\u5e26\uff0c\u4f7f\u7528 Java \u8bed\u8a00\u5199\u6210\u3002\u5728Android\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u5b58\u653e\u8def\u5f84\u662f\uff1a<code>\/system\/framework\/monkey.jar<\/code><\/p>\n<p>Monkey.jar\u7a0b\u5e8f\u662f\u7531\u4e00\u4e2a\u540d\u4e3a\u201cmonkey\u201d\u7684Shell\u811a\u672c\u6765\u542f\u52a8\u6267\u884c\uff0cshell\u811a\u672c\u5728Android\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u5b58\u653e\u8def\u5f84\u662f\uff1a<code>\/system\/bin\/monkey<\/code><\/p>\n<p>Monkey \u542f\u52a8\u65b9\u5f0f\uff1a\u5728 cmd \u547d\u4ee4\u63d0\u793a\u7b26\u91cc\u9762\u8f93\u5165\u547d\u4ee4\u884c\u6765\u542f\u52a8 monkey \u6d4b\u8bd5\u3002<\/p>\n<h2>Monkey \u67b6\u6784<\/h2>\n<p>Monkey \u8fd0\u884c\u5728\u8bbe\u5907\u6216\u6a21\u62df\u5668\u4e0a\u9762\uff0c\u53ef\u4ee5\u8131\u79bbPC\u8fd0\u884c\uff08\u666e\u904d\u505a\u6cd5\u662f\u5c06monkey\u4f5c\u4e3a\u4e00\u4e2a\u5411\u5f85\u6d4b\u5e94\u7528\u53d1\u9001\u968f\u673a\u6309\u952e\u6d88\u606f\u7684\u6d4b\u8bd5\u5de5\u5177\u3002\u9a8c\u8bc1\u5f85\u6d4b\u5e94\u7528\u5728\u8fd9\u4e9b\u968f\u673a\u6027\u7684\u8f93\u5165\u9762\u524d\u662f\u5426\u4f1a\u95ea\u9000\u6216\u8005\u5d29\u6e83\uff09<\/p>\n<h2>Monkey \u547d\u4ee4\u57fa\u672c\u53c2\u6570<\/h2>\n<p>\u5141\u8bb8\u542f\u52a8\u624b\u673a\u91cc\u9762\u6240\u6709\u7684 App\uff0c \u968f\u673a\u64cd\u4f5c 1000\u6b21<\/p>\n<pre><code>adb shell monkey 1000<\/code><\/pre>\n<h3>\u57fa\u7840\u53c2\u6570<\/h3>\n<h4>-p: \u5141\u8bb8\u542f\u52a8 App \u7684\u5305\u540d<\/h4>\n<p>\uff081\uff09\u542f\u52a8\u4e00\u4e2a\u5305\u540d\u7684\u5e94\u7528<\/p>\n<p>QQ \u7684\u5305\u540d\u4e3a\uff1a com.tencent.mobileqq<\/p>\n<pre><code>adb shell monkey -p com.tencent.mobileqq 1000<\/code><\/pre>\n<p>\u968f\u673a\u64cd\u4f5c \u624b\u673aQQ 1000 \u6b21<\/p>\n<p>\uff082\uff09\u542f\u52a8\u6307\u5b9a\u7684\u591a\u4e2a App<\/p>\n<p>\u5fae\u4fe1\u7684\u5305\u540d\u4e3a\uff1acom.tencent.mm<\/p>\n<pre><code>adb shell monkey -p com.tencent.mobileqq -p com.tencent.mm 1000<\/code><\/pre>\n<p>\u968f\u673a\u64cd\u4f5c \u624b\u673aQQ \u548c \u5fae\u4fe1 1000 \u6b21<\/p>\n<h4>-v: \u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55<\/h4>\n<p>\u547d\u4ee4\u884c\u7684\u6bcf\u4e00\u4e2a-v\u5c06\u589e\u52a0\u53cd\u9988\u4fe1\u606f\u7684\u7ea7\u522b<\/p>\n<ul>\n<li><code>-v<\/code>\uff1aLevel 0(\u7f3a\u7701\u503c)\u9664 \u542f\u52a8\u63d0\u793a\u3001\u6d4b\u8bd5\u5b8c\u6210\u548c\u6700\u7ec8\u7ed3\u679c\u4e4b\u5916\uff0c\u63d0\u4f9b\u8f83\u5c11\u4fe1\u606f<\/li>\n<li><code>-v -v<\/code>\uff1aLevel 1\u63d0\u4f9b\u8f83\u4e3a\u8be6\u7ec6\u7684\u6d4b\u8bd5\u4fe1\u606f\uff0c\u5982\u9010\u4e2a\u53d1\u9001\u5230Activity\u7684\u4e8b\u4ef6<\/li>\n<li><code>-v -v -v<\/code>\uff1aLevel 2\u63d0\u4f9b\u66f4\u52a0\u8be6\u7ec6\u7684\u8bbe\u7f6e\u4fe1\u606f\uff0c\u5982\u6d4b\u8bd5\u4e2d\u88ab\u9009\u4e2d\u7684\u6216\u672a\u88ab\u9009\u4e2d\u7684Activity<\/li>\n<\/ul>\n<pre><code>adb shell monkey -p com.tencent.mobileqq -v -v -v 100<\/code><\/pre>\n<h4>-s\uff1a\u4f2a\u968f\u673a\u6570\u751f\u6210\u5668\u7684seed\u503c<\/h4>\n<p>\u5982\u679c\u7528\u76f8\u540c\u7684seed\u503c\u518d\u6b21\u8fd0\u884cmonkey\uff0c\u5c06\u751f\u6210\u76f8\u540c\u7684\u4e8b\u4ef6\u5e8f\u5217\u3002<\/p>\n<pre><code>adb shell monkey -s 12345 -v 10<\/code><\/pre>\n<h4>&#8211;throttle\uff1a\u63d2\u5165\u56fa\u5b9a\u5ef6\u8fdf<\/h4>\n<p>\u5728\u4e8b\u4ef6\u4e4b\u95f4\u63d2\u5165\u56fa\u5b9a\u5ef6\u8fdf\u3002\u901a\u8fc7\u8fd9\u4e2a\u9009\u9879\u53ef\u4ee5\u51cf\u7f13Monkey\u7684\u6267\u884c\u901f\u5ea6\u3002\u5982\u679c\u4e0d\u6307\u5b9a\u8be5\u9009\u9879\uff0cMonkey\u5c06\u4e0d\u4f1a\u88ab\u5ef6\u8fdf\uff0c\u4e8b\u4ef6\u5c06\u5c3d\u53ef\u80fd\u5feb\u5730\u88ab\u6267\u884c\u3002<\/p>\n<pre><code>adb shell monkey --throttle 500 -v 500<\/code><\/pre>\n<p>\u968f\u673a\u6267\u884c 500 \u4e2a\u4e8b\u4ef6\uff0c\u6bcf\u4e2a\u4e8b\u4ef6\u4e4b\u95f4\u5ef6\u8fdf 500 \u6beb\u79d2\u88ab\u6267\u884c\u3002<\/p>\n<h4>&#8211;help: \u5217\u51fa\u7b80\u5355\u7684\u7528\u6cd5<\/h4>\n<pre><code>adb shell monkey -help<\/code><\/pre>\n<h3>\u4e8b\u4ef6\u53d1\u9001\u7c7b\u578b<\/h3>\n<h4>&#8211;pct-touch<\/h4>\n<h4>&#8211;pct-motion<\/h4>\n<h4>&#8211;pct-trackball<\/h4>\n<h4>&#8211;pct-nav<\/h4>\n<h4>&#8211;pct-syskeys<\/h4>\n<h4>&#8211;pct-anyevent<\/h4>\n<h3>\u8c03\u8bd5\u9009\u9879<\/h3>\n<h4>&#8211;hprof<\/h4>\n<h4>&#8211;ignore-crashes<\/h4>\n<p>\u901a\u5e38\uff0c\u5e94\u7528\u53d1\u751f\u5d29\u6e83\u6216\u5f02\u5e38\u65f6Monkey\u4f1a\u505c\u6b62\u8fd0\u884c\u3002\u5982\u679c\u8bbe\u7f6e\u6b64\u9879\uff0cMonkey\u5c06\u7ee7\u7eed\u53d1\u9001\u4e8b\u4ef6\u7ed9\u7cfb\u7edf\uff0c\u76f4\u5230\u4e8b\u4ef6\u8ba1\u6570\u5b8c\u6210\u3002<\/p>\n<pre><code>adb shell monkey --ignore-crashes -v 1000<\/code><\/pre>\n<h4>&#8211;ignore-timeouts<\/h4>\n<p>\u901a\u5e38\uff0c\u5e94\u7528\u7a0b\u5e8f\u53d1\u751f\u4efb\u4f55\u8d85\u65f6\u9519\u8bef\uff08\u5982\u201cApplication Not responding\u201d\u5bf9\u8bdd\u6846\uff09Monkey\u5c06\u505c\u6b62\u8fd0\u884c\uff0c\u8bbe\u7f6e\u6b64\u9879\uff0cMonkey\u5c06\u7ee7\u7eed\u53d1\u9001\u4e8b\u4ef6\u7ed9\u7cfb\u7edf\uff0c\u76f4\u5230\u4e8b\u4ef6\u8ba1\u6570\u5b8c\u6210\u3002<\/p>\n<pre><code>adb shell monkey --ignore-timeouts -v 1000<\/code><\/pre>\n<h4>&#8211;ignore-security-exceptions<\/h4>\n<p>\u901a\u5e38\uff0c\u5f53\u7a0b\u5e8f\u53d1\u751f\u8bb8\u53ef\u9519\u8bef\uff08\u4f8b\u5982\u542f\u52a8\u4e00\u4e9b\u9700\u8981\u8bb8\u53ef\u7684Activity\uff09\u5bfc\u81f4\u7684\u5f02\u5e38\u65f6\uff0cMonkey\u5c06\u505c\u6b62\u8fd0\u884c\u3002\u8bbe\u7f6e\u6b64\u9879\uff0cMonkey\u5c06\u7ee7\u7eed\u53d1\u9001\u4e8b\u4ef6\u7ed9\u7cfb\u7edf\uff0c\u76f4\u5230\u4e8b\u4ef6\u8ba1\u6570\u5b8c\u6210\u3002<\/p>\n<pre><code>adb shell monkey --ignore-security-exceptions -v 1000<\/code><\/pre>\n<h4>&#8211;kill-process-after-error<\/h4>\n<h4>&#8211;monitor-native-crashes<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f Monkey Monkey \u662f\u4e00\u4e2a Android \u81ea\u52a8\u5316\u6d4b\u8bd5\u5c0f\u5de5\u5177\u3002\u4e3b\u8981\u7528\u4e8eAndroid \u7684\u538b\u529b\u6d4b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[222],"tags":[314],"class_list":["post-1253","post","type-post","status-publish","format-standard","hentry","category-android-test","tag-monkey"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1253"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}