Documente Academic
Documente Profesional
Documente Cultură
Installing MonkeyTalk
1.
2.
First, you must install the MonkeyTalkIDE. See the MonkeyTalkIDE Installation Guide for detailed instructions.
Next, you'll need to install the MonkeyTalk Agent in your iOS app or Android app or both for cross-platform testing. See the
MonkeyTalk Agent for iOS Installation Guide or the MonkeyTalk Agent for Android Installation Guide depending on your platform.
Download the zip file here. This download contains the IDE, the Agents (which you will need for the next step), and sample
applications.
Unzip it wherever you want, but remember where you put it because you'll need it later.
On OS X, move the entire MonkeyTalkIDE folder into your applications folder and double click on MonkeyTalk.app to run.
On Windows, move the entire MonkeyTalkIDE folder into your Program Files folder and double click on MonkeyTalk.exe to run.
(Note: If you choose to put MonkeyTalkIDE in your Program Files folder, you will have to choose a different location for your
workspace.)
You may also want to rename the Scheme from the Manage Schemes window:
5. When the dialog box appears, navigate to the directory where you unzipped the MonkeyTalk zip file, and select the MonkeyTalk iOS lib from
pathToMonkeyTalkFolder/agents/iOS.
6. Recursively create groups for any added folders option. Note: It is up to you whether or not you want to Copy items into destination group's
folder.
7. In the Add to Targets box, deselect YourApp and select YourAppMonkey.
5. Choose your duplicated test target from the Scheme menu in Xcode and Run on the Simulator or Device.
Log output will show that MonkeyTalk has successfully loaded in your app (as seen below)
2.
MonkeyTalk-agent.jar can be found in the "agents" folder in the MonkeyTalk package you downloaded earlier, and can be
downloaded here. The exact name of the jar might vary depending on the version, but it should always start with "MonkeyTalkagent".
Create a "libs" folder in your Android project, if you don't already have one.
Copy the .jar into the libs folder
Right click on MonkeyTalk-agent.jar > AspectJ Tools > Add to Aspectpath.
3.
4.
5.
6.
Update the project properties (right-click on the project > Properties > Java Build Path), select the Order and Export tab, and check
the checkbox next to the AspectJ Runtime Library to export it:
8.
Tip: You can return to the Welcome Screen by selecting Help > Welcome from the main menu.
Click on the Create Your First Project. The New Project wizard will be displayed.
Enter a name for your project and click Finish. The workbench window will open.
To create a test script, right-click on the project folder and select New > Test. The MonkeyTalk test editor will open with a new empty test.
10
The script editor will open and the MonkeyTalk toolbar will be displayed.
Assuming you've already linked the MonkeyTalk Agent into the app you want to test, you are now ready to connect and begin recording a test
script.
You can create new projects any time by selcting the File > New MonkeyTalk Project menu option.
11
12
5.
13
If thr Record button is disabled, it is because you are not connected. Click the Connect button to initiate a connection.
5.
6.
Interact with your application. MonkeyTalk should record each action as a new command in the table.
To stop recording, click the Stop button.
If the Record button is not lighting up, it may be one of two things:
1.
2.
You are not properly connected to a device. To read more on connecting to a device, go here.
Your application is not properly set up for MonkeyTalk. To read more on installing the MonkeyTalk agent and setting your app up
correctly, go here.
14
The script above is a simple login test the enters a userid and password, taps the login button, and then taps the logout button. The
MonkeyTalk Script Editor displays and edits scripts in a Table View.You can also edit scripts using any simple text editor. Clicking on the
MonkeyTalk tab in the editor will let you edit the script as text.
A MonkeyTalk command is made up of the values displayed in the columns of the Table View. To specify an empty table cell in a text command,
use an asterisk (*).
15
Restart your app. (Not essential, but useful for returning to a consistent initial state.)
Click the Play button to send the recorded commands to your app.
If MonkeyTalk can't find a component during playback, a command will fail. For example, in a login script, the application might take
a few seconds to process a login request, and a script may not wait long enough before trying to tap on a button that won't be
displayed until the login action has completed.
Failures are logged in red to the console.
16
1.
2.
To edit through the table view, right click on the table and choose "Append row." Click in each cell to enter your new command. You
can also use the drop down menus to select from a list of options.
To edit through the MonkeyTalk view, switch to the MonkeyTalk tab and edit the textual commands directly.
If you wish to know more about MonkeyTalk commands, you can start by reading about the Command Syntax or the User Guide entry for
Playback.
17
1.
Now run the script as normal by pressing the Play button. The script's success or failure is reported in the console.
You can do more than just Verify for simple values. Read the Test Specification or the User Guide entry for Tests for more information.
Next Steps
Congratulations on learning how to setup your application and how to record, playback, and add verification steps to a test script.
See the MonkeyTalk User Guide to learn about additional MonkeyTalk capabilities including:
18
Command Examples
All tokens are space-separated. Values with embedded blanks must be enclosed in quotes. Embedded quotes are escaped with backslash, as is
backslash itself.
Tap on the Button with the label OK:
Button OK Tap
Use a numbered MonkeyId to tap on the first button:
Button #1 Tap
No MonkeyId, so it defaults to #1:
Button * Tap
19
Scripts
Put one or more MonkeyTalk commands in a file and save it with .mt file extension and now you have a MonkeyTalk Script.
For example, a login.mt script might look like this:
# simple script to login as joe
Input username EnterText joe@doe.com
Input password EnterText i like cheese
Button LOGIN Tap
From within another script, we can invoke our login.mt script using the Script command with the file name as the MonkeyId, like this: Script
login.mt Run
Variables
Scripts may contain named substitution variables which are written as ${name} and can be specified anywhere in a MonkeyTalk command.
They may also contain built-in variables, written as %{var}. The available built-in variable are %{componentType}, %{monkeyId}, %{action}, and
any args are %{1}, %{2}, etc. Variables may only be used within a command part, so inside ComponentType, MonkeyId, etc.
For example, a named variable can be used for the Arg:
Input username EnterText ${usr}
Or the Arg and the MonkeyId:
Input ${foo} EnterText ${bar}
Or even everything:
${foo} ${bar} ${baz}
Variables can be embedded inside some text, but not within another variable, for example:
Input username EnterText ${usr}@example.com
But this would be illegal (a variable within a variable):
Input username EnterText ${foo${bar}}
20
Data-driven Scripts
Parametrized scripts are just the beginning, MonkeyTalk allows for full data-driven scripts simply by using the RunWith action instead of Run,
and setting a data file as the first Arg.
Using our parametrized login.mt script, we first write a data file, credentials.csv, in CSV format like this:
usr, pwd
joe-at-doe.com, "i like cheese"
alpha-at-beta.net, password1
charlie-at-dog.org, abc123
Where the first row specifies the variable names (exactly as they are named in the Vars.Define command in login.mt), and the following rows
give the values.
Now, we can data-drive our script like this: Script login.mt RunWith credentials.csv
This will run the login.mt script once for each row of data in the data file. So in the case of the above credentials.csv data file, it would invoke
login.mt three times, first with usr = joe-at-doe.com and pwd = "i like cheese", second with usr = alpha-at-beta.net and pwd = password1, and
third with usr = charlie-at-dog.org and pwd = abc123.
Custom Commands
The MonkeyTalk language can be extended directly by adding new custom commands with custom ComponentTypes and custom Actions. Any
script saved with a two-part filename, in the form of <componentType>.<action>.mt, becomes a custom command. For example, if we renamed
login.mt to login.perform.mt we would add a new Login component type that has a Perform action.
And we invoke our new custom command in the standard fashion:
login * perform
21
Verify
The Verify action exists on all components (except Script and Device) and is used to check if the actual value matches the expected value. In its
base form, verify accepts three optional arguments: expectedValue, propPath, and failMessage.
Without any parameters Verify just verifies the existence of the given component:
Button LOGIN Verify
With just an expectedValue, Verify checks the components value, where value is just the logical value of the component (value of a Button is its
label, value of an Input is its text, value of a CheckBox is "on" or "off", etc.):
Button LOGIN Verify LOGIN
With an expectedValue plus a propPath, Verify checks the given component property. Some propPaths such as value and item are logical
MonkeyTalk-specific property paths and are supported cross-platform (they don't begin with a dot). Component-specific propPath's are
platform-specific (and always begin with a dot).
Verify the font name on an iOS Button:
Button LOGIN Verify Helvetica .font.fontName
22
Verification Commands
Suites
Tests only be run from a suite, and only a suite can contain tests. Furthermore, suites must have the .mts file extension to distinguish them
from scripts. Suites may only contain Test, Setup, and Teardown component types, and also comments.
For example, the suite, myapp.mts, might look like this:
# setup runs before every test
Setup login.mt Run joe@doe.com i like cheese
# teardown runs after every test
TearDown logout.mt Run
# the tests...
Test add_contact.mt RunWith contacts.csv
Test remove_contact.mt RunWith contacts.csv
Here we use Setup and Teardown commands to specify scripts to be run before and after every Test command invocation.
Command Execution
Unless otherwise specified, MonkeyTalk commands are automatically retried until the timeout is reached. The timeout value has a global
default value of two seconds, but it can be overridden on a per command basis by using the timeout Modifier.
For example:
Button OK Tap %timeout=5000 %thinktime=2000 %retrydelay=123
Which will wait for 2 seconds, before trying to tap the OK button, then retry every 123ms before timeout eventually occurs after 5 seconds (7
total seconds after the command started playback).
Scripting in Javascript
Exporting to Javascript is intended as a tool for introducing common programming contructs into MonkeyTalk. This could include things like
loops, control statments, and random numbers.
To export to Javascript, create a MonkeyTalk script and click on the "JavaScript" tab at the bottom of the viewer. There you will find an "Export"
button. Click that button and MonkeyTalk will create a .js file with the same name as the .mt file. (E.g. Login.mt -> Login.js).
To execute the new Monkeytalk-Javascript file, run it just like you would a normal MonkeyTalk script, like so:
Script Login.js Run
23
Every time you save an .mt script, MonkryTalk IDE generates a JavaScript wrapper function so that you can call your script cleanly
and directly from JavaScript. The generated library is called YourProjectName.js and is stored in your project's generated libs
directory. This directory also contains the MonkeyTalk JavaScript API file MonkeyTalkAPI.js.
When you save enterName.mt, a function is generated so that from JavaScript you can say:
# enterName.mt
Vars name="foo"
Input name EnterText ${name}
Button OK Tap
this.app.enterName().run("bar")
or
this.app.enterName().runWith("somedata.csv")
A "call" function is also generated that explicitly defines the expected arguments (which assists command completion in the IDE) so
this.app.enterName().call("foo") works too.
24
25
API Reference
Button
ButtonSelector
o select(value:String):void - Select an item by value.
value - the value of the item to select.
o selectIndex(itemNumber:int):void - Selects an item by index.
itemNumber - the index of the item to select.
o longSelectIndex(itemNumber:int):void - Long press an item by index.
itemNumber - the index of the item to long press.
o inherited from View
CheckBox
DatePicker
o
o
26
o
o
o
o
o
o
Device
shake():void - Shake the device.
rotate(direction:String):void - Change the device orientation.
direction - Left or Right (case insensitive)
back():void - Navigate back. iOS: Pops the current UINavigationItem (if there is one). Android: Presses the hardware
device key.
forward():void - Navigate forward. iOS: Pushes the next UINavigationItem, if there is one. Android: ignored.
search():void - Press the search key. iOS: ignored. Android: Presses the device search key.
menu():void - Press the menu key. iOS: ignored. Android: Presses the device menu key.
Doc
o
o
IndexedSelector
o selectIndex(itemNumber:int):void - Selects an item by index.
itemNumber - the index of the item to select.
o longSelectIndex(itemNumber:int):void - Long press an item by index.
itemNumber - the index of the item to long press.
o inherited from View
Input
o
o
o
ItemSelector
o select(value:String):void - Select an item by value.
value - the value of the item to select.
o selectIndex(itemNumber:int):void - Selects an item by index.
itemNumber - the index of the item to select.
o longSelectIndex(itemNumber:int):void - Long press an item by index.
itemNumber - the index of the item to long press.
o inherited from View
Label
Menu
o
o
o
o
o
NumericSelector
o select(value:float):void - Select a numeric component value
value - the value to select
o inherited from View
RatingBar
o
o
Script
o
o
Scroller
27
Setup
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
Test
o
o
Teardown
Table
TabBar
Slider
TextArea
28
Toggle
ToolBar
o
o
o
o
Vars
VideoPlayer
o play():void - Play the video from the current playback point.
o pause():void - Stop the video at the current playback point.
o stop():void - Stop the video and set playback to the starting point.
o inherited from View
View
o
o
o
o
29
coords - one or more (x,y) coordinate pairs specifying the path of the drag gesture
touchUp(x:int, y:int):void - Stop touching the component.
x - x-coordinate of where touch is released
y - y-coordinate of where touch is released
pinch(scale:float, velocity:float):void - 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)
swipe(direction:String):void - Swipe the component.
direction - Left, Right, Up, or Down (case insensitive)
drag(x1:int, y1:int, x2:int, y2:int):void - Touch down, drag across the component, then up
x1 - starting x-coordinate
y1 - starting y-coordinate
x2 - ending x-coordinate
y2 - ending y-coordinate
get(variable:String, propPath:String):String - Gets the value of the given property from the component, and set it into
the given variable name.
variable - the name of the variable to set
propPath - the property name or path expression (defaults to 'value')
exec(method:String, args:String):String - Call a method on a component. The method must take zero or more String
arguments and return a String result.
method - the method to call
args - the String args to be supplied to the method
30