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. Robotium has full support for Activities, Dialogs, Toasts, Menus and Context Menus. 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 DELETE
           
static int DOWN
           
static int ENTER
           
static int LANDSCAPE
           
static int LEFT
           
static int MENU
           
static int PORTRAIT
           
static int RIGHT
           
static int UP
           
 
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)
          Asserts that the expected Activity is the currently active one.
 void assertCurrentActivity(String message, Class expectedClass, boolean isNewInstance)
          Asserts that the expected Activity is the currently active one, with the possibility to verify that the expected Activity is a new instance of the Activity.
 void assertCurrentActivity(String message, String name)
          Asserts that the expected Activity is the currently active one.
 void assertCurrentActivity(String message, String name, boolean isNewInstance)
          Asserts that the expected Activity is the currently active one, with the possibility to verify that the expected Activity is a new instance of the Activity.
 void assertMemoryNotLow()
          Asserts that the available memory in the system is not low.
 void clearEditText(android.widget.EditText editText)
          Clears the value of an EditText.
 void clearEditText(int index)
          Clears the value of an EditText.
 ArrayList<android.widget.TextView> clickInList(int line)
          Clicks on a given list line and returns an ArrayList of the TextView objects that the list line is showing.
 ArrayList<android.widget.TextView> clickInList(int line, int listIndex)
          Clicks on a given list line on a specified list and returns an ArrayList of the TextViews that the list line is showing.
 void clickLongOnScreen(float x, float y)
          Long clicks a given coordinate on the screen.
 void clickLongOnScreen(float x, float y, int time)
          Long clicks a given coordinate on the screen for a given amount of time.
 void clickLongOnText(String text)
          Long clicks on a given View.
 void clickLongOnText(String text, int match)
          Long clicks on a given View.
 void clickLongOnText(String text, int match, boolean scroll)
          Long clicks on a given View.
 void clickLongOnText(String text, int match, int time)
          Long clicks on a given View.
 void clickLongOnTextAndPress(String text, int index)
          Long clicks on a given View and then selects an item from the context menu that appears.
 void clickLongOnView(android.view.View view)
          Long clicks on a given View.
 void clickLongOnView(android.view.View view, int time)
          Long clicks on a given View for a given amount of time.
 void clickOnButton(int index)
          Clicks on a Button with a given index.
 void clickOnButton(String name)
          Clicks on a Button with a given text.
 void clickOnCheckBox(int index)
          Clicks on a CheckBox with a given index.
 void clickOnEditText(int index)
          Clicks on an EditText with a given index.
 void clickOnImage(int index)
          Clicks on an ImageView with a given index.
 void clickOnImageButton(int index)
          Clicks on an ImageButton with a given index.
 void clickOnMenuItem(String text)
          Clicks on a menu item with a given text.
 void clickOnMenuItem(String text, boolean subMenu)
          Clicks on a menu item with a given text.
 void clickOnRadioButton(int index)
          Clicks on a RadioButton with a given index.
 void clickOnScreen(float x, float y)
          Clicks on a given coordinate on the screen.
 void clickOnText(String text)
          Clicks on a View displaying a given text.
 void clickOnText(String text, int match)
          Clicks on a View displaying a given text.
 void clickOnText(String text, int match, boolean scroll)
          Clicks on a View displaying a given text.
 void clickOnToggleButton(String name)
          Clicks on a ToggleButton with a given text.
 void clickOnView(android.view.View view)
          Clicks on a given View.
 void drag(float fromX, float toX, float fromY, float toY, int stepCount)
          Simulate touching a given location and dragging it to a new location.
 void enterText(android.widget.EditText editText, String text)
          Enters text into a given EditText.
 void enterText(int index, String text)
          Enters text into an EditText with a given index.
 void finalize()
          All activites that have been active are finished.
 ArrayList<android.app.Activity> getAllOpenedActivities()
          Returns an ArrayList of all the opened/active activities.
 android.widget.Button getButton(int index)
          Returns a Button with a given index.
 android.widget.Button getButton(String text)
          Returns a Button which shows a given text.
 android.app.Activity getCurrentActivity()
          Returns the current Activity.
 ArrayList<android.widget.Button> getCurrentButtons()
          Returns an ArrayList of the Button objects located in the current Activity.
 ArrayList<android.widget.CheckBox> getCurrentCheckBoxes()
          Returns an ArrayList of the CheckBox objects contained in the current Activity.
 ArrayList<android.widget.DatePicker> getCurrentDatePickers()
          Returns an ArrayList of the DatePicker objects contained in the current Activity.
 ArrayList<android.widget.EditText> getCurrentEditTexts()
          Returns an ArrayList of the EditText objects contained in the current Activity.
 ArrayList<android.widget.GridView> getCurrentGridViews()
          Returns an ArrayList of the GridView objects contained in the current Activity.
 ArrayList<android.widget.ImageButton> getCurrentImageButtons()
          Returns an ArrayList of the ImageButton objects contained in the current Activity.
 ArrayList<android.widget.ImageView> getCurrentImageViews()
          Returns an ArrayList of the ImageView objects contained in the current Activity.
 ArrayList<android.widget.ListView> getCurrentListViews()
          Returns an ArrayList of the ListView objects contained in the current Activity.
 ArrayList<android.widget.ProgressBar> getCurrentProgressBars()
          Returns an ArrayList of the ProgressBar objects contained in the current Activity.
 ArrayList<android.widget.RadioButton> getCurrentRadioButtons()
          Returns an ArrayList of the RadioButton objects contained in the current Activity.
 ArrayList<android.widget.ScrollView> getCurrentScrollViews()
          Returns an ArrayList of the ScrollView objects contained in the current Activity.
 ArrayList<android.widget.Spinner> getCurrentSpinners()
          Returns an ArrayList of the Spinner objects (drop-down menus) contained in the current Activity.
 ArrayList<android.widget.TextView> getCurrentTextViews(android.view.View parent)
          Returns an ArrayList of the TextView objects contained in the current Activity or View.
 ArrayList<android.widget.TimePicker> getCurrentTimePickers()
          Returns an ArrayList of the TimePicker objects contained in the current Activity.
 ArrayList<android.widget.ToggleButton> getCurrentToggleButtons()
          Returns an ArrayList of the ToggleButton objects contained in the current Activity.
 android.widget.EditText getEditText(int index)
          Returns an EditText with a given index.
 android.widget.EditText getEditText(String text)
          Returns an EditText which shows a given text.
 android.widget.ImageView getImage(int index)
          Returns an ImageView with a given index.
 android.widget.ImageButton getImageButton(int index)
          Returns an ImageButton with a given index.
 String getString(int resId)
          Returns a localized string.
 android.widget.TextView getText(int index)
          Returns a TextView with a given index.
 android.widget.TextView getText(String text)
          Returns a TextView which shows a given text.
 android.view.View getTopParent(android.view.View view)
          Returns the absolute top parent View in for a given View.
 android.view.View getView(int id)
          Returns a View with a given id.
 ArrayList<android.view.View> getViews()
          Returns an ArrayList of the View objects located in the current Activity.
 ArrayList<android.view.View> getViews(android.view.View parent)
          Returns an ArrayList of the View objects contained in the parent view
 void goBack()
          Simulates pressing the hardware back key.
 void goBackToActivity(String name)
          Returns to the given Activity.
 boolean isCheckBoxChecked(int index)
          Checks if a CheckBox with a given index is checked.
 boolean isCheckBoxChecked(String text)
          Checks if a CheckBox with a given text is checked.
 boolean isRadioButtonChecked(int index)
          Checks if a RadioButton with a given index is checked.
 boolean isRadioButtonChecked(String text)
          Checks if a RadioButton with a given text is checked.
 boolean isSpinnerTextSelected(int index, String text)
          Checks if a given text is selected in a given Spinner.
 boolean isSpinnerTextSelected(String text)
          Checks if a given text is selected in any Spinner located on the current screen.
 boolean isTextChecked(String text)
          Checks if the given text is checked.
 boolean isToggleButtonChecked(int index)
          Checks if a ToggleButton with a given index is checked.
 boolean isToggleButtonChecked(String text)
          Checks if a ToggleButton with a given text is checked.
 void pressMenuItem(int index)
          Presses a MenuItem with a given index.
 void pressSpinnerItem(int spinnerIndex, int itemIndex)
          Presses on a Spinner (drop-down menu) item.
 boolean scrollDown()
          Scrolls down the screen.
 boolean scrollDownList(int listIndex)
          Scrolls down a list with a given listIndex.
 void scrollToSide(int side)
          Scrolls horizontally.
 boolean scrollUp()
          Scrolls up the screen.
 boolean scrollUpList(int listIndex)
          Scrolls up a list with a given listIndex.
 boolean searchButton(String text)
          Searches for a Button with the given text string and returns true if at least one Button is found.
 boolean searchButton(String text, boolean onlyVisible)
          Searches for a Button with the given text string and returns true if at least one Button is found.
 boolean searchButton(String text, int minimumNumberOfMatches)
          Searches for a Button with the given text string and returns true if the searched Button is found a given number of times.
 boolean searchButton(String text, int minimumNumberOfMatches, boolean onlyVisible)
          Searches for a Button with the given text string and returns true if the searched Button is found a given number of times.
 boolean searchEditText(String text)
          Searches for a text string in the EditText objects located in the current Activity.
 boolean searchText(String text)
          Searches for a text string and returns true if at least one item is found with the expected text.
 boolean searchText(String text, boolean onlyVisible)
          Searches for a text string and returns true if at least one item is found with the expected text.
 boolean searchText(String text, int minimumNumberOfMatches)
          Searches for a text string and returns true if the searched text is found a given number of times.
 boolean searchText(String text, int minimumNumberOfMatches, boolean scroll)
          Searches for a text string and returns true if the searched text is found a given number of times.
 boolean searchText(String text, int minimumNumberOfMatches, boolean scroll, boolean onlyVisible)
          Searches for a text string and returns true if the searched text is found a given number of times.
 boolean searchToggleButton(String text)
          Searches for a ToggleButton with the given text string and returns true if at least one ToggleButton is found.
 boolean searchToggleButton(String text, int minimumNumberOfMatches)
          Searches for a ToggleButton with the given text string and returns true if the searched ToggleButton is found a given number of times.
 void sendKey(int key)
          Tells Robotium to send a key: Right, Left, Up, Down, Enter, Menu, Delete, Call or End Call.
 void setActivityOrientation(int orientation)
          Sets the Orientation (Landscape/Portrait) for the current activity.
 void setDatePicker(android.widget.DatePicker datePicker, int year, int monthOfYear, int dayOfMonth)
          Sets the date in a given DatePicker.
 void setDatePicker(int index, int year, int monthOfYear, int dayOfMonth)
          Sets the date in a DatePicker with a given index.
 void setProgressBar(int index, int progress)
          Sets the progress of a ProgressBar with a given index.
 void setProgressBar(android.widget.ProgressBar progressBar, int progress)
          Sets the progress of a given ProgressBar.
 void setTimePicker(int index, int hour, int minute)
          Sets the time in a TimePicker with a given index.
 void setTimePicker(android.widget.TimePicker timePicker, int hour, int minute)
          Sets the time in a given TimePicker.
 void sleep(int time)
          Robotium will sleep for a specified time.
 boolean waitForActivity(String name, int timeout)
          Waits for the given Activity.
 boolean waitForDialogToClose(long timeout)
          Waits for a Dialog to close.
 boolean waitForText(String text)
          Waits for a text to be shown.
 boolean waitForText(String text, int minimumNumberOfMatches, long timeout)
          Waits for a text to be shown.
 boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll)
          Waits for a text to be shown.
<T extends android.view.View>
boolean
waitForView(Class<T> viewClass, int minimumNumberOfMatches, int timeout)
          Waits for a view to be shown.
<T extends android.view.View>
boolean
waitForView(Class<T> viewClass, int minimumNumberOfMatches, int timeout, boolean scroll)
          Waits for a view to be shown.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LANDSCAPE

public static final int LANDSCAPE
See Also:
Constant Field Values

PORTRAIT

public static final int PORTRAIT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

UP

public static final int UP
See Also:
Constant Field Values

DOWN

public static final int DOWN
See Also:
Constant Field Values

ENTER

public static final int ENTER
See Also:
Constant Field Values

MENU

public static final int MENU
See Also:
Constant Field Values

DELETE

public static final int DELETE
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 instance.
activity - Activity the start activity
Method Detail

getViews

public ArrayList<android.view.View> getViews()
Returns an ArrayList of the View objects located in the current Activity.

Returns:
an ArrayList of the View objects located in the current Activity

getViews

public ArrayList<android.view.View> getViews(android.view.View parent)
Returns an ArrayList of the View objects contained in the parent view

Parameters:
parent - the parent view from which to return the views
Returns:
an ArrayList of the View objects contained in the given View

getTopParent

public android.view.View getTopParent(android.view.View view)
Returns the absolute top parent View in for a given View.

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

clearEditText

public void clearEditText(int index)
Clears the value of an EditText.

Parameters:
index - the index of the EditText that should be cleared. 0 if only one is available

clearEditText

public void clearEditText(android.widget.EditText editText)
Clears the value of an EditText.

Parameters:
editText - the EditText that should be cleared

waitForText

public boolean waitForText(String text)
Waits for a text to be shown. Default timeout is 20 seconds.

Parameters:
text - the text that is expected to be shown
Returns:
true if text is shown and false if it is not shown before the timeout

waitForText

public boolean waitForText(String text,
                           int minimumNumberOfMatches,
                           long timeout)
Waits for a text to be shown.

Parameters:
text - the text that needs to be shown
minimumNumberOfMatches - the minimum number of matches that are expected to be shown. 0 means any number of matches
timeout - the the amount of time in milliseconds to wait
Returns:
true if text is shown and false if it is not shown before the timeout

waitForText

public boolean waitForText(String text,
                           int minimumNumberOfMatches,
                           long timeout,
                           boolean scroll)
Waits for a text to be shown.

Parameters:
text - the text that needs to be shown
minimumNumberOfMatches - the minimum number of matches that are expected to be shown. 0 means any number of matches
timeout - the the amount of time in milliseconds to wait
scroll - true if scrolling should be performed
Returns:
true if text is shown and false if it is not shown before the timeout

waitForView

public <T extends android.view.View> boolean waitForView(Class<T> viewClass,
                                                         int minimumNumberOfMatches,
                                                         int timeout)
Waits for a view to be shown.

Parameters:
viewClass - the View class to wait for
minimumNumberOfMatches - the minimum number of matches that are expected to be shown. 0 means any number of matches
timeout - the amount of time in milliseconds to wait
Returns:
true if view is shown and false if it is not shown before the timeout

waitForView

public <T extends android.view.View> boolean waitForView(Class<T> viewClass,
                                                         int minimumNumberOfMatches,
                                                         int timeout,
                                                         boolean scroll)
Waits for a view to be shown.

Parameters:
viewClass - the View class to wait for
minimumNumberOfMatches - the minimum number of matches that are expected to be shown. 0 means any number of matches
timeout - the amount of time in milliseconds to wait
scroll - true if scrolling should be performed
Returns:
true if view is shown and false if it is not shown before the timeout

searchEditText

public boolean searchEditText(String text)
Searches for a text string in the EditText objects located in the current Activity. Will automatically scroll when needed.

Parameters:
text - the text to search for
Returns:
true if an EditText with the given text is found or false if it is not found

searchButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
Returns:
true if a Button with the given text is found and false if it is not found

searchButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
onlyVisible - true if only Button visible on the screen should be searched
Returns:
true if a Button with the given text is found and false if it is not found

searchToggleButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
Returns:
true if a ToggleButton with the given text is found and false if it is not found

searchButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
minimumNumberOfMatches - the minimum 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

searchButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
minimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be found
onlyVisible - true if only Button visible on the screen should be searched
Returns:
true if a Button with the given text is found a given number of times and false if it is not found

searchToggleButton

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

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression
minimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be found
Returns:
true if a ToggleButton with the given text is found a given number of times and false if it is not found

searchText

public boolean searchText(String text)
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:
text - the text to search for. The parameter will be interpreted as a regular expression
Returns:
true if the search string is found and false if it is not found

searchText

public boolean searchText(String text,
                          boolean onlyVisible)
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:
text - the text to search for. The parameter will be interpreted as a regular expression
onlyVisible - true if only texts visible on the screen should be searched
Returns:
true if the search string is found and false if it is not found

searchText

public boolean searchText(String text,
                          int minimumNumberOfMatches)
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:
text - the text to search for. The parameter will be interpreted as a regular expression
minimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be found
Returns:
true if text string is found a given number of times and false if the text string is not found

searchText

public boolean searchText(String text,
                          int minimumNumberOfMatches,
                          boolean scroll)
Searches for a text string and returns true if the searched text is found a given number of times.

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression.
minimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be found
scroll - true if scrolling should be performed
Returns:
true if text string is found a given number of times and false if the text string is not found

searchText

public boolean searchText(String text,
                          int minimumNumberOfMatches,
                          boolean scroll,
                          boolean onlyVisible)
Searches for a text string and returns true if the searched text is found a given number of times.

Parameters:
text - the text to search for. The parameter will be interpreted as a regular expression.
minimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be found
scroll - true if scrolling should be performed
onlyVisible - true if only texts visible on the screen should be searched
Returns:
true if text string is found a given number of times and false if the text string is not found

setActivityOrientation

public void setActivityOrientation(int orientation)
Sets the Orientation (Landscape/Portrait) for the current activity.

Parameters:
orientation - the orientation to be set. Solo.LANDSCAPE for landscape or Solo.PORTRAIT for portrait.

getAllOpenedActivities

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

Returns:
an ArrayList of all the opened/active activities

getCurrentActivity

public android.app.Activity getCurrentActivity()
Returns the current Activity.

Returns:
the current Activity

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  String name)
Asserts that the expected Activity is the currently active one.

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)
Asserts that the expected Activity is the currently active one.

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)
Asserts that the expected Activity is the currently active one, 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)
Asserts that the expected Activity is the currently active one, 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

assertMemoryNotLow

public void assertMemoryNotLow()
Asserts that the available memory in the system is not low.


waitForDialogToClose

public boolean waitForDialogToClose(long timeout)
Waits for a Dialog to close.

Parameters:
timeout - the amount of time in milliseconds to wait
Returns:
true if the Dialog is closed before the timeout and false if it is not closed

goBack

public void goBack()
Simulates pressing the hardware back key.


clickOnScreen

public void clickOnScreen(float x,
                          float y)
Clicks on a given coordinate on the screen.

Parameters:
x - the x coordinate
y - the y coordinate

clickLongOnScreen

public void clickLongOnScreen(float x,
                              float y)
Long clicks a given coordinate on the screen.

Parameters:
x - the x coordinate
y - the y coordinate

clickLongOnScreen

public void clickLongOnScreen(float x,
                              float y,
                              int time)
Long clicks a given coordinate on the screen for a given amount of time.

Parameters:
x - the x coordinate
y - the y coordinate
time - the amount of time to long click

clickOnButton

public void clickOnButton(String name)
Clicks on a Button with a given text. Will automatically scroll when needed.

Parameters:
name - the name of the Button presented to the user. The parameter will be interpreted as a regular expression

clickOnImageButton

public void clickOnImageButton(int index)
Clicks on an ImageButton with a given index.

Parameters:
index - the index of the ImageButton to be clicked. 0 if only one is available

clickOnToggleButton

public void clickOnToggleButton(String name)
Clicks on a ToggleButton with a given text.

Parameters:
name - the name of the ToggleButton presented to the user. The parameter will be interpreted as a regular expression

clickOnMenuItem

public void clickOnMenuItem(String text)
Clicks on a menu item with a given text.

Parameters:
text - the menu text that should be clicked on. The parameter will be interpreted as a regular expression

clickOnMenuItem

public void clickOnMenuItem(String text,
                            boolean subMenu)
Clicks on a menu item with a given text.

Parameters:
text - the menu text that should be clicked on. The parameter will be interpreted as a regular expression
subMenu - true if the menu item could be located in a sub menu

pressMenuItem

public void pressMenuItem(int index)
Presses a MenuItem with a given index. Index 0 is the first item in the first row, Index 3 is the first item in the second row and index 5 is the first item in the third row.

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

pressSpinnerItem

public void pressSpinnerItem(int spinnerIndex,
                             int itemIndex)
Presses 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 relative to the currently selected item A Negative number moves up on the Spinner, positive moves down

clickOnView

public void clickOnView(android.view.View view)
Clicks on a given View.

Parameters:
view - the View that should be clicked

clickLongOnView

public void clickLongOnView(android.view.View view)
Long clicks on a given View.

Parameters:
view - the view that should be long clicked

clickLongOnView

public void clickLongOnView(android.view.View view,
                            int time)
Long clicks on a given View for a given amount of time.

Parameters:
view - the view that should be long clicked
time - the amount of time to long click

clickOnText

public void clickOnText(String text)
Clicks on a View displaying a given text. Will automatically scroll when needed.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression

clickOnText

public void clickOnText(String text,
                        int match)
Clicks on a View displaying a given text. Will automatically scroll when needed.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression
match - the match that should be clicked on

clickOnText

public void clickOnText(String text,
                        int match,
                        boolean scroll)
Clicks on a View displaying a given text.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression
match - the match that should be clicked on
scroll - true if scrolling should be performed

clickLongOnText

public void clickLongOnText(String text)
Long clicks on a given View. Will automatically scroll when needed. clickOnText(String) can then be used to click on the context menu items that appear after the long click.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression

clickLongOnText

public void clickLongOnText(String text,
                            int match)
Long clicks on a given View. Will automatically scroll when needed. clickOnText(String) can then be used to click on the context menu items that appear after the long click.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression
match - the match that should be clicked on

clickLongOnText

public void clickLongOnText(String text,
                            int match,
                            boolean scroll)
Long clicks on a given View. clickOnText(String) can then be used to click on the context menu items that appear after the long click.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression
match - the match that should be clicked on
scroll - true if scrolling should be performed

clickLongOnText

public void clickLongOnText(String text,
                            int match,
                            int time)
Long clicks on a given View. clickOnText(String) can then be used to click on the context menu items that appear after the long click.

Parameters:
text - the text that should be clicked on. The parameter will be interpreted as a regular expression
match - the match that should be clicked on
time - the amount of time to long click

clickLongOnTextAndPress

public void clickLongOnTextAndPress(String text,
                                    int index)
Long clicks on a given View and then selects an item from the context menu that appears. Will automatically scroll when needed.

Parameters:
text - the text to be clicked on. The parameter will be interpreted as a regular expression
index - the index of the menu item to be pressed. 0 if only one is available

clickOnButton

public void clickOnButton(int index)
Clicks on a Button with a given index.

Parameters:
index - the index number of the Button. 0 if only one is available

clickOnRadioButton

public void clickOnRadioButton(int index)
Clicks on a RadioButton with a given index.

Parameters:
index - the index of the RadioButton to be clicked. 0 if only one is available

clickOnCheckBox

public void clickOnCheckBox(int index)
Clicks on a CheckBox with a given index.

Parameters:
index - the index of the CheckBox to be clicked. 0 if only one is available

clickOnEditText

public void clickOnEditText(int index)
Clicks on an EditText with a given index.

Parameters:
index - the index of the EditText to be clicked. 0 if only one is available

clickInList

public ArrayList<android.widget.TextView> clickInList(int line)
Clicks on a given list line and returns an ArrayList of the TextView objects that the list line is showing. Will use the first list it finds.

Parameters:
line - the line that should be clicked
Returns:
an ArrayList of the TextView objects located in the list line

clickInList

public ArrayList<android.widget.TextView> clickInList(int line,
                                                      int listIndex)
Clicks on a given list line on a specified list and returns an ArrayList of the TextViews that the list line is showing.

Parameters:
line - the line that should be clicked
listIndex - the index of the list. 1 if two lists are available
Returns:
an ArrayList of the TextView objects located in the list line

drag

public void drag(float fromX,
                 float toX,
                 float fromY,
                 float toY,
                 int stepCount)
Simulate touching a given location and dragging it 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 - X coordinate 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

scrollDown

public boolean scrollDown()
Scrolls down the screen.

Returns:
true if more scrolling can be done and false if it is at the end of the screen

scrollUp

public boolean scrollUp()
Scrolls up the screen.

Returns:
true if more scrolling can be done and false if it is at the top of the screen

scrollDownList

public boolean scrollDownList(int listIndex)
Scrolls down a list with a given listIndex.

Parameters:
listIndex - the ListView to be scrolled. 0 if only one list is available
Returns:
true if more scrolling can be done

scrollUpList

public boolean scrollUpList(int listIndex)
Scrolls up a list with a given listIndex.

Parameters:
listIndex - the ListView to be scrolled. 0 if only one list is available
Returns:
true if more scrolling can be done

scrollToSide

public void scrollToSide(int side)
Scrolls horizontally.

Parameters:
side - the side to which to scroll; RIGHT or LEFT

setDatePicker

public void setDatePicker(int index,
                          int year,
                          int monthOfYear,
                          int dayOfMonth)
Sets the date in a DatePicker with a given index.

Parameters:
index - the index of the DatePicker. 0 if only one is available
year - the year e.g. 2011
monthOfYear - the month e.g. 03
dayOfMonth - the day e.g. 10

setDatePicker

public void setDatePicker(android.widget.DatePicker datePicker,
                          int year,
                          int monthOfYear,
                          int dayOfMonth)
Sets the date in a given DatePicker.

Parameters:
datePicker - the DatePicker object.
year - the year e.g. 2011
monthOfYear - the month e.g. 03
dayOfMonth - the day e.g. 10

setTimePicker

public void setTimePicker(int index,
                          int hour,
                          int minute)
Sets the time in a TimePicker with a given index.

Parameters:
index - the index of the TimePicker. 0 if only one is available
hour - the hour e.g. 15
minute - the minute e.g. 30

setTimePicker

public void setTimePicker(android.widget.TimePicker timePicker,
                          int hour,
                          int minute)
Sets the time in a given TimePicker.

Parameters:
timePicker - the TimePicker object.
hour - the hour e.g. 15
minute - the minute e.g. 30

setProgressBar

public void setProgressBar(int index,
                           int progress)
Sets the progress of a ProgressBar with a given index. Examples are SeekBar and RatingBar.

Parameters:
index - the index of the ProgressBar
progress - the progress that the ProgressBar should be set to

setProgressBar

public void setProgressBar(android.widget.ProgressBar progressBar,
                           int progress)
Sets the progress of a given ProgressBar. Examples are SeekBar and RatingBar.

Parameters:
progressBar - the ProgressBar
progress - the progress that the ProgressBar should be set to

enterText

public void enterText(int index,
                      String text)
Enters text into an EditText with a given index.

Parameters:
index - the index of the EditText. 0 if only one is available
text - the text string to enter into the EditText field

enterText

public void enterText(android.widget.EditText editText,
                      String text)
Enters text into a given EditText.

Parameters:
editText - the EditText to enter text into
text - the text string to enter into the EditText field

clickOnImage

public void clickOnImage(int index)
Clicks on an ImageView with a given index.

Parameters:
index - the index of the ImageView to be clicked. 0 if only one is available

getCurrentImageViews

public ArrayList<android.widget.ImageView> getCurrentImageViews()
Returns an ArrayList of the ImageView objects contained in the current Activity.

Returns:
an ArrayList of the ImageView objects contained in the current Activity

getEditText

public android.widget.EditText getEditText(int index)
Returns an EditText with a given index.

Parameters:
index - the index of the EditText. 0 if only one is available
Returns:
the EditText with a specified index or null if index is invalid

getButton

public android.widget.Button getButton(int index)
Returns a Button with a given index.

Parameters:
index - the index of the Button. 0 if only one is available
Returns:
the Button with a specified index or null if index is invalid

getText

public android.widget.TextView getText(int index)
Returns a TextView with a given index.

Parameters:
index - the index of the TextView. 0 if only one is available
Returns:
the TextView with a specified index or null if index is invalid

getImage

public android.widget.ImageView getImage(int index)
Returns an ImageView with a given index.

Parameters:
index - the index of the ImageView. 0 if only one is available
Returns:
the ImageView with a specified index or null if index is invalid

getImageButton

public android.widget.ImageButton getImageButton(int index)
Returns an ImageButton with a given index.

Parameters:
index - the index of the ImageButton. 0 if only one is available
Returns:
the ImageButton with a specified index or null if index is invalid

getText

public android.widget.TextView getText(String text)
Returns a TextView which shows a given text.

Parameters:
text - the text that is shown
Returns:
the TextView that shows the given text

getButton

public android.widget.Button getButton(String text)
Returns a Button which shows a given text.

Parameters:
text - the text that is shown
Returns:
the Button that shows the given text

getEditText

public android.widget.EditText getEditText(String text)
Returns an EditText which shows a given text.

Parameters:
text - the text that is shown
Returns:
the EditText which shows the given text

getView

public android.view.View getView(int id)
Returns a View with a given id.

Parameters:
id - the R.id of the View to be returned
Returns:
a View with a given id

getCurrentEditTexts

public ArrayList<android.widget.EditText> getCurrentEditTexts()
Returns an ArrayList of the EditText objects contained in the current Activity.

Returns:
an ArrayList of the EditText objects contained in the current Activity

getCurrentListViews

public ArrayList<android.widget.ListView> getCurrentListViews()
Returns an ArrayList of the ListView objects contained in the current Activity.

Returns:
an ArrayList of the ListView objects contained in the current Activity

getCurrentScrollViews

public ArrayList<android.widget.ScrollView> getCurrentScrollViews()
Returns an ArrayList of the ScrollView objects contained in the current Activity.

Returns:
an ArrayList of the ScrollView objects contained in the current Activity

getCurrentSpinners

public ArrayList<android.widget.Spinner> getCurrentSpinners()
Returns an ArrayList of the Spinner objects (drop-down menus) contained in the current Activity.

Returns:
an ArrayList of the Spinner objects (drop-down menus) contained in the current Activity

getCurrentTextViews

public ArrayList<android.widget.TextView> getCurrentTextViews(android.view.View parent)
Returns an ArrayList of the TextView objects contained in the current Activity or View.

Parameters:
parent - the parent View from which the TextView objects should be returned. null if all TextView objects from the current Activity should be returned
Returns:
an ArrayList of the TextView objects contained in the current Activity or View

getCurrentGridViews

public ArrayList<android.widget.GridView> getCurrentGridViews()
Returns an ArrayList of the GridView objects contained in the current Activity.

Returns:
an ArrayList of the GridView objects contained in the current Activity

getCurrentButtons

public ArrayList<android.widget.Button> getCurrentButtons()
Returns an ArrayList of the Button objects located in the current Activity.

Returns:
an ArrayList of the Button objects located in the current Activity

getCurrentToggleButtons

public ArrayList<android.widget.ToggleButton> getCurrentToggleButtons()
Returns an ArrayList of the ToggleButton objects contained in the current Activity.

Returns:
an ArrayList of the ToggleButton objects contained in the current Activity

getCurrentRadioButtons

public ArrayList<android.widget.RadioButton> getCurrentRadioButtons()
Returns an ArrayList of the RadioButton objects contained in the current Activity.

Returns:
an ArrayList of the RadioButton objects contained in the current Activity

getCurrentCheckBoxes

public ArrayList<android.widget.CheckBox> getCurrentCheckBoxes()
Returns an ArrayList of the CheckBox objects contained in the current Activity.

Returns:
an ArrayList of the CheckBox objects contained in the current Activity

getCurrentImageButtons

public ArrayList<android.widget.ImageButton> getCurrentImageButtons()
Returns an ArrayList of the ImageButton objects contained in the current Activity.

Returns:
an ArrayList of the ImageButton objects contained in the current Activity

getCurrentDatePickers

public ArrayList<android.widget.DatePicker> getCurrentDatePickers()
Returns an ArrayList of the DatePicker objects contained in the current Activity.

Returns:
an ArrayList of the DatePicker objects contained in the current Activity

getCurrentTimePickers

public ArrayList<android.widget.TimePicker> getCurrentTimePickers()
Returns an ArrayList of the TimePicker objects contained in the current Activity.

Returns:
an ArrayList of the TimePicker objects contained in the current Activity

getCurrentProgressBars

public ArrayList<android.widget.ProgressBar> getCurrentProgressBars()
Returns an ArrayList of the ProgressBar objects contained in the current Activity.

Returns:
an ArrayList of the ProgressBar objects contained in the current Activity

isRadioButtonChecked

public boolean isRadioButtonChecked(int index)
Checks if a RadioButton with a given index is checked.

Parameters:
index - of the RadioButton to check. 0 if only one is available
Returns:
true if RadioButton is checked and false if it is not checked

isRadioButtonChecked

public boolean isRadioButtonChecked(String text)
Checks if a RadioButton with a given text is checked.

Parameters:
text - the text that the RadioButton shows
Returns:
true if a RadioButton with the given text is checked and false if it is not checked

isCheckBoxChecked

public boolean isCheckBoxChecked(int index)
Checks if a CheckBox with a given index is checked.

Parameters:
index - of the CheckBox to check. 0 if only one is available
Returns:
true if CheckBox is checked and false if it is not checked

isToggleButtonChecked

public boolean isToggleButtonChecked(String text)
Checks if a ToggleButton with a given text is checked.

Parameters:
text - the text that the ToggleButton shows
Returns:
true if a ToggleButton with the given text is checked and false if it is not checked

isToggleButtonChecked

public boolean isToggleButtonChecked(int index)
Checks if a ToggleButton with a given index is checked.

Parameters:
index - of the ToggleButton to check. 0 if only one is available
Returns:
true if ToggleButton is checked and false if it is not checked

isCheckBoxChecked

public boolean isCheckBoxChecked(String text)
Checks if a CheckBox with a given text is checked.

Parameters:
text - the text that the CheckBox shows
Returns:
true if a CheckBox with the given text is checked and false if it is not checked

isTextChecked

public boolean isTextChecked(String text)
Checks if the given text is checked.

Parameters:
text - the text that the CheckedTextView or CompoundButton objects show
Returns:
true if the given text is checked and false if it is not checked

isSpinnerTextSelected

public boolean isSpinnerTextSelected(String text)
Checks if a given text is selected in any Spinner located on the current screen.

Parameters:
text - the text that is expected to be selected
Returns:
true if the given text is selected in any Spinner and false if it is not

isSpinnerTextSelected

public boolean isSpinnerTextSelected(int index,
                                     String text)
Checks if a given text is selected in a given Spinner.

Parameters:
index - the index of the spinner to check. 0 if only one spinner is available
text - the text that is expected to be selected
Returns:
true if the given text is selected in the given Spinner and false if it is not

sendKey

public void sendKey(int key)
Tells Robotium to send a key: Right, Left, Up, Down, Enter, Menu, Delete, Call or End Call.

Parameters:
key - the key to be sent. Use Solo.RIGHT, LEFT, UP, DOWN, ENTER, MENU, DELETE, #CALL, #ENDCALL

goBackToActivity

public void goBackToActivity(String name)
Returns to the given Activity.

Parameters:
name - the name of the Activity to return to, e.g. "MyActivity"

waitForActivity

public boolean waitForActivity(String name,
                               int timeout)
Waits for the given Activity.

Parameters:
name - the name of the Activity to wait for e.g. "MyActivity"
timeout - the amount of time in milliseconds to wait
Returns:
true if Activity appears before the timeout and false if it does not

getString

public String getString(int resId)
Returns a localized string.

Parameters:
resId - the resource ID for the string
Returns:
the localized string

sleep

public void sleep(int time)
Robotium will sleep for a specified time.

Parameters:
time - the time in milliseconds that Robotium should sleep

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.