Posts Tagged ‘MonkeyTalk’

MonkeyTalk all Actions/methods  with their Description and Examples:

MonkeyTalk Action Description Example for android
Device Rotate This method is used for Change the device orientation.
Android:Landscape,Portrait
Ios:Left,Right
Device *  Rotate Landscape
Back iOS: Pops the current UINavigationItem (if there is one)
Android: Presses the hardware device key
Device *  back
forward iOS: Pushes the next UINavigationItem, if there is one
Android: ignored.
N/A on Android.
search iOS: ignored.
Android: Presses the device search key.
Device *  Search
Screenshot This method is used to create screenshot folder in running project and we can capture screenshot at any point Device *  Screenshot
Menu Android: Presses the device menu key.
iOS: ignored
Device * Menu
Shake This method is used for specific apps.  Device * Shake
Get This method returns “iOS” or “Android”. Device * Get a
Table Select This method is used to select an element from the table. Table * Select Boron
SelectRow Select a row.
row – the row to select
section – the section containing the row. (Ignored on Android).
Where row and section are arguments.
ScrollToRow(by row) Scroll to a row by row number.
Row – the row to select
section – the section containing the row. (Ignored on Android).
Where row and section are arguments and both args should be integer.
ScrollToRow(by Value) Scroll to a row by value.
value (int)- the value of the row to scroll to.
SetEditing Enable/disable table editing. iOS: Enabled editing mode for table. Android: ignored. N/A on Android.
Insert Insert a row into the table. iOS: Inserts a row. Android: Ignored. N/A on Android.
Remove Remove a row from the table.  iOS: Deletes the row. Android: Ignored. N/A on Android.
Move Move a row. iOS: Moves a row. Android: Ignored N/A on Android.
SelectIndex Selects an item by index. Table * SelectIndex 3
Where 3 is item no i.e index and index should be integer.
LongSelectIndex Long press an item by index. Table * LongSelectIndex 4
Where 4 is item no i.e index and index should be integer.
View verify Verifies that a property of the component has some expected value.If  Expected value is null then it  verifies the existence of the component. Syntax: ComponentType MonkeyId  Verify arg
where for argument pass expected value for verification and componenttype can be any component of monkeytalk like label,button,tabbar etc.
Example: Label #1 Verify “Welcome, test!” %thinktime=8000
Label LOGOUT Verify LOGOUT %thinktime=3000
or
View  LOGOUT Verify LOGOUT %thinktime=3000
verifyNot Verifies that a property of the component does not have some value.If  Expected value is null then it  verifies the non-existence of the component. ComponentType MonkeyId  VerifyNot arg
Label LOGOUT VerifyNot Login %thinktime=3000
or
View LOGOUT VerifyNot Login %thinktime=3000
verifyRegex Verifies that a property of the component matches some regular expression.
verifyNotRegex Verifies that a property of the component does not have a value matching a regular expression
verifyWildcard  Verifies that a property of the component does have a value matching some wildcard expression
verifyNotWildcard  Verifies that a property of the component does not have a value matching some wildcard expression
Get Retrieves a property value from the component Syntax: ComponentType MonkeyId Get Variable PropPath
Example: Button LOGIN Get b :text
Label #1 Get a
Tap Taps on the component. On Android, plays a “click”. On iOS, plays a TouchDown/TouchMove/TouchUp sequence. Button LOGOUT Tap
Swipe Swipe(scroll)  the component in direction Left, Right, Up, or Down (case insensitive) WebView webview swipe Down
Table * Swipe Up
Slider * Swipe Right
Drag Touch down, drag across the component, then up Input username Drag 43 154 181 162
where 43 and 154 are x1,y1 i.e starting cordinates and 181 & 162 are x2,y2  i.e ending cordinates.
TouchDown Start touching the component. Input username TouchDown 43 154
where 43 and 154 are x and y cordinates of touch and x,y should be integer.
TouchMove Drag across the component.
one or more (x,y) coordinate pairs specifying the path of the drag gesture
Input username TouchMove 146 170
TouchUp Stop touching the component Input username TouchUp 43 154
where 43 and 154 are x and y cordinates of touch where touch is released and x,y should be integer.
Pinch Pinch the component.
scale – The scale factor relative to the points of the two touches in screen coordinates
velocity – The velocity of the pinch in scale factor per second (read-only)
Exec Call a method on a component. The method must take zero or more String arguments and return a String result. Not implemented yet by gorilla logics.
LongPress Performs a long press on the component. On Android, plays a “longClick”. On iOS, plays a longPush gesture View LOGOUT  LongPress
Button LOGIN  LongPress
ButtonSelector Select Select an item by value. ButtonSelector forms_radios select A
SelectIndex Selects an item by index.
LongSelectIndex Long press an item by index.
Input EnterText Enter text into the input field.
text – the text to enter
hitDone – iOS: if true, hit Done key after entering text. Android: ignored.
Where text and hitdone are arguments of entertext action.
Input username EnterText test
Clear Clear text from the input field Input username Clear
Script Run Run the script with the given args. Script test1.mt Run john “my password” %thinktime=3000
RunWith Run the script with the given CSV file. Script datdriven.mt RunWith credentials.csv
Slider Select Select a numeric component value Slider forms_slider_bar Select 52 %thinktime=3000
TabBar Select Select an item by value. TabBar * Select hierarchy %thinktime=1000
SelectIndex Selects an item by index. TabBar * SelectIndex 2 %thinktime=5000
LongSelectIndex Long press an item by index.
Vars Define Define the named variables used in the script. Vars * Define user pass
CheckBox On This action sets or returns the checked state of a checkbox. CheckBox forms_checkbox on
Off This action sets or returns the Unchecked state of a checkbox. CheckBox forms_checkbox off
ItemSelector Select Select an item by value. ItemSelector * Select Carbon
SelectIndex Selects an item by index. ItemSelector * SelectIndex 8
LongSelectIndex Long press an item by index. ItemSelector * LongSelectIndex 8
Button Tap Taps(click) on the Button. On Android, plays a “click”. On iOS, plays a TouchDown/TouchMove/TouchUp sequence. Button LOGOUT Tap
DatePicker EnteDate Change the current date value.
A date with the format YYYY-MM-DD where YYYY is the year, MM is the month (01-12), and DD is the day (01-31).
NumericSelector select Select a numeric component value
RatingBar select Select a numeric component value
Scroller scroll Scroll to the specified coordinates.
x – the x-coordinate (horizontal)
y – the y-coordinate (vertical)
TextArea EnterText Enter text into the input field.
text – the text to enter
hitDone – iOS: if true, hit Done key after entering text. Android: ignored.
Where text and hitdone are arguments of entertext action.
TextArea * enterText “This is a textarea”
Clear Clear text from the input field TextArea * Clear
ToolBar SelectIndex Selects an item by index.
LongSelectIndex Long press an item by index.
VideoPlayer Play Play the video from the current playback point.
Pause Stop the video at the current playback point
Stop Stop the video and set playback to the starting point.
Menu Select Select an item by value. Menu * select About
Verify Menu * Verify About
SelectIndex Selects an item by index.
LongSelectIndex Long press an item by index.
Doc vars Document the named variables used in the script.
script Document the script itself.
Label All methods of view are applicable on label. Label #1 Verify “Welcome, test!”
Label LOGOUT VerifyNot LOGIN
Setup Run Run the setup script with the given args. SetUp login.mt run john “my password”
RunWith Data-drive the setup script with the given CSV data file. SetUp login.mt runwith cre.csv
(where the first arg is the data file filename )
Teardown Run Run the teardown script with the given args TearDown logout.mt run
RunWith Data-drive the teardown script with the given CSV data file. TearDown logout.mt runwith logout.csv
Test Run Run the test script with the given args. Test testcase1.mt run
RunWith Data-drive the test script with the given CSV data file. Test testcase1.mt runwith login.csv
Toggle On Enabled the switch on. Toggle MonkeyId On
Off Disabled the switch. Toggle MonkeyId Off

MonkeyTalk Test Suite:

MonkeyTalk Test Suite is a file with extension .mts in which you can manage the number of scripts. You can use SetUp, TearDown and Test commands in test suites. A test suite can only contain three types of commands.

Test is a script which runs as part of test suite.

Setup-A script to run before each test in the script.

TearDown – A script to run after each test in the script.

Steps to create Test Suite:

  • Right click on Project.
  • Select new.
  • Then Select Test Suite.

Scripts which you want to run through testsuite should have extension .mt.

Test Suite Must contains at least one Script.

Advantage:

We can Run no of scripts in one go and Screenshots are captured and stored in screenshot folder under project in report folder for failures automatically.

Test suites output the standard XML report, making MonkeyTalk easy to integrate into existing systems.

Results:

The results are displayed in the JUnit panel at the bottom of the screen.

You can also view Results from Test Xml file under project in report folder.

List of MonkeyTalk Component Types:

MonkeyTalk Android IOS
Device Device Device
Table ListView UITableView
View View View
ButtonSelector RadioGroup UISegmentedControl
Input EditText UITextField
Script
Slider SeekBar UISlider
TabBar TabHost UITabBar
Vars
CheckBox CheckBox UISwitch
ItemSelector Spinner UIPicker
Button Button UIButton
DatePicker DatePicker UIDatePicker
NumericSelector
RatingBar Slider RatingBar
Scroller Scroller UIScrollView
TextArea TextView UITextView
ToolBar ActionBar UIToolBar
VideoPlayer VideoView MPMoviePlayerController
Menu Menu TabBar
Doc
Label TextView UILabel
Setup
Teardown
Test
Toggle ToggleButton UISwitch

Data Driven Script:

In MonkeyTalk you can use/create the Data Driven Script by using RunWith action and three files are required for Data Driven Script.

1. Main file– Its extension is .mt.In this main script is written.

datadriven.mt

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

you can view tabular form of Tabular form datadriven.mt script:

 

2. Driver script: Its extension is .mt. This script is use to run the main file.

Script datdriven.mt RunWith credentials.csv

you can view tabular form of Tabular form Driver script:

3. CSV File:Its extension is .csv.

You can create csv file in your MonkeyTalk project by following below mentioned steps :

Right click on project folder

new >>other >>Click on General >>choose file >> give a name with extension .csv

Now  in this file give values for variables which you are defined in main file/script. In first row of this file mention variables name separated by space which you have define in main file.

user pass
joew,sword1
jyoti,password1
charlie,test

you can view tabular form of Tabular form csv file:

MonkeyTalk Parameterized script:

Passing variable values through driver script. 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.

In MonkeyTalk form:

# Driven script (test1.mt)

Vars * Define paswords user

Input username EnterText ${user}

Input password EnterText ${pass}

Button LOGIN Tap %thinktime=500

Button LOGOUT Tap %thinktime=3000

You can view the tabular form of driven (test1.mt) script which i have created:

# Driver Script

Script test1.mt Run john “mypassword”

Script test1.mt Run john1 “mypassword1” %thinktime=3000

Driver script in tabular form:

Parametrized script by using default  values:

# default.mt

Vars * Define username=Jyoti  password=test

Input username EnterText ${username}

Input password EnterText ${password}

Button LOGIN Tap %thinktime=3000

Label * Verify “Welcome, ${username}!” %thinktime=3000

 Result:

17:03:44.664: Started Script Playback

17:03:44.673: Vars * Define username=Jyoti pw=test

17:03:44.681: Input username EnterText jyoti

17:03:45.340: Input password EnterText test

17:03:46.004: Button LOGIN Tap %thinktime=3000

17:03:49.180: Label * Verify “Welcome, fred!” %thinktime=3000

17:03:53.327: Completed Script Playback – OK

when we send the parameters through driver script

Script default.mt Run pooja

In this case username argument will take pooja and password argument takes default value i.e. test

 Result:

17:09:05.839: Started Script Playback

17:09:05.843: Script default.mt Run pooja

17:09:05.848: Started Script Playback

17:09:05.851: Vars * Define usr=jyoti pw=test

17:09:05.855: Input username EnterText pooja

17:09:06.614: Input password EnterText test

17:09:07.088: Button LOGOUT tap %thinktime=3000

17:09:07.297: Button LOGIN Tap %thinktime=3000

17:09:10.543: Label * Verify “Welcome, pooja!” %thinktime=3000

17:09:11.158: Completed Script Playback – OK

Steps to record actions from emulator to MonkeyTalk IDE:

1. Open Eclipse.

2. Import project in eclipse and convert it to AspectJ by following steps mentioned on “https://tfortesting.wordpress.com/2012/08/31/steps-to-install-monkeytalk-android-agent/ “link.

3. Open Emulator.

4. Deploy your application to an Android device or emulator.

     Right click on Android project

     Choose “Run as” option and then “Android Application”

5. Open app in emulator for which you want to record script.

6. Open MonkeyTalk IDE and Click on the connection dropdown button on the tool bar (on initial start up it will be the green android icon).

7. Choose “Android Emulator” or “iOS Simulator”.

8. If connection was successful, a message to that effect should appear in the console.

9. In case record button is not visible to you can try

     Create a new AVD (emulator)

     Install a fresh app in emulator

     Stop and restart the server by:

     adb kill-server

     adb start-server

10. Create a MonkeyTalk project in MonkeyTalk IDE.

11. Then Create script under this MonkeyTalk project and Click on record button.

MonkeyTalk Command:

MonkeyTalk Commands are very easy to understand. Even non programmer can easily  understands the MonkeyTalk commands.

MonkeyTalk commands are newline terminated and have the following syntax:
ComponentType  MonkeyId  Action  Argumets  Modifiers

These all are parts of MonkeyTalk commands. ComponentType.Action is known as the command name. MonkeyTalk command are terminated by new line.

Description of each part of MonkeyTalk command:

ComponentType:

This part ofMonkeyTalk command is required field i.e. mandatory field. In this part you have to mention the type of component on which we want to perform action. For example Button, Slider, Spinner etc. Component types are not case sensitive.

MonkeyId:

  • This part ofMonkeyTalk command is also a required field i.e. mandatory field. An identifier that is used to distinguish between components of the same type being displayed simultaneously.
  • Monkeytalk ids are case sensitive.
  • MonkeyId can be specified as asterisk (*), which finds the first matching component.
  • MonkeyId’s can also be specified as a 1-based (not zero-based) index of the form #N.

Action:

This part ofMonkeyTalk command is also a required field i.e. mandatory field. In this field you have to mention the action to be performed. Examples Tap, Select, Drag, Swipe, EnterText. Actions are not case sensitive.

Arguments:

This part ofMonkeyTalk command is not a required field. It is required according to ComponentType and Action .Arguments are separated by space. If an Argument is required but not specified,it takes on a default value.

Modifiers:

It is an optional field. There are three system-defined modifiers:

  • %timeout – how long in ms to continue retrying a command before timing out
  • %thinktime – how long in ms to wait before executing the command for the first time
  • %retrydelay – how long in ms to delay between retry attempts

IMPORTANT POINTS (points to be remembered)

  • MonkeyIds and Args are case-sensitive, but CommandTypes and Actions are not.
  • All tokens are space-separated.
  • Values with embedded blanks must be enclosed in quotes.

Example:

Tap on a button with label login:

In MonkeyTalk i.e. in .mt form

Button LOGIN tap %thinktime=3000

In javascript form i.e. in .js

this.app.button(“LOGIN”).tap({thinktime:”3000″});

Where button is componenttype, login is monkeyid and Tap is action and thinktime is modifier.

Connecting MonkeyTalk IDE to Emulator, Simulator, or Real Device:

MonkeyTalk IDE appears as:

MonkeyTalk IDE is desktop app for record/playback/creation of test scripts.

Android Emulator / iOS Simulator:

  • Open the IDE.
  • Start up your Android or iOS emulator/simulator and load it with your MonkeyTalk enabled app.
  • Click on the connection dropdown button on the tool bar (on initial start up it will be the green android icon).

  •  Choose an option from connection dropdown with which you want to connect IDE.

Note: If you are connecting to an Android device for the first time, you will be prompted to point the MonkeyTalk IDE to your local Android SDK. Check the “Include Android Testing?” checkbox and point it to the SDK. You can also set this in your MonkeyTalk Preferences.

  • If connection was successful, a message to that effect should appear in the console.

Android and iOS Real Device:

  • Open the IDE
  • Start up your Android or iOS device, connect it to your local wireless network, and load it with your MonkeyTalk enabled app.
  • Click on the connection dropdown button on the tool bar (on initial start up it will be the green android icon).
  • Choose “Networked Android or iOS device.
  • Enter the IP address of the mobile device.
  • If connection was successful, a message to that effect should appear in the console.