Tuesday, 7 August 2012

Datadriven Script (MonkeyTalk)


This basically requires three files all placed in the root folder of your MonkeyTalk Project.

1.  MonkeyTalk code script. This is the one where you all the automation code.
2.  A driver script. This script is the one which we will run to execute the test. This script just calls the main MonkeyTalk code script and passes a csv (comma separated value) file with it. Think of this script as a main method in a java class file which is invoked first and others are invoked as the thread of main method progresses
3. CSV file. This file contains all the arguments that you want to pass for each variable in the driven script. The order of the

Main MonkeyTalk code script (or the driven script) in MonkeyTalk form:-

Vars * Define user pass
Input username Tap
Input username EnterText ${user}
Input password EnterText ${pass}
Button LOGIN Verify LOGIN %thinktime=1000
Button LOGIN Tap
Label * Verify "Welcome, ${user}!" %thinktime=3000
Button LOGOUT VerifyNot LOGIN
Button LOGOUT Tap %thinktime=5000

Driver Script in MonkeyTalk form:-

Script <name_of_driven_script>.mt RunWith <name_of_csv_file>.csv

CSV file:-

user pass
username1, password1
username2, password2
username3, password3

Notice that the first line (row) in the CSV file is the variable name and the contents of second row are the values in the variable.

Iterations: The number of rows in the csv file is the number of times the script is iterated. So in this case the script is run 3 times. In the first iteration the csv file passes the value username1 to the user variable and password1 to pass variable and so on.

Variable initiation: It does not matter whether the declared variable in the driven script is initialized or not. Even if the declared variable is initialized with some value that value will be wiped of that variable during the first iteration and the new value as mentioned in the script will be assigned to the variable. This is based on the assumption that the declared variable is mentioned in the script.

Do I need mention all the variables in the csv file even if I don’t want to change their value in each iteration? No. Mention only that variable that you want to iterate in each iteration.

Leaving a blank value for a var in csv: Leaving a value blank for a variable in csv file leaves the variable empty (technically, null). Even if it is the second iteration the variable does not contain the value provided to it in the first iteration. This means that the var is wiped off even when there are not values to be assigned to it the second iteration.

Note: Just make sure that you hit the play or run button when you are using browsing the driver script and not the driven script.


Javascript form of the Monkey Script:-

load("libs/<monkey_project_name>.js");
<monkey_project_name>.<driven_script_name>.prototype.run = function(user, pass) {
                this.app.input("username").tap();
                this.app.input("username").enterText(user);
                this.app.input("password").enterText(pass);
                this.app.button("LOGIN").verify("LOGIN", {thinktime:"1000"});
                this.app.button("LOGIN").tap();
                this.app.label().verify("Welcome, " + user + "!", {thinktime:"3000"});
                this.app.button("LOGOUT").verifyNot("LOGIN");
                this.app.button("LOGOUT").tap({thinktime:"5000"});
};

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete