TUTORIAL: Advanced recording

Recording flow

Top right corner of the recording wizard page contains the buttons that controls the recording flow. Press Record button (Pic.1.b) to start. It will turn into Stop button, which is used to interrupt. Each time you start recording, the application is restarted. If you wish to interrupt the recording temporarily simply use Pause (Pic.1.b) button. None of your actions will be captured until you press Resume button.
This is useful when you record Robotium test that will have more than one test method. You can use Pause button to return to the main activity of your application and Resume to start back the recording in a new test method. See more in the Test command view section.

Recorder screen

Pic. 1. Recording view: a) Configuration picker b) Recording flow controlers
c) Command view tree d) Screenshot, Add method, Delete
Pausing is also handy if you happened to press something you didn’t mean to. For example you click on an item that takes you to a new activity, but you didn’t want to do that. Pause the recording, navigate back to the previous activity and delete the commands from the list. Deleting commands is explained later on.
If you are recording from sources, you can select a Run Configuration that will be used to launch your application. You can set it in the Configuration box (Pic.1.a). To create and manage the configurations, do the following:
  1. Right click on your project in the Package Explorer
  2. Run As – > Run Configurations…

Test command view

The command view tree (Pic.1.c), located in the center of the screen, features three kind of items:

  • A test case – single node, which represents the actual test file.
  • Test methods – the individual methods in the test file.
  • Test commands – the recorded actions – touches, drags, changes of activity etc.

We recommend that you split your test case to many smaller methods, rather than recording everything to single huge test method.

Adding methods

Add method to the test case:

  1. Press Add methodAdd Method to add new method to the test case.
  2. Type method name and press OK.

Recording Robotium test returns a plain JUnit test case which test methods are executed according to JUnit own test method life cycle. There is no guaranty to the order the test methods will be run. Additionally, there are two special methods setUp() and tearDown(). They are called, respectively, before and after execution of each test method. Those methods are used to prepare so called fixturesetUp() initiates it, tearDown() cleans things up. The fixture is a scaffolding common for each test method of the test case. In our case, setUp() method creates a new instance of a Robotium Solo class. When the object is created its loads the main activity of the application – the starting point for each test method.

The Recorder generates the JUnit 3.x code. In contrast to Junit 4.x, which uses @Test annotation to distinguish test methods, the 3.x version checks the methods names. The method will be executed according to the aforementioned scheme only if its name starts with prefix test. However, when you are adding a method, you are not forced to follow that pattern. You may use it to record auxiliary methods – piece of code that is repeated in your test many times. For example, it might be opening some view of your application. You can use that method later, after finished recording, when you modify the generated output code.
For the time being the Recorder does not support JUnit 4.x because Android Instrumentation does not support it.

Adding commands

You can add commands manually if recorder didn’t recognize any events or if you wanna do something beyond normal recording process. To do this:

  1. Right click the command, method, test case to open context menu
  2. Choose New command
  3. Choose the one you want to add
  4. Set needed properties in popped-up dialog and press OK
Place of adding commands depend on place where you clicked right mouse button:
  • on test case – new command will be added as last command in current recording method
  • on method – new command will be added as last command in this method
  • on command – new command will be added after selected one

Manual addition commands is not only useful for elements which wasn’t recognized properly but is also very useful together with assertion feature. You can add one of five asserts and take more control on test.

Editing commands

You can edit previously added or recorded commands. Do to it:

  1. Double-click on chosen command
  2. Set needed properties in popped-up dialog and press OK
or
  1. Right click the command to open context menu
  2. Choose edit command
  3. Set needed properties in popped-up dialog and press OK

Set currently recorded method

New test commands are appended only to one method at the time. The currently recorded method is marked with the icon. To change the recorded method:

  1. Right click the method in the command view to open context menu.
  2. Choose Set current recording

Renaming methods

You can always rename the method you have created. To rename:

  1. Right click the method in the command view to open context menu.
  2. Choose Rename method
  3. Give the new name for the method and press OK

Deleting methods

If you wish to remove one or more methods do the following:

  1. Select methods to deletion in the command view. Hold Ctrl button on keyboard to select multiple methods.
  2. Make sure that no test commands are selected.
  3. Press button (Pic.1.d) or select Remove method in context menu.
  4. Confirm by pressing Yes button.

Note: You cannot remove method that is currently being recorded – switch the recording to other method first.

Deleting commands

Similarly to removing methods you can remove test commands:

  1. Select commands to deletion in the command view. Hold Ctrl button on keyboard to select multiple methods.
  2. Make sure that no methods are selected.
  3. Press button (Pic.1.d) or select Remove command in context menu.

Note: It is quite common to remove test commands. To simplify operation there is no confirmation window – just be careful!

Copy, cut and paste commands/methods

You can copy/cut methods and commands:

  1. Select methods/commands to copy/cut in the command view. Hold Ctrl button on keyboard to select multiple methods/commands.
  2. Press Ctrl+c or Copy method/command in context menu(or Ctrl+x or Cut method/command in context menu for cut).
  3. Click place where you want to paste methods/commands.
  4. Press Paste before/after in context menu.

Drag&drops commands

You can drag and drop commands inside method or even between methods.

Hot keys

You can use hot keys to quickly push buttons when recording:

  • Ctrl+b – Paster before.
  • Ctrl+c – Copy method/command.
  • Ctrl+x – Cut method/command.
  • Ctrl+n – Add new method.
  • Ctrl+r – Set current recording.
  • Ctrl+v – Paster after.
  • Ctrl+e – edit command.
  • Delete – Delete method/command.
  • F2 – Rename method.

Screenshots

If you automate your UI tests, you probably don’t want to waste your time staring at them during execution. But what if something goes wrong? Wouldn’t it be great to see what happened? You can know that by capturing screenshots during the test execution. If you wish your test to take screenshots in a specific moment of your test press (Pic.1.d). It will add the capturing screenshot test commandat the end of the currently recorded method.

Note: Robotium stores screenshot on the SD card in the device, whereas monkerunner stores screenshots on the specified directory on the machine which executes the test scripts.

If you want Robotium to be able to capture screenshots, you have to place write permissions in the AndroidManifest.xml file of your application and testing application:

<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

Note: If you are using emulator to play Robotium tests with screenshots, make sure it has SD card configured.

 

Next on tutorials:
  1. Using Smart Asserts
Read our blog
18.05.2012

Before we start, please download the latest version of Testdroid Recorder and install it in Eclipse. Here you will find [...]

16.05.2012

May 15th, 2012 by Bitbar Woot! The Testdroid team just received an invitation from Google Android Developer Advocates team to play [...]

We make your app testing easier:
follow
Company info

Bitbar is a technology and services company with ambition to help its customers to get most of their R&D by offering high-performance automated software Build and Test solutions. Our solutions are ideal for development teams that want to deliver high quality software without the hassle of developing, building and maintaining own tools for Android testing. We are accelerating time to market and lowering costs of developing software on Android platform, be it on smartphones, tablet computers or TVs.


Bitbar is a technology and services company with ambition to help its customers to get most of their R&D by offering high-performance automated software Build and Test solutions. Our solutions are ideal for development teams that want to deliver high quality software without the hassle of developing, building and maintaining own tools for Android testing. We are accelerating time to market and lowering costs of developing software on Android platform, be it on smartphones, tablet computers or TVs.


Bitbar is a technology and services company with ambition to help its customers to get most of their R&D by offering high-performance automated software Build and Test solutions. Our solutions are ideal for development teams that want to deliver high quality software without the hassle of developing, building and maintaining own tools for Android testing. We are accelerating time to market and lowering costs of developing software on Android platform, be it on smartphones, tablet computers or TVs.


Copyrights to Bitbar info@bitbar.com