com.jayway.android.robotium.solo
Class Solo

java.lang.Object
  extended by com.jayway.android.robotium.solo.Solo

public class Solo
extends Object

This class contains all the methods that the sub-classes have. It supports test cases that span over multiple activities. It supports regular expressions and will automatically scroll when needed. When writing tests there is no need to plan for or expect new activities in the test case. All is handled automatically by Robotium-Solo. Robotium-Solo can be used in conjunction with ActivityInstrumentationTestCase2. The test cases are written from a user perspective were technical details are not needed. Example of usage (test case spanning over multiple activities):


 public void setUp() throws Exception {
 solo = new Solo(getInstrumentation(), getActivity());
 }

 public void testTextShows() throws Exception {

 solo.clickOnText("Categories");
 solo.clickOnText("Other");
 solo.clickOnButton("Edit");
 solo.searchText("Edit Window");
 solo.clickOnButton("Commit");
 assertTrue(solo.searchText("Changes have been made successfully"));
 }

 

Author:
Renas Reda, renas.reda@jayway.com

Field Summary
static int LEFT
           
static int RIGHT
           
 
Constructor Summary
Solo(android.app.Instrumentation inst, android.app.Activity activity)
          Constructor that takes in the instrumentation and the start activity.
 
Method Summary
 void assertCurrentActivity(String message, Class expectedClass)
          Method used to assert that an expected activity is currently active.
 void assertCurrentActivity(String message, Class expectedClass, boolean isNewInstance)
          Method used to assert that an expected activity is currently active with the possibility to verify that the expected activity is a new instance of the activity.
 void assertCurrentActivity(String message, String name)
          Method used to assert that an expected activity is currently active.
 void assertCurrentActivity(String message, String name, boolean isNewInstance)
          Method used to assert that an expected activity is currently active with the possibility to verify that the expected activity is a new instance of the activity.
 void clickLongOnScreen(android.view.View view)
          Method used to long click on a specific view.
 void clickLongOnTextAndPress(String text, int index)
          This method is used to long click on a specific text view and then selecting an item from the menu that appears.
 boolean clickOnButton(int index)
          This method used to click on a button with a specific index.
 void clickOnButton(String name)
          Method used to click on a button with a given text.
 void clickOnImage(int index)
          This method is used to click on an image with a certain index.
 void clickOnScreen(android.view.View view)
          Method used to click on a specific view.
 void clickOnText(String text)
          This method is used to click on a specific view displaying a certain text.
 void drag(float fromX, float toX, float fromY, float toY, int stepCount)
          Simulate touching a specific location and dragging to a new location.
 void enterText(int index, String text)
          This method is used to enter text into an EditText or a NoteField with a certain index.
 void finalize()
          All activites that have been active are finished.
 ArrayList<android.app.Activity> getAllOpenedActivities()
          This method returns an ArrayList of all the opened/active activities.
 android.widget.Button getButton(int index)
          This method returns a button with a certain index.
 int getCurrenButtonsCount()
          This method returns the number of buttons located in the current activity.
 android.app.Activity getCurrentActivity()
          This method returns the current activity.
 ArrayList<android.widget.Button> getCurrentButtons()
          This method returns an ArrayList with the buttons located in the current activity.
 ArrayList<android.widget.EditText> getCurrentEditTexts()
          This method returns an ArrayList of all the edit texts located in the current activity.
 ArrayList<android.widget.GridView> getCurrentGridViews()
          This method returns an ArrayList of the grid views located in the current activity.
 ArrayList<android.widget.ImageView> getCurrentImageViews()
          This method returns an ArrayList of the images contained in the current activity.
 ArrayList<android.widget.ListView> getCurrentListViews()
          This method returns an ArrayList of all the list views located in the current activity.
 ArrayList<android.widget.Spinner> getCurrentSpinners()
          This method returns an ArrayList of spinners (drop-down menus) located in the current activity.
 ArrayList<android.widget.TextView> getCurrentTextViews(android.view.View parent)
          This method returns an ArrayList of the text views located in the current activity.
 android.widget.EditText getEditText(int index)
          This method returns an EditText with a certain index.
 android.view.View getTopParent(android.view.View view)
          Method used to get the absolute top view in an activity.
 ArrayList<android.view.View> getViews()
          This method returns an ArrayList of all the views located in the current activity.
 void goBack()
          Method used to simulate pressing the hard key back.
 void pressMenuItem(int index)
          Method used to press a MenuItem with a certain index.
 void pressSpinnerItem(int spinnerIndex, int itemIndex)
          Method used to press on a spinner (drop-down menu) item.
 boolean scrollDownList()
          This method is used to scroll down a list or scroll view.
 void scrollToSide(int side)
          This method is used to scroll horizontally.
 void scrollUpList()
          This method is used to scroll up a list.
 boolean searchButton(String search)
          Searches for a button with the given search string and returns true if at least one button is found with the expected text.
 boolean searchButton(String search, int matches)
          Searches for a button with the given search string and returns true if the searched button is found a given number of times.
 boolean searchEditText(String search)
          Searches for a text string in the edit texts located in the current activity.
 boolean searchText(String search)
          Searches for a text string and returns true if at least one item is found with the expected text.
 boolean searchText(String search, int matches)
          Searches for a text string and returns true if the searched text is found a given number of times.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values
Constructor Detail

Solo

public Solo(android.app.Instrumentation inst,
            android.app.Activity activity)
Constructor that takes in the instrumentation and the start activity.

Parameters:
inst - the instrumentation object
activity - the start activity
Method Detail

getViews

public ArrayList<android.view.View> getViews()
This method returns an ArrayList of all the views located in the current activity.

Returns:
ArrayList with the views found in the current activity

getTopParent

public android.view.View getTopParent(android.view.View view)
Method used to get the absolute top view in an activity.

Parameters:
view - the view whose top parent is requested
Returns:
the top parent view

searchEditText

public boolean searchEditText(String search)
Searches for a text string in the edit texts located in the current activity. Will automatically scroll when needed.

Parameters:
search - the search string to be searched
Returns:
true if an edit text with the given text is found or false if it is not found

searchButton

public boolean searchButton(String search)
Searches for a button with the given search string and returns true if at least one button is found with the expected text. Will automatically scroll when needed.

Parameters:
search - the string to be searched. Regular expressions are supported
Returns:
true if a button with the given text is found and false if it is not found

searchButton

public boolean searchButton(String search,
                            int matches)
Searches for a button with the given search string and returns true if the searched button is found a given number of times. Will automatically scroll when needed.

Parameters:
search - the string to be searched. Regular expressions are supported
matches - the number of matches expected to be found. 0 matches means that one or more matches are expected to be found
Returns:
true if a button with the given text is found a given number of times and false if it is not found

searchText

public boolean searchText(String search)
Searches for a text string and returns true if at least one item is found with the expected text. Will automatically scroll when needed.

Parameters:
search - the string to be searched. Regular expressions are supported
Returns:
true if the search string is found and false if it is not found

searchText

public boolean searchText(String search,
                          int matches)
Searches for a text string and returns true if the searched text is found a given number of times. Will automatically scroll when needed.

Parameters:
search - the string to be searched. Regular expressions are supported
matches - the number of matches expected to be found. 0 matches means that one or more matches are expected to be found
Returns:
true if search string is found a given number of times and false if the search string is not found

getAllOpenedActivities

public ArrayList<android.app.Activity> getAllOpenedActivities()
This method returns an ArrayList of all the opened/active activities.

Returns:
ArrayList of all the opened activities

getCurrentActivity

public android.app.Activity getCurrentActivity()
This method returns the current activity.

Returns:
current activity

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  String name)
Method used to assert that an expected activity is currently active.

Parameters:
message - the message that should be displayed if the assert fails
name - the name of the activity that is expected to be active e.g. "MyActivity"

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  Class expectedClass)
Method used to assert that an expected activity is currently active.

Parameters:
message - the message that should be displayed if the assert fails
expectedClass - the class object that is expected to be active e.g. MyActivity.class

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  String name,
                                  boolean isNewInstance)
Method used to assert that an expected activity is currently active with the possibility to verify that the expected activity is a new instance of the activity.

Parameters:
message - the message that should be displayed if the assert fails
name - the name of the activity that is expected to be active e.g. "MyActivity"
isNewInstance - true if the expected activity is a new instance of the activity

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  Class expectedClass,
                                  boolean isNewInstance)
Method used to assert that an expected activity is currently active with the possibility to verify that the expected activity is a new instance of the activity.

Parameters:
message - the message that should be displayed if the assert fails
expectedClass - the class object that is expected to be active e.g. MyActivity.class
isNewInstance - true if the expected activity is a new instance of the activity

goBack

public void goBack()
Method used to simulate pressing the hard key back.


clickOnButton

public void clickOnButton(String name)
Method used to click on a button with a given text. Will automatically scroll when needed.

Parameters:
name - the name of the button presented to the user. Regular expressions are supported

pressMenuItem

public void pressMenuItem(int index)
Method used to press a MenuItem with a certain index. Index 0 is the first item in the first row and index 3 is the first item in the second row.

Parameters:
index - the index of the menu item to be pressed

pressSpinnerItem

public void pressSpinnerItem(int spinnerIndex,
                             int itemIndex)
Method used to press on a spinner (drop-down menu) item.

Parameters:
spinnerIndex - the index of the spinner menu to be used
itemIndex - the index of the spinner item to be pressed

clickOnScreen

public void clickOnScreen(android.view.View view)
Method used to click on a specific view.

Parameters:
view - the view that should be clicked

clickLongOnScreen

public void clickLongOnScreen(android.view.View view)
Method used to long click on a specific view.

Parameters:
view - the view that should be long clicked

clickOnText

public void clickOnText(String text)
This method is used to click on a specific view displaying a certain text. Will automatically scroll when needed.

Parameters:
text - the text that should be clicked on. Regular expressions are supported

clickLongOnTextAndPress

public void clickLongOnTextAndPress(String text,
                                    int index)
This method is used to long click on a specific text view and then selecting an item from the menu that appears. Will automatically scroll when needed.

Parameters:
text - the text that should be clicked on. Regular expressions are supported
index - the index of the menu item that should be pressed

clickOnButton

public boolean clickOnButton(int index)
This method used to click on a button with a specific index.

Parameters:
index - the index number of the button
Returns:
true if button with specified index is found

drag

public void drag(float fromX,
                 float toX,
                 float fromY,
                 float toY,
                 int stepCount)
Simulate touching a specific location and dragging to a new location. This method was copied from TouchUtils.java in the Android Open Source Project, and modified here.

Parameters:
fromX - X coordinate of the initial touch, in screen coordinates
toX - Xcoordinate of the drag destination, in screen coordinates
fromY - X coordinate of the initial touch, in screen coordinates
toY - Y coordinate of the drag destination, in screen coordinates
stepCount - How many move steps to include in the drag

scrollDownList

public boolean scrollDownList()
This method is used to scroll down a list or scroll view.

Returns:
true if more scrolling can be done and false if it is at the end of the scroll/list view

scrollUpList

public void scrollUpList()
This method is used to scroll up a list.


scrollToSide

public void scrollToSide(int side)
This method is used to scroll horizontally.

Parameters:
side - the side in which to scroll

enterText

public void enterText(int index,
                      String text)
This method is used to enter text into an EditText or a NoteField with a certain index.

Parameters:
index - the index of the text field. Index 0 if only one available.
text - the text string that is to be entered into the text field

clickOnImage

public void clickOnImage(int index)
This method is used to click on an image with a certain index.

Parameters:
index - the index of the image to be clicked

getCurrentImageViews

public ArrayList<android.widget.ImageView> getCurrentImageViews()
This method returns an ArrayList of the images contained in the current activity.

Returns:
ArrayList of the images contained in the current activity

getEditText

public android.widget.EditText getEditText(int index)
This method returns an EditText with a certain index.

Returns:
the EditText with a specified index

getButton

public android.widget.Button getButton(int index)
This method returns a button with a certain index.

Parameters:
index - the index of the button
Returns:
the button with the specific index

getCurrenButtonsCount

public int getCurrenButtonsCount()
This method returns the number of buttons located in the current activity.

Returns:
the number of buttons in the current activity

getCurrentEditTexts

public ArrayList<android.widget.EditText> getCurrentEditTexts()
This method returns an ArrayList of all the edit texts located in the current activity.

Returns:
an ArrayList of the edit texts located in the current activity

getCurrentListViews

public ArrayList<android.widget.ListView> getCurrentListViews()
This method returns an ArrayList of all the list views located in the current activity.

Returns:
an ArrayList of the list views located in the current activity

getCurrentSpinners

public ArrayList<android.widget.Spinner> getCurrentSpinners()
This method returns an ArrayList of spinners (drop-down menus) located in the current activity.

Returns:
an ArrayList of the spinners located in the current activity or view

getCurrentTextViews

public ArrayList<android.widget.TextView> getCurrentTextViews(android.view.View parent)
This method returns an ArrayList of the text views located in the current activity.

Parameters:
parent - the parent View in which the text views should be returned. Null if all text views from the current activity should be returned
Returns:
an ArrayList of the text views located in the current activity or view

getCurrentGridViews

public ArrayList<android.widget.GridView> getCurrentGridViews()
This method returns an ArrayList of the grid views located in the current activity.

Returns:
an ArrayList of the grid views located in the current activity

getCurrentButtons

public ArrayList<android.widget.Button> getCurrentButtons()
This method returns an ArrayList with the buttons located in the current activity.

Returns:
and ArrayList of the buttons located in the current activity

finalize

public void finalize()
              throws Throwable
All activites that have been active are finished.

Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2009-2010. All Rights Reserved.