Monkytalk Learning -4-js Script modification Run

Source: Internet
Author: User

JS script to modify and run aspects of the content,

1. Export Scripts

After the recording is completed or edited through the table view interface, JavaScript scripts are automatically generated and entered into the JavaScript tab to see the following results

Clicking the Export button will automatically generate a. js file with the same content as you see in JavaScript.

2. What to Do

If you want to include common programming structures like flow control, loops, and random number generators, then Exportin G to Javascript is a good a-do.

This is the official interpretation of the role of the editing script, in short, in JS can do loop, random number of operations. Here's an example of a loop.

Load ("Libs/newdemo.js"); NewDemo.Login.prototype.run=function(username, _password) {/** * @type MT. Application*/    varApp = This. App; Username= (username! = Undefined && Username! = "*"? Username: "<username>"); Password= (Password! = undefined && Password! = "*"? Password: "<password>"); App.input ("Username"). Entertext (username); App.input ("Password"). Tap (); App.input ("Password"). Entertext (password); App.button ("LOGIN"). Tap (); App.device (). WaitFor ("10"); App.button ("LOGOUT"). Tap (); };

Probably mean, before the operation, read the parameter value from the CSV file, call the login.mt to log in and exit, now to do is, from JS on the implementation of cyclic n operations.

3. Editing scripts

The exported JS script can be edited, plus a looping statement. Because I have not written a JS script, picked the simplest to write

Load ("Libs/newdemo.js"); NewDemo.Login.prototype.run=function(username, password) {/** * @type MT. Application*/    varApp = This. App;  for(vari = 0; I < 5; i + +) {username= (username! = Undefined && Username! = "*"? Username: "<username>"); Password= (Password! = undefined && Password! = "*"? Password: "<password>"); App.input ("Username"). Entertext (username); App.input ("Password"). Tap (); App.input ("Password"). Entertext (password); App.button ("LOGIN"). Tap (); App.device (). WaitFor ("10"); App.button ("LOGOUT"). Tap (); }};

4. Run the script

How do I run a script? Back to our run.mt,

Modify the login.mt in Monkeyid in the diagram to Login or login.js

Connecting the IDE and simulator, the emulator Launcher app is required

Then run the run.mt on it.

After testing, it is possible, indeed, after getting a set of parameters from the CSV, run 5 times, and then get another set of parameters from the CSV, and then run five times, know that the three sets of parameters are completed.

5. Use of random numbers.

Note: The following code is seen from the official website. If you try it yourself, you can actually generate a random number.

if(typeofTest = = "undefined") {Load ("Libs/newdemo.js");}; NewDemo.Test1.prototype.run=function(usr, pwd) {usr= USR | |Randstr (); PWD= PWD | |Randstr ();  This. App.input ("username"). Entertext (USR);  This. App.input ("Password"). Entertext (PWD);  This. App.button ("LOGIN"). Tap ();  This. App.button ("LOGOUT"). Tap ();};functionRandstr () {varText = ""; varpossible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  for(vari=0; I < 5; i++) Text+ = Possible.charat (Math.floor (Math.random () *possible.length)); returntext;}

Monkytalk Learning -4-js Script modification Run

Related Article

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.