一.主布局文件 activity_main.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/edit_monkeyPackage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeypackage"
android:maxLines="" >
</EditText> <EditText
android:id="@+id/edit_monkeytime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeytime"
android:maxLines="" >
</EditText> <EditText
android:id="@+id/edit_monkeycount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeycount"
android:maxLines="" >
</EditText>
<Button
android:id="@+id/button_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_submit" /> <TextView
android:id="@+id/TextView_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/TextView_01" /> </LinearLayout>

二. res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MonkeyTest</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="monkeypackage">Input monkeyPackage</string>
<string name="monkeytime">Input monkeyTime</string>
<string name="monkeycount">Input monkeyCount</string>
<string name="button_submit">Submit</string>
<string name="TextView_01">Log Out</string> </resources>

三.主Activity文件 MainActivity.java

package com.example.runmonkeytest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText; import android.widget.TextView;
import android.widget.Toast; @SuppressLint("NewApi")
public class MainActivity extends Activity { private EditText monkeyPackage;
private EditText monkeyTime;
private EditText monkeyCount;
private TextView LogOut; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); monkeyPackage = (EditText) findViewById(R.id.edit_monkeyPackage);
monkeyTime = (EditText) findViewById(R.id.edit_monkeytime);
monkeyCount = (EditText) findViewById(R.id.edit_monkeycount);
LogOut = (TextView) findViewById(R.id.TextView_01);
Button button1 =(Button) findViewById(R.id.button_submit); button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Toast.makeText(MonkeyTestActivity.this, "You clicked Button Submit", Toast.LENGTH_SHORT).show();
String monkeyPackageContext = monkeyPackage.getText().toString();
String monkeyTimeContext = monkeyTime.getText().toString();
String monkeyCountContext = monkeyCount.getText().toString(); if(monkeyPackageContext.isEmpty()){
Toast.makeText(MainActivity.this, "input packageName", Toast.LENGTH_SHORT).show();
}else if(monkeyTimeContext.isEmpty()){
Toast.makeText(MainActivity.this, "input pauseTime", Toast.LENGTH_SHORT).show();
}else if(monkeyCountContext.isEmpty()){
Toast.makeText(MainActivity.this, "input Count", Toast.LENGTH_SHORT).show();
}else{
int T = Integer.parseInt(monkeyTimeContext) ;
int C = Integer.parseInt(monkeyCountContext);
String acctionText = "monkey -p "+monkeyPackageContext+" --throttle "+
T + " -s 1000 " + " -v -v -v " + C;// + ">/sdcard/aaaaaa_monkey.log"; Log.d("MonkeyTestActivity", "Toast");
Log.d("MonkeyTestActivity", acctionText);
Toast.makeText(MainActivity.this, acctionText, Toast.LENGTH_SHORT).show(); do_exec(acctionText);
Log.d("MonkeyTestActivity", "Toast2");
} }
}
);
} protected String do_exec(String cmd) {
String s = "\n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
s += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LogOut.setText(s);
return cmd; } }

四.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.runmonkeytest"
android:versionCode=""
android:versionName="1.0" > <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-permission android:name="andorid.permission.WRITE_EXTERNAL_STORAGE"/> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.runmonkeytest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion=""
/> </manifest>

执行monkey APK 制作的更多相关文章

  1. 对当前目录下的所有APK包执行Monkey测试,并自动保存Crash日志

    适用平台:Android,代码几个月前写的,有问题请及时回复.本代码会依次安装当前目录下的APK安装包,之后执行Monkey测试,然后卸载掉换下一个,继续重复执行,如出现Cransh,会自动保存在当前 ...

  2. IOS操作系统上执行monkey测试

    IOS操作系统上执行monkey测试 IOS操作系统不像Android系统那么方便,各种限制也比较多,目前我的建议还是直接在模拟器上执行monkey测试.如果需要在真机上面执行,可以参考文档: htt ...

  3. dofile执行ANDROID APK里面的文件

    我使用dofile执行APK文件是不行的,比如 dofile("assets/res/flist")只能先拷贝到writablePath然后再dofile拿到数据后再清除这个临时文 ...

  4. Android 使用DexClassLoader要执行其他apk方法

    Android在apk文件dex文件是java编译出来.class次打包,当然在打包之前会利用自己的协议做一些数据处理,比如优化函数表和变量表.在java程序中是使用classloader来载入这些编 ...

  5. monkey测试跑多个apk|monkey命令

    1.如何跑多个apk的monkey? 黑名单:执行除了黑名单中以外的apk: 白名单:只执行在白名单中的apk. 黑名单的设置方法: a.创建一个名称为blacklist的txt文档,在文件中输入应用 ...

  6. 如何保存不连着电脑跑monkey?如何跑多个APK的monkey?

    哈喽,大家有没有遇到用真机跑monkey的时候,跑到一半结果小手一抖不小心把线碰掉了,结果报告就没获取到啦~ 今天就来解决这个问题 1.如何保存不连着电脑跑monkey? 1).输入命令进入shell ...

  7. Android插件化开发---执行未安装apk中的Service

    欢迎各位增加我的Android开发群[257053751​] 假设你还不知道什么叫插件化开发.那么你应该先读一读之前写的这篇博客:Android插件化开发,初入殿堂 上一篇博客主要从总体角度分析了一下 ...

  8. 老李推荐:第5章7节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles

    老李推荐:第5章7节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles   poptest是国内唯一一家培养测试开 ...

  9. Android APP压力测试(二)之Monkey信息自动收集脚本

      Android APP压力测试(二) 之Monkey信息自动收集脚本 前言: 上一篇Monkey介绍基本搬抄官方介绍,主要是为了自己查阅方便.本文重点介绍我在进行Monkey时如何自动收集相关信息 ...

随机推荐

  1. leetcode感想

    想想要参加秋招了,重新开始刷leetcode,记录一下自己在过程遇到的问题. 算法优化: 1.合并if分支. 2.将所有可以直接给出结果的特殊情况放在最前面直接返回.

  2. checkbox属性获取

    checked属性获取不能用attr,要用prop

  3. json转换字符串

    在使用json模块时需要先 import json 引入模块 json.dumps()模块函数 功能:将Python数据类型转换成字符串[有参] 使用方法:json.dumps(要转换的数据类型变量) ...

  4. js 浏览器判断

    获取浏览器类型 function getBrowser() { var userAgent = navigator.userAgent //取得浏览器的userAgent字符串 var isOpera ...

  5. Phoenix安装

    第一步: 安装erlang虚拟机: 第二步: 安装Elixir Add Erlang Solutions repo: wget https://packages.erlang-solutions.co ...

  6. 关于SASS

    SASS:(是一款辅助编写css的工具 安装之后可以通过同时按window键+“R”键 输入“powershell”进入CMD命令页面: 输入“sass -v”可以查看当前的sass版本 输入“cd ...

  7. 二、 编写一个类,用两个栈实现队列,支持队列的基本操作(add,poll,peek)

    请指教交流! package com.it.hxs.c01; import java.util.Stack; /* 编写一个类,用两个栈实现队列,支持队列的基本操作(add,poll,peek) */ ...

  8. 查看python内部模块命令,内置函数,查看python已经安装的模块命令

    查看python内部模块命令,内置函数,查看python已经安装的模块命令 可以用dir(modules) 或者用 pip list或者用 help('modules') 或者用 python -m  ...

  9. # -*- coding: utf-8 -*-

    -- coding: utf-8 -- import scrapy from jobscrawler_qianchengwuyou.items import JobscrawlerQianchengw ...

  10. Python with open as函数

    可以反复调用write()来写入文件,但是务必要调用f.close()来关闭文件. 当我们写文件时,操作系统往往不会立刻把数据写入磁盘,而是放到内存缓存起来,空闲的时候再慢慢写入. 只有调用close ...