Author: Reshma Sandeep Das
Date: 2009-29-07
Version: 3.7
Category
0x2001C3AF
Topic title
Synonyms for the topic
•	Context1 with a comment
•	User Emulator
Purpose and Scope
This document provides an outline on the User Emulator tool, instructions on how to use the tool and guidelines on reading and analysing the results after running the tool.
Overview
User Emulator:
User Emulator is a tool for automated test creation, execution and management. The tool is very useful to automate functional and non-functional testing of applications. Eg, stress testing application usage over 24 hours. Regression testing, etc. 
The user emulator tool programmatically simulates application UI usage as described in an XML script on the S60 device. This tool helps in writing, reusing and executing tests on the code under development.

Following are the features supported by the User Emulator tool:
– Up/down/left/right arrow key events
– Selection, LSK, RSK key events
– Menu key events
– Alpha-Numeric key events
– Launch application using UID/Name
– Loops in XML script
– Pointer/Touch events
– Take Screen shots
– Capture Panics 
– Log to file
– Record and playback of Key/Pointer events
– Random Test 
– Random Test to stress all applications under S60 menu system
– Random Test targeted to specific applications

Menu Options: 
After the application launch, any scripts available in the default settings path are displayed to the user. This view is refreshed if there is any change in the settings path or addition/deletion of scripts.
1. Run Scripts
Script execution can start by selecting the Run Scripts menu option. Script selection can be made by clicking on a script name. Single selection or multiple script selection option is available to the user. After the selection, file(s) are parsed using an XML parser and appropriate actions are performed. Visual indications of scripts execution pass/fail/cancellation are displayed using icons on the screen.
•	Green Icon: pass
•	Red Icon: Fail
•	Yellow Icon: Cancellation of script execution
Script run starts on idle screen after the Menu application and idle screen reset

2. Select
This option can be used for file selection and de-selection respectively. There is an option to select/de-select a single file or multiple files at the same time.
3. Record input
This menu option allows users to start recording any key presses or screen taps. User has to enter a name for the recorded script. The file name cannot contain any special characters. An error message is displayed to the user and a dialog is prompted to enter correct filename. The file is stored in 'Scripts Path ' folder. Screenshot tag can be added dynamically in the script by pushing the camera button once during script recording. Recording can be cancelled any time by pressing the power button once.
Script recording starts on idle screen after the Menu application and idle screen reset

4. Random test run
Starts the random test on the device and sends random key presses and screen taps to the device. Random test can be stopped by pressing the power button once.
5. Settings
This menu option launches a settings dialog that has configuration information for the User Emulator tool.

•	Scripts Path: User can modify the storage path of the test scripts.
•	Log Status: Logging option can be turned ON/OFF using this settings option.      
•	Log File Path: Path for the log file that logs the script execution actions. This file also captures any system wide panics.  

Note: User has to exit the tool in order to check the log files. Log files are overwritten every time the tool starts.

•	Target for Random Test? Can be ON/OFF. 'ON' enables random tests on ID specified application(s). If it is in 'OFF' state then random test will perform without starting an application at start time.

•	App Ids of Random Test: If the previous option is 'ON' then 'Random test run' will start application(s) at the beginning of the test using these IDs.
6. System Info
Option that gives the complete system information 
7. Help
Help file describing the User Emulator tool usage
8. About
A brief about the tool

Middle soft Key Options:
1.	Run Scripts
User can call Run Scripts to run a script on focus. 

XML Script Format
This section describes the data format of the XML script that is generated during script recording operation from an S60 device.
The XML script has user actions (key inputs/ screen taps) recorded and can be used to simulate the same during script execution.
Each user action is written as an action element enclosed within the main tag having the following syntax:

Syntax:
<UserEmulator>
 <action>
  <name>. </name>
  <type>. </type>
  <params>. </params>
  <keys>. </keys> 
  <screenshot> . </screenshot>
  <print> . </print>
 </action> 
</UserEmulator>

Description of tags and elements
•	<name>... </name>: 
This is an optional tag which can be used to define the action. A meaningful name can be given to this tag to identify the action. 

Syntax:
 <name> <Application name> </name>

Example: 
  <name> Calculator </name>

•	<type>... </type>: 
This is a mandatory tag which should be defined to identify the type of action. User has to choose any one of the below mentioned values to identify the type of action.

Currently supported types of action: 
   - app      (To launch an application)
   - view     (To switch the views)
   - closeapp   (To close any application)
   - keypress   (To simulate key press)
   - wait           (To pause for the specified duration in milliseconds)
   - javaapp     (To launch a java midlet)
   - pointerevent (To simulate pointer events)
   - orientation    (Change device's screen orientation (portrait or landscape mode))
   - screenreset  (Resets menu screen and older version of Home Screen's idle screen )

Note: 
The above types of action are case sensitive 

Syntax:
 <type> <action-type> </type>

Example: 
  <type> app </type>
  <type> view </type>
  <type> closeapp </type>

•	<params>... </params>: 
This tag should be used to pass parameters for carrying out specified action. This tag is mandatory if the <type> tag is set to any one of the following types:
"app, view, closeapp, wait, javaapp"

Syntax:
  <params> <application specific params> </type>

Example:

In order to launch an application, currently the UID of the application has to be passed as the first parameter and the application name as the second parameter. Comma (',') is used as a delimiter between the parameters. The second parameter (application name) is a label which is required for logging purposes
<params> 0x10005902, Calculator </params> //Launches the calculator application

For closing an application, the UID of the application along with the application name (comma separated) to be closed should be passed.
<params> 0x10005902, Calculator </params> // Closes the calculator application

In order to switch views, application UID and view ID (comma separated) should be passed to the params tag
<params> 0x101f4cd5, 0x05 </params> // Activates Missed calls view

For wait operation, the time interval in milliseconds should be specified as follows:
<params> 100 </params> //Pause for 100 milliseconds

For launching a java midlet, midlet name should be specified in the params tag. Midlet name is case sensitive.
<params> Music Store </params> //Launches Music Store application

•	<keys>… </keys>: 
This tag should be used to pass any key events to the application. More than one key code can be specified in the <keys> tag. Space (" ") is used as a delimiter between the key codes. Following key codes can be passed as the key events in <keys> tag.

 Key Codes Reference:
  LSK     = left soft key
  RSK    = right soft key
  DAK    = down arrow key
  RAK    = right arrow key
  LAK     = left arrow key
  UAK    = up arrow key
  MSK    = Middle soft key
  SP       = Space
  BS       = Backspace/clear
  lt          = Less Than
  gt         = Greater Than
  amp     = Ampersand
  MENU  = Menu
  KYES  = Green Key
  KNO    = Red Key

  1 = Number 1
  2 = Number 2
  3 = Number 3  
  4 = Number 4
  5 = Number 5
  6 = Number 6
  7 = Number 7  
  8 = Number 8
  9 = Number 9
 
Alphabets: 
a-z and A-Z  

Special characters:
. ? @  , ' ! " - ( ) / : _ ; + % = [ ] { } \ ~ ^ | ` $

Syntax:
  <keys> <key value > </type> 

Example: 
   <keys> DAK <keys> // Press down arrow key 

•	Loop:
This tag should be used to specify any repetitive actions and should be defined using the tag  
   <loop count='2'> // begin loop 
   .
   .
   </loop> // end loop

In the above tag, 'count' indicates the number of times the set of actions has to be executed in a loop. 

Syntax:
    <loop count=<enter the count value for looping action>
     .
     .
     </loop>

Example:

<loop count='5'>
 <action>
  <names> enter 1 </name>
  <type>    keypress   </type>
  <keys>   1 </keys>
 </action>
 </loop>

In the above example, key press 1 is sent to the application. This operation is carried out five times in a loop. 

Note: 
By specifying the count value as 'infinite', one can execute the operations in a loop infinitely.

Stopping Script Executions
Script execution can be interrupted by pressing the Power button on the device.
   
Example for launching a calculator application
<action>
  <name>   Calculator </name>
  <type>   app   </type>
  <params> 0x10005902, Calculator</params>
</action>

Example for switching views 
Activates the Missed calls view

<action>
  <name>   Missed Calls </name>
  <type>   view   </type>
  <params> 0x101f4cd5, 0x05 </params>
  <keys>   MSK MSK </keys>
</action>

Example for closing a calculator application
<action>
  <name>   Calculator </name>
  <type>   closeapp   </type>
  <params> 0x10005902, calculator</params>
</action>

Example for keypress action 
<action>
  <type>   keypress   </type>
  <keys>   1 2 </keys>
</action>

Example for wait/pause
<action>
  <name>   pause </name>
  <type>   wait   </type>
  <params> 4000 </params> //Time interval in milliseconds
</action>

Example for Loop action
<loop count='5'>
 <action>
  <name>   enter 1 and 2 </name>
  <type>   keypress   </type>
  <keys>   1 2 </keys>
 </action>
 </loop>

Example for launching a java application
Launches the Music Store application

<action>
  <name>   Music Store </name>
  <type>   javaapp  </type>
  <params> Music Store </params> //Midlet name 
</action>

<print>…</print>:
This is an optional tag that can be added in the scripts to print any debug logs. 

Example:
<action>
  <name>   Calculator </name>
  <type>   app   </type>
  <params> 0x10005902, calculator</params>
  <print>Open calculator</print>
 </action>

•	<screenshot> … </screenshot>
User Emulator can take a screenshot of the action that has the <screenshot> tag. The image file is stored with the name specified in the <screenshot tag> under the <\Logs\script file name> directory specified in the settings dialog. 
During script recording, this tag can be automatically added at any stage of recording, by just clicking on the camera button once. The name of the screenshot is added automatically and has the following format:
"app name in foreground"-"time stamp"

Example:
<screenshot> Menu-4563678 </screenshot>

•	Pointer Events
User Emulator can simulate pointer events on the touch enabled devices. Following are the pointer events currently supported. The pointer events are added within the <params> tag.

pointerdownAt ,x, y: Simulates pointer down event. 
x and y values are the co-ordinates of the pointer. (Start of a flick or tap, etc.)

pointerupAt, x,y: Simulates pointer up event. 
x and y values are the co-ordinates of the pointer. (End of a flick or tap, etc.)

moveto x, y: Simulates pointer move event. 
x and y values are the co-ordinates of the end of movement.

pointerdownAt, x, y, z:  Simulates finger down event. 
x and y values are the co-ordinates of the finger. Z is a threshold value. (Added to every co-ordinates)

pointerupAt, x,y,z: Simulates finger up event. 
x and y values are the co-ordinates of the finger. Z is a threshold value. (Added to every co-ordinates)

moveto x, y,z: Simulates finger move event. 
x and y values are the co-ordinates of the end of movement. Z is a threshold value. (Added to every co-ordinates)

Example:
<action>
  <name>  xxx </name>
  <type>   pointerevent   </type>
  <params> pointerdownAt,560,320,5 </params>
</action>

<action>
  <name>  xxx </name>
  <type>   pointerevent   </type>
  <params> moveTo, 520,310,5 </params>
</action>

<action>
  <name>  xxx </name>
  <type>   pointerevent   </type>
  <params> pointerupAt, 520,300,5 </params>
</action>

Note:
•	Since on software level there is no difference between stylus, finger tap, thumb tap, etc. all types of pointer events have general pointer event names with a threshold value.
•	In order to get the same results during script execution, all the screens on the device should be reset to its initial state before script recording and playback. 
•	Currently the tool supports basic reset functionality of resetting the Menu application's scroll bar, closing any open applications on the device and resetting the idle screen. 
o	If there are any changes to the application position in the Menu application or any changes on the Home Screen, the script when played back may not produce the same results. This is a known limitation of the tool