com.jayway.android.robotium.solo
Class Solo

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

public class Solo
extends Object

Main class for development of Robotium tests. Robotium has full support for WebViews, 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, renasreda@gmail.com

Field Summary
protected  com.jayway.android.robotium.solo.ActivityUtils activityUtils
           
protected  com.jayway.android.robotium.solo.Asserter asserter
           
protected  com.jayway.android.robotium.solo.Checker checker
           
protected  com.jayway.android.robotium.solo.Clicker clicker
           
static int CLOSED
           
static int DELETE
           
protected  com.jayway.android.robotium.solo.DialogUtils dialogUtils
           
static int DOWN
           
static int ENTER
           
protected  com.jayway.android.robotium.solo.Getter getter
           
protected  android.app.Instrumentation instrumentation
           
static int LANDSCAPE
           
static int LEFT
           
static int MENU
           
static int OPENED
           
static int PORTRAIT
           
protected  com.jayway.android.robotium.solo.Presser presser
           
static int RIGHT
           
protected  com.jayway.android.robotium.solo.ScreenshotTaker screenshotTaker
           
protected  com.jayway.android.robotium.solo.Scroller scroller
           
protected  com.jayway.android.robotium.solo.Searcher searcher
           
protected  com.jayway.android.robotium.solo.Sender sender
           
protected  com.jayway.android.robotium.solo.Setter setter
           
protected  com.jayway.android.robotium.solo.Sleeper sleeper
           
static int SMALLTIMEOUT
           
protected  com.jayway.android.robotium.solo.TextEnterer textEnterer
           
static int TIMEOUT
           
static int UP
           
protected  com.jayway.android.robotium.solo.ViewFetcher viewFetcher
           
protected  com.jayway.android.robotium.solo.Waiter waiter
           
protected  com.jayway.android.robotium.solo.WebUtils webUtils
           
 
Constructor Summary
Solo(android.app.Instrumentation instrumentation)
          Constructor that takes in the instrumentation.
Solo(android.app.Instrumentation instrumentation, 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 is not considered low by the system.
 void clearEditText(android.widget.EditText editText)
          Clears the value of an EditText.
 void clearEditText(int index)
          Clears the value of an EditText.
 void clearTextInWebElement(By by)
          Clears text in a web element.
 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 index)
          Clicks on a given list line on a specified ListView and returns an ArrayList of the TextView objects that the list line is showing.
 ArrayList<android.widget.TextView> clickLongInList(int line)
          Long clicks on a given list line and returns an ArrayList of the TextView objects that the list line is showing.
 ArrayList<android.widget.TextView> clickLongInList(int line, int index)
          Long clicks on a given list line on a specified ListView and returns an ArrayList of the TextView objects that the list line is showing.
 ArrayList<android.widget.TextView> clickLongInList(int line, int index, int time)
          Long clicks on a given list line on a specified ListView and returns an ArrayList of the TextView objects 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 clickOnActionBarHomeButton()
          Clicks on an ActionBar Home/Up button.
 void clickOnActionBarItem(int resourceId)
          Clicks on an ActionBar item with a given resource id.
 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 MenuItem with a given text.
 void clickOnMenuItem(String text, boolean subMenu)
          Clicks on a MenuItem 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 clickOnView(android.view.View view, boolean immediately)
          Clicks on a given View.
 void clickOnWebElement(By by)
          Clicks on a WebElement.
 void clickOnWebElement(By by, int match)
          Clicks on a WebElement.
 void clickOnWebElement(By by, int match, boolean scroll)
          Clicks on a WebElement.
 void clickOnWebElement(WebElement webElement)
          Clicks on the given WebElement.
 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 in a given EditText.
 void enterText(int index, String text)
          Enters text in an EditText with a given index.
 void enterTextInWebElement(By by, String text)
          Enters text in a WebElement.
 void finalize()
          Finalizes the solo object and removes the ActivityMonitor.
 void finishOpenedActivities()
          The activities that are alive are finished.
 android.app.Instrumentation.ActivityMonitor getActivityMonitor()
          Returns the ActivityMonitor used by Robotium.
 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.widget.Button getButton(String text, boolean onlyVisible)
          Returns a Button which shows a given text.
 android.app.Activity getCurrentActivity()
          Returns the current Activity.
 ArrayList<android.view.View> getCurrentViews()
          Returns an ArrayList of the Views currently shown in the focused Activity or Dialog.
<T extends android.view.View>
ArrayList<T>
getCurrentViews(Class<T> classToFilterBy)
          Returns an ArrayList of Views of the specified Class located in the focused Activity or Dialog.
<T extends android.view.View>
ArrayList<T>
getCurrentViews(Class<T> classToFilterBy, android.view.View parent)
          Returns an ArrayList of Views of the specified Class located under the specified parent.
 ArrayList<WebElement> getCurrentWebElements()
          Returns an ArrayList of WebElements currently shown in the active WebView.
 ArrayList<WebElement> getCurrentWebElements(By by)
          Returns an ArrayList of WebElements of the specified By object currently shown in the active WebView.
 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.EditText getEditText(String text, boolean onlyVisible)
          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.widget.TextView getText(String text, boolean onlyVisible)
          Returns a TextView which shows a given text.
 android.view.View getTopParent(android.view.View view)
          Returns the absolute top parent View for a given View.
<T extends android.view.View>
T
getView(Class<T> viewClass, int index)
          Returns a View of a given class and index.
 android.view.View getView(int id)
          Returns a View with a given resource id.
 ArrayList<android.view.View> getViews()
          Returns an ArrayList of all the View objects located in the focused Activity or Dialog.
 ArrayList<android.view.View> getViews(android.view.View parent)
          Returns an ArrayList of the View objects contained in the parent View.
 WebElement getWebElement(By by, int index)
          Returns a WebElement with a given index
 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 in 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 pressMenuItem(int index, int itemsPerRow)
          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(android.widget.AbsListView list)
          Scrolls down a given ListView.
 boolean scrollDownList(int index)
          Scrolls down a ListView with a given index.
 boolean scrollListToBottom(android.widget.AbsListView list)
          Scrolls to the bottom of a given ListView.
 boolean scrollListToBottom(int index)
          Scrolls a ListView with a given index to the bottom.
 void scrollListToLine(android.widget.AbsListView absListView, int line)
          Scroll the given ListView to a given line.
 void scrollListToLine(int index, int line)
          Scroll a ListView with a given index to a given line.
 boolean scrollListToTop(android.widget.AbsListView list)
          Scrolls to the top of a given ListView.
 boolean scrollListToTop(int index)
          Scrolls a ListView with a given index to the top.
 void scrollToBottom()
          Scrolls to the bottom of the screen.
 void scrollToSide(int side)
          Scrolls horizontally.
 void scrollToTop()
          Scrolls to the top of the screen.
 boolean scrollUp()
          Scrolls up the screen.
 boolean scrollUpList(android.widget.AbsListView list)
          Scrolls up a given ListView.
 boolean scrollUpList(int index)
          Scrolls up a ListView with a given index.
 void scrollViewToSide(android.view.View view, int side)
          Scrolls a View horizontally.
 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 currently shown and returns true if found.
 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)
          Sends a key: Right, Left, Up, Down, Enter, Menu or Delete.
 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 setSlidingDrawer(int index, int status)
          Sets the status of a SlidingDrawer with a given index.
 void setSlidingDrawer(android.widget.SlidingDrawer slidingDrawer, int status)
          Sets the status of a given SlidingDrawer.
 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.
 void takeScreenshot()
          Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
 void takeScreenshot(String name)
          Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/".
 void takeScreenshot(String name, int quality)
          Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/".
 void typeText(android.widget.EditText editText, String text)
          Types text in a given EditText.
 void typeText(int index, String text)
          Types text in an EditText with a given index.
 void typeTextInWebElement(By by, String text)
          Types text in a WebElement.
 void typeTextInWebElement(By by, String text, int match)
          Types text in a WebElement.
 void typeTextInWebElement(WebElement webElement, String text)
          Types text in a WebElement.
 boolean waitForActivity(String name)
          Waits for the given Activity.
 boolean waitForActivity(String name, int timeout)
          Waits for the given Activity.
 boolean waitForCondition(Condition condition, int timeout)
          Waits for a condition to be satisfied.
 boolean waitForDialogToClose(long timeout)
          Waits for a Dialog to close.
 boolean waitForDialogToOpen(long timeout)
          Waits for a Dialog to open.
 boolean waitForFragmentById(int id)
          Waits for a Fragment with a given id to appear.
 boolean waitForFragmentById(int id, int timeout)
          Waits for a Fragment with a given id to appear.
 boolean waitForFragmentByTag(String tag)
          Waits for a Fragment with a given tag to appear.
 boolean waitForFragmentByTag(String tag, int timeout)
          Waits for a Fragment with a given tag to appear.
 boolean waitForLogMessage(String logMessage)
          Waits for a log message to appear.
 boolean waitForLogMessage(String logMessage, int timeout)
          Waits for a log message to appear.
 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.
 boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll, boolean onlyVisible)
          Waits for a text to be shown.
<T extends android.view.View>
boolean
waitForView(Class<T> viewClass)
          Waits for a View of a certain class to be shown.
<T extends android.view.View>
boolean
waitForView(Class<T> viewClass, int minimumNumberOfMatches, int timeout)
          Waits for a View of a certain class to be shown.
<T extends android.view.View>
boolean
waitForView(Class<T> viewClass, int minimumNumberOfMatches, int timeout, boolean scroll)
          Waits for a View of a certain class to be shown.
<T extends android.view.View>
boolean
waitForView(android.view.View view)
          Waits for a given View to be shown.
<T extends android.view.View>
boolean
waitForView(android.view.View view, int timeout, boolean scroll)
          Waits for a given View to be shown.
 void waitForWebElement(By by)
          Waits for a WebElement.
 void waitForWebElement(By by, int timeout, boolean scroll)
          Waits for a WebElement.
 void waitForWebElement(By by, int match, int timeout, boolean scroll)
          Waits for a WebElement.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

asserter

protected final com.jayway.android.robotium.solo.Asserter asserter

viewFetcher

protected final com.jayway.android.robotium.solo.ViewFetcher viewFetcher

checker

protected final com.jayway.android.robotium.solo.Checker checker

clicker

protected final com.jayway.android.robotium.solo.Clicker clicker

presser

protected final com.jayway.android.robotium.solo.Presser presser

searcher

protected final com.jayway.android.robotium.solo.Searcher searcher

activityUtils

protected final com.jayway.android.robotium.solo.ActivityUtils activityUtils

dialogUtils

protected final com.jayway.android.robotium.solo.DialogUtils dialogUtils

textEnterer

protected final com.jayway.android.robotium.solo.TextEnterer textEnterer

scroller

protected final com.jayway.android.robotium.solo.Scroller scroller

sleeper

protected final com.jayway.android.robotium.solo.Sleeper sleeper

waiter

protected final com.jayway.android.robotium.solo.Waiter waiter

setter

protected final com.jayway.android.robotium.solo.Setter setter

getter

protected final com.jayway.android.robotium.solo.Getter getter

webUtils

protected final com.jayway.android.robotium.solo.WebUtils webUtils

sender

protected final com.jayway.android.robotium.solo.Sender sender

screenshotTaker

protected final com.jayway.android.robotium.solo.ScreenshotTaker screenshotTaker

instrumentation

protected final android.app.Instrumentation instrumentation

TIMEOUT

public static final int TIMEOUT
See Also:
Constant Field Values

SMALLTIMEOUT

public static final int SMALLTIMEOUT
See Also:
Constant Field Values

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

CLOSED

public static final int CLOSED
See Also:
Constant Field Values

OPENED

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

Solo

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

Parameters:
instrumentation - the Instrumentation instance
activity - the start Activity or null if no start activity is provided

Solo

public Solo(android.app.Instrumentation instrumentation)
Constructor that takes in the instrumentation.

Parameters:
instrumentation - the Instrumentation instance
Method Detail

getActivityMonitor

public android.app.Instrumentation.ActivityMonitor getActivityMonitor()
Returns the ActivityMonitor used by Robotium.

Returns:
the ActivityMonitor used by Robotium

getViews

public ArrayList<android.view.View> getViews()
Returns an ArrayList of all the View objects located in the focused Activity or Dialog.

Returns:
an ArrayList of the View objects located in the focused window

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 for a given View.

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

waitForText

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

Parameters:
text - the text to wait for, specified as a regular expression
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 to wait for, specified as a regular expression
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 to wait for, specified as a regular expression
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

waitForText

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

Parameters:
text - the text to wait for, specified as a regular expression
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
onlyVisible - true if only visible text views should be waited for
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)
Waits for a View of a certain class to be shown. Default timeout is 20 seconds.

Parameters:
viewClass - the View class to wait for

waitForView

public <T extends android.view.View> boolean waitForView(android.view.View view)
Waits for a given View to be shown. Default timeout is 20 seconds.

Parameters:
view - the View object to wait for
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(android.view.View view,
                                                         int timeout,
                                                         boolean scroll)
Waits for a given View to be shown.

Parameters:
view - the View object to wait for
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

waitForView

public <T extends android.view.View> boolean waitForView(Class<T> viewClass,
                                                         int minimumNumberOfMatches,
                                                         int timeout)
Waits for a View of a certain class 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 of a certain class 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 the View is shown and false if it is not shown before the timeout

waitForWebElement

public void waitForWebElement(By by)
Waits for a WebElement. Default timeout is 20 seconds.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")

waitForWebElement

public void waitForWebElement(By by,
                              int timeout,
                              boolean scroll)
Waits for a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
timeout - the the amount of time in milliseconds to wait
scroll - true if scrolling should be performed

waitForWebElement

public void waitForWebElement(By by,
                              int match,
                              int timeout,
                              boolean scroll)
Waits for a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
match - if multiple objects match, this determines which one will be clicked
timeout - the the amount of time in milliseconds to wait
scroll - true if scrolling should be performed

waitForCondition

public boolean waitForCondition(Condition condition,
                                int timeout)
Waits for a condition to be satisfied.

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

searchEditText

public boolean searchEditText(String text)
Searches for a text string in the EditText objects currently shown and returns true if found. 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.

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 is not considered low by the system.


waitForDialogToOpen

public boolean waitForDialogToOpen(long timeout)
Waits for a Dialog to open.

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

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 MenuItem 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 MenuItem 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

clickOnWebElement

public void clickOnWebElement(WebElement webElement)
Clicks on the given WebElement.

Parameters:
webElement - the WebElement to click

clickOnWebElement

public void clickOnWebElement(By by)
Clicks on a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")

clickOnWebElement

public void clickOnWebElement(By by,
                              int match)
Clicks on a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
match - if multiple objects match, this determines which one will be clicked

clickOnWebElement

public void clickOnWebElement(By by,
                              int match,
                              boolean scroll)
Clicks on a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
match - if multiple objects match, this determines which one will be clicked
scroll - true if scrolling should be performed

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 6 is the first item in the third row.

Parameters:
index - the index of the MenuItem to be pressed

pressMenuItem

public void pressMenuItem(int index,
                          int itemsPerRow)
Presses a MenuItem with a given index. Supports three rows with a given amount of items. If itemsPerRow equals 5 then index 0 is the first item in the first row, index 5 is the first item in the second row and index 10 is the first item in the third row.

Parameters:
index - the index of the MenuItem to be pressed
itemsPerRow - the amount of menu items there are per row.

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 to be clicked

clickOnView

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

Parameters:
view - the View to be clicked
immediately - true if view is to be clicked without any wait

clickLongOnView

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

Parameters:
view - the View to 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 to 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 to be clicked. 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 to be clicked. The parameter will be interpreted as a regular expression
match - if multiple objects match the text, this determines which one will be clicked

clickOnText

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

Parameters:
text - the text to be clicked. The parameter will be interpreted as a regular expression
match - if multiple objects match the text, this determines which one will be clicked
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 to be clicked. 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 to be clicked. The parameter will be interpreted as a regular expression
match - if multiple objects match the text, this determines which one will be clicked

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 to be clicked. The parameter will be interpreted as a regular expression
match - if multiple objects match the text, this determines which one will be clicked
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 to be clicked. The parameter will be interpreted as a regular expression
match - if multiple objects match the text, this determines which one will be clicked
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. 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 of the Button to be clicked. 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 ListView it finds.

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

clickInList

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

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

clickLongInList

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

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

clickLongInList

public ArrayList<android.widget.TextView> clickLongInList(int line,
                                                          int index)
Long clicks on a given list line on a specified ListView and returns an ArrayList of the TextView objects that the list line is showing.

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

clickLongInList

public ArrayList<android.widget.TextView> clickLongInList(int line,
                                                          int index,
                                                          int time)
Long clicks on a given list line on a specified ListView and returns an ArrayList of the TextView objects that the list line is showing.

Parameters:
line - the line to be clicked
index - the index of the list. 1 if two lists are available
time - the amount of time to long click
Returns:
an ArrayList of the TextView objects located in the list line

clickOnActionBarItem

public void clickOnActionBarItem(int resourceId)
Clicks on an ActionBar item with a given resource id.

Parameters:
resourceId - the R.id of the ActionBar item

clickOnActionBarHomeButton

public void clickOnActionBarHomeButton()
Clicks on an ActionBar Home/Up button.


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

scrollToBottom

public void scrollToBottom()
Scrolls to the bottom 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

scrollToTop

public void scrollToTop()
Scrolls to the top of the screen.


scrollDownList

public boolean scrollDownList(android.widget.AbsListView list)
Scrolls down a given ListView.

Parameters:
list - the AbsListView to be scrolled
Returns:
true if more scrolling can be done

scrollListToBottom

public boolean scrollListToBottom(android.widget.AbsListView list)
Scrolls to the bottom of a given ListView.

Parameters:
list - the AbsListView to be scrolled
Returns:
true if more scrolling can be done

scrollUpList

public boolean scrollUpList(android.widget.AbsListView list)
Scrolls up a given ListView.

Parameters:
list - the AbsListView to be scrolled
Returns:
true if more scrolling can be done

scrollListToTop

public boolean scrollListToTop(android.widget.AbsListView list)
Scrolls to the top of a given ListView.

Parameters:
list - the AbsListView to be scrolled
Returns:
true if more scrolling can be done

scrollDownList

public boolean scrollDownList(int index)
Scrolls down a ListView with a given index.

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

scrollListToBottom

public boolean scrollListToBottom(int index)
Scrolls a ListView with a given index to the bottom.

Parameters:
index - 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 index)
Scrolls up a ListView with a given index.

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

scrollListToTop

public boolean scrollListToTop(int index)
Scrolls a ListView with a given index to the top.

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

scrollListToLine

public void scrollListToLine(android.widget.AbsListView absListView,
                             int line)
Scroll the given ListView to a given line.

Parameters:
absListView - the AbsListView to scroll
line - the line to scroll to

scrollListToLine

public void scrollListToLine(int index,
                             int line)
Scroll a ListView with a given index to a given line. g

Parameters:
index - the index of the AbsListView to scroll
line - the line to scroll to

scrollToSide

public void scrollToSide(int side)
Scrolls horizontally.

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

scrollViewToSide

public void scrollViewToSide(android.view.View view,
                             int side)
Scrolls a View horizontally.

Parameters:
view - the View to scroll
side - the side 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 which starts from zero e.g. 0 for January
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 which starts from zero e.g. 03 for April
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

setSlidingDrawer

public void setSlidingDrawer(int index,
                             int status)
Sets the status of a SlidingDrawer with a given index. Examples are Solo.CLOSED and Solo.OPENED.

Parameters:
index - the index of the SlidingDrawer
status - the status that the SlidingDrawer should be set to

setSlidingDrawer

public void setSlidingDrawer(android.widget.SlidingDrawer slidingDrawer,
                             int status)
Sets the status of a given SlidingDrawer. Examples are Solo.CLOSED and Solo.OPENED.

Parameters:
slidingDrawer - the SlidingDrawer
status - the status that the SlidingDrawer should be set to

enterText

public void enterText(int index,
                      String text)
Enters text in 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 in a given EditText.

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

enterTextInWebElement

public void enterTextInWebElement(By by,
                                  String text)
Enters text in a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
text - the text to enter

typeText

public void typeText(int index,
                     String text)
Types text in an EditText with a given index.

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

typeText

public void typeText(android.widget.EditText editText,
                     String text)
Types text in a given EditText.

Parameters:
editText - the EditText to type text in
text - the text string to type in the EditText field

typeTextInWebElement

public void typeTextInWebElement(By by,
                                 String text)
Types text in a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
text - the text to enter

typeTextInWebElement

public void typeTextInWebElement(By by,
                                 String text,
                                 int match)
Types text in a WebElement.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
text - the text to enter
match - if multiple objects match, this determines which one will be typed in

typeTextInWebElement

public void typeTextInWebElement(WebElement webElement,
                                 String text)
Types text in a WebElement.

Parameters:
webElement - the WebElement to type text in
text - the text to enter

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

clearTextInWebElement

public void clearTextInWebElement(By by)
Clears text in a web element.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")

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

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, specified as a regular expression
Returns:
the TextView that shows the given text

getText

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

Parameters:
text - the text that is shown, specified as a regular expression
onlyVisible - true if only visible texts on the screen should be returned
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, specified as a regular expression
Returns:
the Button that shows the given text

getButton

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

Parameters:
text - the text that is shown, specified as a regular expression
onlyVisible - true if only visible buttons on the screen should be returned
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, specified as a regular expression
Returns:
the EditText which shows the given text

getEditText

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

Parameters:
text - the text that is shown, specified as a regular expression
onlyVisible - true if only visible EditTexts on the screen should be returned
Returns:
the EditText which shows the given text

getView

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

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

getView

public <T extends android.view.View> T getView(Class<T> viewClass,
                                               int index)
Returns a View of a given class and index.

Parameters:
viewClass - the class of the requested view
index - the index of the View. 0 if only one is available
Returns:
a View with a given class and index

getWebElement

public WebElement getWebElement(By by,
                                int index)
Returns a WebElement with a given index

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
index - the index of the WebElement. 0 if only one is available

getCurrentViews

public ArrayList<android.view.View> getCurrentViews()
Returns an ArrayList of the Views currently shown in the focused Activity or Dialog.

Returns:
an ArrayList of the View objects currently shown in the focused window

getCurrentViews

public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T> classToFilterBy)
Returns an ArrayList of Views of the specified Class located in the focused Activity or Dialog.

Parameters:
classToFilterBy - return all instances of this class. Examples are Button.class or ListView.class
Returns:
an ArrayList of Views of the specified Class located in the current Activity

getCurrentViews

public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T> classToFilterBy,
                                                                  android.view.View parent)
Returns an ArrayList of Views of the specified Class located under the specified parent.

Parameters:
classToFilterBy - return all instances of this class. Examples are Button.class or ListView.class
parent - the parent View for where to start the traversal
Returns:
an ArrayList of Views of the specified Class located under the specified parent

getCurrentWebElements

public ArrayList<WebElement> getCurrentWebElements()
Returns an ArrayList of WebElements currently shown in the active WebView.

Returns:
an ArrayList of the WebElement objects currently shown in the active WebView

getCurrentWebElements

public ArrayList<WebElement> getCurrentWebElements(By by)
Returns an ArrayList of WebElements of the specified By object currently shown in the active WebView.

Parameters:
by - the By object. Examples are By.id("id") and By.name("name")
Returns:
an ArrayList of the WebElement objects currently shown in the active WebView

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, specified as a regular expression
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, specified as a regular expression
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, specified as a regular expression
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, specified as a regular expression
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 in the current screen.

Parameters:
text - the text that is expected to be selected, specified as a regular expression
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, specified as a regular expression
Returns:
true if the given text is selected in the given Spinner and false if it is not

sendKey

public void sendKey(int key)
Sends a key: Right, Left, Up, Down, Enter, Menu or Delete.

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

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)
Waits for the given Activity. Default timeout is 20 seconds.

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

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

waitForFragmentByTag

public boolean waitForFragmentByTag(String tag)
Waits for a Fragment with a given tag to appear. Default timeout is 20 seconds.

Parameters:
tag - the name of the tag
Returns:
true if fragment appears and false if it does not appear before the timeout

waitForFragmentByTag

public boolean waitForFragmentByTag(String tag,
                                    int timeout)
Waits for a Fragment with a given tag to appear.

Parameters:
tag - the name of the tag
timeout - the amount of time in milliseconds to wait
Returns:
true if fragment appears and false if it does not appear before the timeout

waitForFragmentById

public boolean waitForFragmentById(int id)
Waits for a Fragment with a given id to appear. Default timeout is 20 seconds.

Parameters:
id - the id of the fragment
Returns:
true if fragment appears and false if it does not appear before the timeout

waitForFragmentById

public boolean waitForFragmentById(int id,
                                   int timeout)
Waits for a Fragment with a given id to appear.

Parameters:
id - the id of the fragment
timeout - the amount of time in milliseconds to wait
Returns:
true if fragment appears and false if it does not appear before the timeout

waitForLogMessage

public boolean waitForLogMessage(String logMessage)
Waits for a log message to appear. Default timeout is 20 seconds. Requires read logs permission (android.permission.READ_LOGS) in AndroidManifest.xml of the application under test.

Parameters:
logMessage - the log message to wait for
Returns:
true if log message appears and false if it does not appear before the timeout

waitForLogMessage

public boolean waitForLogMessage(String logMessage,
                                 int timeout)
Waits for a log message to appear. Requires read logs permission (android.permission.READ_LOGS) in AndroidManifest.xml of the application under test.

Parameters:
logMessage - the log message to wait for
timeout - the amount of time in milliseconds to wait
Returns:
true if log message appears and false if it does not appear before the timeout

getString

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

Parameters:
resId - the resource id of 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
Finalizes the solo object and removes the ActivityMonitor.

Overrides:
finalize in class Object
Throws:
Throwable
See Also:
finishOpenedActivities() to close the activities that have been active.

finishOpenedActivities

public void finishOpenedActivities()
The activities that are alive are finished. Usually used in tearDown().


takeScreenshot

public void takeScreenshot()
Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.


takeScreenshot

public void takeScreenshot(String name)
Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.

Parameters:
name - the name to give the screenshot

takeScreenshot

public void takeScreenshot(String name,
                           int quality)
Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.

Parameters:
name - the name to give the screenshot
quality - the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality).


Copyright © 2009-2013. All Rights Reserved.