android monkeyrunner 2

Running monkeyrunner
运行monkeyrunner


You can either run monkeyrunner programs from a file, or enter monkeyrunner statements in an interactive session. You do both by invoking the monkeyrunner command which is found in the tools/ subdirectory of your SDK directory. If you provide a filename as an argument, the monkeyrunner command runs the file's contents as a Python program; otherwise, it starts an interactive session.
您可以直接使用一个代码文件运行monkeyrunner,抑或在交互式对话中输入monkeyrunner语句。不论使用哪种方式,您都需要调用SDK目录的tools子目录下的monkeyrunner命令。如果您提供一个文件名作为运行参数,则monkeyrunner将视文件内容为Python程序,并加以运行;否则,它将提供一个交互对话环境。

The syntax of the monkeyrunner command is
monkeyrunner命令的语法为:


monkeyrunner -plugin <plugin_jar> <program_filename> <program_options>
monkeyrunner -plugin  <程序文件名> <程序选项>

Table 1 explains the flags and arguments.
表 1阐释了命令的标志和参数。

Table 1. monkeyrunner flags and arguments.
表1.monkeyrunner标志和参数。
    

Argument               Description
-plugin <plugin_jar>  (Optional) Specifies a .jar file containing a plugin for monkeyrunner. To learn more about monkeyrunner plugins, see Extending monkeyrunner with plugins. To specify more than one file, include the argument multiple times.
<program_filename> If you provide this argument, the monkeyrunner command runs the contents of the file as a Python program. If the argument is not provided, the command starts an interactive session.
<program_options> (Optional) Flags and arguments for the program in <program_file>.                                                                                           
           

参数                   说明
----------------------------------------------------------------------------------------------
-plugin              (可选)指定一个内含monkeyrunner插件的.jar文件。
                         欲了解更多关于monkeyrunner插件的内容,请参照使
                         用插件扩展monkeyrunner。  要指定多个文件,包括
                         多次论证。如欲指定超过一个文件,可以多次使用此参数。
----------------------------------------------------------------------------------------------     <程序文件名>     如果您指定此参数,monkeyrunner将视文件内容为Python
                         程序并予以执行。如果此参数未予指定,则开启一个交互式会话。
----------------------------------------------------------------------------------------------
<程序选项>      (可选)<程序文件名>           
                        所指定的程序所需的参数
----------------------------------------------------------------------------------------------
monkeyrunner Built-in Help      
monkeyrunner内建帮助

You can generate an API reference for monkeyrunner by running:
您可以用以下命令来生成monkeyrunner的API参考:

monkeyrunner <format> help.py <outfile>
monkeyrunner  help.py

The arguments are:
参数说明:

    * <format> is either text for plain text output or html for HTML output.
    * 可以为text或html,分别代表纯文本和HTML输出。
    * <outfile> is a path-qualified name for the output file.
    *  指定了输出文件的全路经名称。



Extending monkeyrunner with Plugins
使用插件扩展monkeyrunner


You can extend the monkeyrunner API with classes you write in the Java programming language and build into one or more .jar files. You can use this feature to extend the monkeyrunner API with your own classes or to extend the existing classes. You can also use this feature to initialize the monkeyrunner environment.
您可以用Java语言创建新的类,并打包成一个或多个.jar文件,以此来扩展monkeyrunnerAPI。您可以使用您自己写的类或者继承现有的类来扩展monkeyrunnerAPI。您还可以使用此功能来初始化monkeyrunner环境。

To provide a plugin to monkeyrunner, invoke the monkeyrunner command with the -plugin <plugin_jar> argument described in table 1.
为了使monkeyrunner加载一个插件,您应当如使用如表1中所述的-plugin参数来调用monkeyrunner命令。

In your plugin code, you can import and extend the the main monkeyrunner classes MonkeyDevice, MonkeyImage, and MonkeyRunner in com.android.monkeyrunner (see The monkeyrunner API).
在您编写的插件中,您可以导入或继承位于com.android.monkeyrunner包中的几个主要的monkeyrunner类:MonkeyDevice, MonkeyImage和MonkeyRunner(参见monkeyrunnerAPI )。


Note that plugins do not give you access to the Android SDK. You can't import packages such as com.android.app. This is because monkeyrunner interacts with the device or emulator below the level of the framework APIs.
请注意,插件无法让你访问Android的SDK。您不能导入com.android.app等包。这是因为monkeyrunner是在框架API层次之下与设备或模拟器进行交互的。


The plugin startup class
插件启动类


The .jar file for a plugin can specify a class that is instantiated before script processing starts. To specify this class, add the key MonkeyRunnerStartupRunner to the .jar file's manifest. The value should be the name of the class to run at startup. The following snippet shows how you would do this within an ant build script:
用于插件的.jar文件可以指定一个类,使其在脚本执行之前就实例化。如欲指定这个类,您需要在.jar文件的manifest中添加键MonkeyRunnerStartupRunner。其值为启动时运行的类的名称。以下代码段显示了如何在一个ant构建脚本达到这样的目的:

<jar jarfile="myplugin" basedir="${build.dir}">
<manifest>
<attribute name="MonkeyRunnerStartupRunner" value="com.myapp.myplugin"/>
</manifest>
</jar>

   
To get access to monkeyrunner's runtime environment, the startup class can implement com.google.common.base.Predicate<PythonInterpreter>. For example, this class sets up some variables in the default namespace:
如欲访问monkeyrunner的运行时环境,启动类可以实现com.google.common.base.Predicate。例如,用这个类在默认的命名空间中设置一些变量:

package com.android.example;
 
 import com.google.common.base.Predicate;
 import org.python.util.PythonInterpreter;
 
 public class Main implements Predicate {
     @Override
     public boolean apply(PythonInterpreter anInterpreter) {
 
         /*
         * Examples of creating and initializing variables in the monkeyrunner environment's
         * namespace. During execution, the monkeyrunner program can refer to the variables "newtest"
         * and "use_emulator"
         *
         */
         anInterpreter.set("newtest", "enabled");
         anInterpreter.set("use_emulator", 1);
 
         return true;
     }
 }

你可能感兴趣的:(android,python,ant,Google,脚本)