Passing variable values through driver script (MonkeyTalk)
Value for variables can be passed as arguments in a driver
script. The only requirement is that they should be provided in the same order
as they are declared. We have two scripts here one is the main code (driven)
script and the driver script.
MonkeyTalk form:-
Driven script
Vars * Define pass user
Input username EnterText ${user}
Input password EnterText ${pass}
Button LOGIN Tap %thinktime=500
Button LOGOUT Tap %thinktime=3000
Driver Script
Script <driven_script_name>.mt Run username1
"password1"
Script <driven_script_name>.mt Run username2
"password2" %thinktime=3000
Test message
Javascript
form:
Driven script
load("libs/<monkey_talk_project_name>.js");
<monkey_talk_project_name>.<driven_script_name>.prototype.run
= function(pass, user) {
this.app.input("username").enterText(user);
this.app.input("password").enterText(pass);
this.app.button("LOGIN").${empty}({thinktime:"500"});
this.app.button("LOGOUT").${empty}({thinktime:"3000"});
};
Driver script
load("libs/<monkey_talk_project_name>.js");
<monkey_talk_project_name>.<driver_script_name>.prototype.run
= function() {
this.app.<dri>().run("john1",
"password1");
this.app.gj1().run("john2",
"password2", {thinktime:"3000"});
};
Think Time at the end of second line of the driver
script is important because when a script is executed the second time
the first script needs some time to process the logout operation before
starting the second script. Likewise, we can also provide a think time to the
first script if it were to be followed by a test setup method/script while
requires some processing.
Order of variables: It can be observed that in
the driven script the password variable is declared first followed by the
username variable. So all the values passed in as the first argument in the
driver script are assigned to the pass variable. Although one might want to
believe that since user variable is used first in the script the first value
passed as argument would be the assigned to user, that is NOT correct.
Variables values that contain spaces can also
be passed using the driven script. To prevent the space within the variable
value from being interpreted as a separator between two arguments, one has to
pass the argument within double quotes. For example: one can pass a password as
“this is my password”
Related Links:-
Related Links:-
- Eclipse configuration with Android SDK (Click here..)
- MonkeyTalk: Installation of Agent (Click here..)
- Writing script in MonkeyTalk (Click here..)
- Simple Login Script (Click here..)
- Datadriven Script (Click here..)
- Conditional statements ( Click Here )
- Steps to install Android Apps to SD Card (Click here..)
- Steps to install Android App in Emulator ( Click Here )
No comments:
Post a Comment