8th Chapter 5 "Monkeyrunner Source Analysis" Monkeyrunner start run process-run test script

Source: Internet
Author: User

Monkeyrunner after preparing services such as Androiddebugbridge and Devicemonitor, it basically solves the problem of communication with the target device, and what needs to be done is to run the test script.

178 public   static void Main (string[] args) {179     monkeyrunneroptions options = Monkeyrunneroptions.processoptions (args); 181     if (options = = null) {182       return;183     }184     185 186 Replacealllogformatters (Monkeyformatter.default_instance, Options.getloglevel ()); 187 188     MonkeyRunnerStarter Runner = new Monkeyrunnerstarter (options), 189     int error = Runner.run (); 191 192 system.exit     (error); 193   }194}
Code 8-5-1 monkeyrunnerstarter-main

From the above code and the above sections of this chapter analysis, Monkeyrunnerstarter in the process of instantiating Monkeyrunnerstarter started Androiddebugbridge and Devicemonitor, It then goes to the next line of 189 lines to call Monkeyrunnerstarter's Run method.

   the "monkeyrunnerpath" int Run () ()     . Com.android.monkeyrunner.bindir ") + File.separator +" Monkeyrunner ";     map<string, predicate<pythoninterpreter>> plugins = Handleplugins ();     This.options.getScriptFile () = = null) {       scriptrunner.console (monkeyrunnerpath);       This.chimp.shutdown ( );     "0",     "Scriptrunner.run", "int" error = "Monkeyrunnerpath", "This.options.getScriptFile" (). GetAbsolutePath (), this.options.getArguments (), plugins);     This.chimp.shutdown ();     return error; Bayi   }
Code 8-5-2 monkeyrunnerstarter-run

    • 68 line: Gets the absolute path of the Monkeyrunner script. "Com.android.monkeyrunner.bindir" We analyzed earlier, it represents the "/tools" in your SDK installation directory, followed by the file delimiter "/" and "Monkeyrunner" this script. So the end result is similar to "/users/apple/develop/sdk/tools/monkeyrunner."
    • 72-73 rows: If the user does not provide a script file path when running Monkeyrunner at the command line, then call the Scriptrunner class's console to request that the Jython parser open an interactive window to let the user interact
    • Line 74: When the user stops interacting close the window, call Chimpchat's Shutdown method to notify the corresponding module that the test has stopped so that they can handle it accordingly. For example, a "quit" command will be sent to the Monkey service to notify it that the test has stopped
    • 77 Rows: If the user provides a script path when running Monkeyrunner at the command line, then the call will be the Scriptrunner run method that runs the script, in fact the Jython parser is the final call to run the script.

Whether you open the interactive console or run the script directly, you end up using the Jython parser to do things like we go in Scriptrunner's Run method:

A   . public static int run (string executablepath, String scriptfilename, collection<string> args, map<string , predicate<pythoninterpreter>> plugins) ...   94     Pythoninterpreter python = new Pythoninterpreter (), ....     try115     {       python.execfile (scriptfilename); 117     } ...}
Code 8-3-3 scriptrunner-run

The thing to do is to instantiate a Jython parser, where the Pythoninterpreter package is "Org.python.util". After obtaining the Jython parser, the execfile method of the parser is called directly to execute the target test script.

Note: More articles please pay attention to the public number: Techgogogo or personal blog http://techgogogo.com. Of course, you are also very welcome to pick up directly (ZHUBAITIAN1). This article by Heaven Zhuhai Branch Rudder original. Reproduced please consciously, whether the complaint rights to look at the mood.


8th Chapter 5 "Monkeyrunner Source Analysis" Monkeyrunner start run process-run test script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.