monkeytalk documentation

39
I MonkeyTalk Documentation

Upload: vivek-pansara

Post on 08-May-2015

1.460 views

Category:

Software


4 download

DESCRIPTION

Here's everything you want to know about MonkeyTalk Testing tool. You can easily automate testing of android application.

TRANSCRIPT

  • 1.I MonkeyTalk Documentation

2. II Table of Contents List of Figures .................................................................................................................................IV List of Tables ...................................................................................................................................V 1. Required softwares and Libraries:........................................................................................... 1 2. MonkeyTalk Tool support checklist......................................................................................... 2 3. Setup & Configuration of MonkeyTalk.................................................................................... 5 3.1 Install the MonkeyTalk IDE............................................................................................... 5 3.2 Installing the MonkeyTalk Android Agent........................................................................ 5 3.3 Create a Testing Project ................................................................................................... 7 3.4 Install the Android App .................................................................................................... 8 3.5 Connect to Your App ........................................................................................................ 9 3.5.1 Connecting to Emulator, Simulator, or Hardware.......................................................... 9 3.5.2 Android Emulator ........................................................................................................... 9 3.5.3 Android devices over WiFi............................................................................................ 10 4. How MonkeyTalk works: ....................................................................................................... 12 5. Supported Platforms: ............................................................................................................ 15 6. Application type:.................................................................................................................... 16 6.1 Native App:.......................................................................................................................... 16 6.2 Web App:............................................................................................................................. 16 6.3 Hybrid Apps:........................................................................................................................ 16 7. Language syntax & example.................................................................................................. 18 7.1 Commands: .................................................................................................................... 18 7.2 Modifiers ........................................................................................................................ 25 8. Advance feature add using JavaScript................................................................................... 26 3. III 8.1 Scripting in JavaScript.......................................................................................................... 26 8.1.1 If Control Statement..................................................................................................... 26 8.1.2 While Control statement.............................................................................................. 27 8.2 JavaScript Wrapper Library ................................................................................................. 27 8.3 Using JavaScript API ............................................................................................................ 28 8.3.1 Timeout and Thinktime ................................................................................................ 30 8.3.2 Verify Commands ......................................................................................................... 30 8.3.3 Calling MonkeyTalk from JavaScript............................................................................. 30 8.3.4 Calling Custom Commands........................................................................................... 30 9. Error Handling and Debugging Strategy................................................................................ 31 9.1 Using try-catch .................................................................................................................... 31 9.2 Using Modifiers ................................................................................................................... 32 9.3 Debugging............................................................................................................................ 32 10. Reporting............................................................................................................................ 33 4. IV List of Figures 3.1 Converting into AspectJ Project.11 3.2 Configurations of Libraries12 3.3 MonkeyTalk Script Editor13 3.4 MonkeyTalk IDE and Android Emulator14 3.5 Status of Connection in Console15 4.1 Recording of Commands.17 4.2 Stop Recording of Commands and Recorded Commands..18 4.3 Play Recorded Commands.19 4.4 Failure of Command..19 10.1 Report in XML format38 10.2 Report in HTML Format...39 5. V List of Tables 2.1 Table of supported features....7 7.2 List of MonkeyTalk commands.....23 6. 1 1. Required softwares and Libraries: MonkeyTalk v2.0.1 (https://www.cloudmonkeymobile.com/developer- resources/downloads (Login is needed)) Android Development Tools v21.1.0 (http://developer.android.com/sdk/index.html#download) Java Development Kit v1.7.0 (http://java.com/en/download/windows_ie.jsp?locale=en) AspectJ Development Tool v2.2.0 (http://www.eclipse.org/ajdt/whatsnew220) Monkeytalk agent.jar v2.0.1 (https://www.cloudmonkeymobile.com/developer- resources/downloads (Login is needed)) 7. 2 2. MonkeyTalk Tool support checklist Features and Benefits Community Edition Professional Edition iOS and Android apps - native, hybrid, and mobile web Simulators or Real Devices - no Jail breaking required Robust cross-platform Recording/Playback that actually works Full touch and gesture support Integrated Environment to create, run, and edit your tests Use the keyword-driven MonkeyTalk language, or powerful JavaScript or Java APIs Run your tests interactively or from continuous integration environments Validate controls, images, text, or any property of any object 8. 3 Data-drive your tests from a spreadsheet HTML, XML, xUnit reporting for tests and suites Instrument your app at run-time - no special build Install, launch, stop, or uninstall your app anytime Multiple devices from one script (ex. a chat conversation) Advanced command editor App restart from script command Extended reporting Built-in emulator Supports linked-in libraries and subprojects 9. 4 Integrated workflow for CloudMonkey LabManager Technical support from CloudMonkey Mobile Table 2.1 Table of supported features 10. 5 3. Setup & Configuration of MonkeyTalk The MonkeyTalk platform consists of two primary components: MonkeyTalk IDE and MonkeyTalk Agents The MonkeyTalk IDE is an Eclipse based tool that records, plays, edits, and manages functional test suites for iOS and Android applications running on simulators, emulators, and devices. MonkeyTalk Agents are libraries for iOS and Android that must be linked into applications to be tested. The agents enable applications to record and play MonkeyTalk Commands. Each command performs a user interface action or verification step. 3.1 Install the MonkeyTalk IDE 1. Download the zip file. This download contains the IDE, the Agents, and sample applications. 2. Unzip it wherever you want, but remember where you put it because you'll need it later. 3. On OS X, move the entire MonkeyTalk folder into your applications folder and double click on MonkeyTalk.app to run. 4. On Windows, move the entire MonkeyTalk folder into your Program Files folder and double click on MonkeyTalk.exe to run. 3.2 Installing the MonkeyTalk Android Agent Open your Android project in Eclipse and follow these instructions. 1. Install the AspectJ Development Tools plugin (AJDT) into Eclipse. 2. Convert your Android project to AspectJ. 11. 6 Figure 3.1 Converting into AspectJ Project 3. Add the monkeytalk-agent.jar to your Android project. 4. The agent can be found in the agents/android/ folder in the main MonkeyTalk zip package you downloaded earlier. The exact name of the android agent jar will include the version number (for example, monkeytalk-agent-1.0.30.jar). 5. Create a libs/ folder in your Android project (if you don't already have one), and copy the agent jar into it. 6. Include the monkeytalk-agent.jar in the AspectJ build path (right-click on monkeyTalk-agent.jar > AspectJ Tools > Add to Aspectpath). 7. Update your AndroidManifest.xml to include the following two permissions: android.permission.INTERNET android.permission.GET_TASKS 8. 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: 12. 7 Figure 3.2 Configurations of Libraries 9. You should also export the monkeytalk-agent.jar file you added to the project. (Note: in some older versions of the Android Development Tools, this export may create a "Dexification Error" - if you get this problem just uncheck this). 10.Deploy your application to an Android device or emulator 3.3 Create a Testing Project 1. Click on the Create Your First Project. The New Project wizard will be displayed. 2. Enter a name for your project and click Finish. The workbench window will open. 3. To create a test script, right-click on the project folder and select New > Script. The MonkeyTalk test editor will open with a new empty script. 4. Pick a name for your new script. The script editor will open and the MonkeyTalk toolbar will be displayed. 13. 8 Figure 3.3 MonkeyTalk Script Editor 5. 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. 3.4 Install the Android App You will need either i. an Android device, on the same WiFi network as the computer running the MonkeyTalk IDE, or ii. an Android Emulator and the Android SDK installed on your computer You can install it as you would any other .apk file, and then just launch it. 14. 9 You can also install .apk file from command line using adb command: adb install pathProjectName.apk Here pathProjectName.apk is the full relative path to the apk. 3.5 Connect to Your App 3.5.1 Connecting to Emulator, Simulator, or Hardware 1. The IDE communicates with the app over HTTP via a USB tether or Wi-Fi connection. You can record and play back tests against apps running on your local computer or network, or remotely over the internet. Figure 3.4 MonkeyTalk IDE and Android Emulator 3.5.2 Android Emulator 1. Open the IDE 2. Start up your Android emulator and load it with your MonkeyTalk enabled app. 3. Click on the connection dropdown button on the tool bar (on initial startup it will be the green android icon). 15. 10 Figure 3.5 Status of Connection in Console 4. Choose Android Emulator, depending on your platform of choice. 5. 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. 6. If connection was successful, a message to that effect should appear in the console. 3.5.3 Android devices over WiFi 1. Open the IDE 2. Start up your Android device, connect it to your local wireless network, and load it with your MonkeyTalk enabled app. 16. 11 3. Click on the connection dropdown button on the tool bar (on initial startup it will be the green android icon). 4. Choose Networked Android. 5. Enter the IP address of the mobile device. 6. If connection was successful, a message to that effect should appear in the console. 17. 12 4. How MonkeyTalk works: MonkeyTalk uses record and playback rule for testing. 4.1 Recording through the MonkeyTalk IDE 1. Make sure your device is on the same wifi network as your computer. 2. Connect to your device over the network. 3. Pull up your application on the device. 4. Click Record on the MonkeyTalk IDE. Figure 4.1 Recording of Commands 5. Interact with your application. MonkeyTalk should record each action as a new command in the table. 6. To stop recording, click the Stop button. 18. 13 Figure 4.2 Stop Recording of Commands and Recorded Commands 7. If the "Record" button is not lighting up, it may be one of two things: i. You are not properly connected to a device. ii. Your application is not properly set up for MonkeyTalk. 4.2 Playback 1. Restart your app. (Not essential, but useful for returning to a consistent initial state.) 2. Click the Play button to send the recorded commands to your app. 19. 14 Figure 4.3 Play Recorded Commands 3. 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. 4. Failures are logged in red to the console. Figure 4.4 Failure of Command 20. 15 5. Supported Platforms: Mac OS X Windows Linux 21. 16 6. Application type: Native, Web and Hybrid in iOS and Android 6.1 Native App: Native apps are built for a specific platform with the platform SDK, tools and languages, typically provided by the platform vendor Best Suited to provide best user experience and for targeted devices Dependent on native platform and hence requires separate code bases for respective device platforms. 6.2 Web App: Mobile Web apps are server-side apps, built with any server-side technology (PHP, Node.js, ASP.NET) that render HTML that has been styled so that it renders well on a device form factor. They are accessible over device native / third party browsers Applicable if existing web page functionality to be accessed from wide range of devices Maximum interoperability as there is little or no dependency on native device OS 6.3 Hybrid Apps: Native apps, run on the device, and are written with web technologies (HTML5, CSS and JavaScript). Development methodology where mobile applications are developed in one common language and which can be deployed to all the popular platforms at once 22. 17 Hybrid apps run inside a native container, and leverage the devices browser engine (but not the browser) to render the HTML and process the JavaScript locally HTML5 provides mobile device users richer mobile applications and improved usability 23. 18 7. Language syntax & example MonkeyTalk Commands are newline terminated and have following Syntax: ComponentType MonkeyId Action Args Modifiers 7.1 Commands: MonkeyTalk Action Description Example Device Rotate Change the device orientation. i.e. Landscape,Portrait Device * Rotate Landscape Back Presses the hardware device key Device * back search Presses the device search key. Device * Search Screenshot create screenshot folder in running project and we can capture screenshot at any point Device * Screenshot Menu Presses the device menu key. Device * Menu Get Returns iOS or Android. Device * Get a Select select an element from the table. Table * Select Boron SelectRow Select a row. row the row to select ScrollToRow(by row) Scroll to a row by row number. 24. 19 Table Row the row to select ScrollToRow(by Value) Scroll to a row by value. value (int)- the value of the row to scroll to. 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. 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. 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 25. 20 View 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 Tap Taps on the component i.e. plays a click. Swipe Swipe(scroll) the component in direction Left, Right, Up, or Down (case insensitive) Drag Touch down, drag across the component, then up TouchDown Start touching the component. TouchMove Drag across the component. one or more (x,y) coordinate pairs specifying the path of the drag gesture TouchUp Stop touching the component 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) 26. 21 Exec Call a method on a component. The method must take zero or more String arguments and return a String result. LongPress Performs a long press on the component i.e. it plays a longClick. 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 Where text is an 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 Select Select an item by value. TabBar * Select hierarchy %thinktime=1000 27. 22 TabBar 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 i.e. it plays a click. 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 28. 23 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. Where text is an 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. All methods of Label #1 Verify 29. 24 Label view are applicable on label. 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 Table 7.2 List of MonkeyTalk commands RunIf Command: Run a script that will only execute given a specific command passes. Example: Script logout.mt RunIf Label * Verify "Welcome, Fred!" 30. 25 7.2 Modifiers %timeout It is used for how long in mili-seconds to continue retrying a command before timing out. USE: Button LOGIN Verify LOGIN %timeout=3000 %thinktime It is used for how long in mili-seconds to wait before executing the command for the first time. USE: Button LOGOUT Tap %thinktime=3000 %retrydelay It is used for how long in mili-seconds to delay between retry attempts. USE: Button LOGOUT Tap %retrydelay=3000 %ignore It can skip commands. It can also skip tests and setup/teardown on individual tests within the suite. USE: Test Script.mt Run %ignore=true 31. 26 8. Advance feature add using JavaScript One can program in JavaScript and use additional features like loops, multiple inputs etc. 8.1 Scripting in JavaScript 8.1.1 If Control Statement For example, here is a script that enters a random username and password if none are provided: if (typeof Test == "undefined") { load("libs/Test.js"); }; Test.Login.prototype.run = function(usr, pwd) { usr = usr || randStr(); pwd = pwd || randStr(); this.app.input("username").enterText(usr); this.app.input("password").enterText(pwd); this.app.button("LOGIN").tap(); }; function randStr() { var text = ""; var possible ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for( var i=0; i < 5; i++ ) 32. 27 text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } 8.1.2 While Control statement For example, here is a script that selects an item from the item selector spinner Time 10 times: var counter=0; while(counter