Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 自動化測試(5)(robotium)

Android 自動化測試(5)(robotium)

編輯:關於Android編程

關於Android的自動化測試之UI測試,之前介紹過Android 自動化測試(4), 在android原生的單元測試框架上,利用uiautomator.jar這個類庫來完成Android的界面上的測試,這已經使得測試比較簡單了。但還有更加簡單的寫測試的方式,那就是利用一些第三方的測試框架,比如robotium。

Android的第三方的測試框架,有Robolectric 和 robotium,我試著用了下,覺得robotium已經非常好用了。

1、概要
Robotium是一款國外的Android自動化測試框架,它提供了模擬各種手勢操作(點擊、長按、滑動等)、查找和斷言機制的API,能夠對各種控件進行操作。Robotium結合Android官方提供的測試框架,做了一些封裝,達到對簡化應用程序進行自動化的測試的目的。
Robotium provides the following benefits:
Test Android apps, both native and hybrid. 測試安卓應用,native的和hybrid的都支持。
Requires minimal knowledge of the application under test. 需要很少的應用測試的知識
The framework handles multiple Android activities automatically. 框架能自動的支持多個安卓Activities
Minimal time needed to write solid test cases. 花較少的時間就可以寫比較可靠的測試Case
Readability of test cases is greatly improved, compared to standard instrumentation tests. 對比標准的測試,測試Case的可讀性大大提高。
Test cases are more robust due to the run-time binding to UI components. 由於run-time 綁定到了UI不見, 測試Case更加魯棒了。
Fast test case execution. 快速的測試Case的執行
Integrates smoothly with Maven, Gradle or Ant to run tests as part of continuous integration. 和Mave,Gradle,Ant等平滑的集成,跑單元測試,成為持續集成的一個部分。

入門教程和簡單工程搭建見Robotium環境搭建與新手入門教程。 代碼下載見http://download.csdn.net/detail/vshuang/8053865

2、核心類介紹:
最核心的類,如之前的所述,當屬控件的搜索和控制。com.robotium.solo.Solo 當然不讓地成為 Robotium框架的核心。
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):

以下是摘自robotium-solo-5.2.1-javadoc

Author:
Renas Reda, [email protected]


Field Detail

asserter

protected final com.robotium.solo.Asserter asserter

viewFetcher

protected final com.robotium.solo.ViewFetcher viewFetcher

checker

protected final com.robotium.solo.Checker checker

clicker

protected final com.robotium.solo.Clicker clicker

presser

protected final com.robotium.solo.Presser presser

searcher

protected final com.robotium.solo.Searcher searcher

activityUtils

protected final com.robotium.solo.ActivityUtils activityUtils

dialogUtils

protected final com.robotium.solo.DialogUtils dialogUtils

textEnterer

protected final com.robotium.solo.TextEnterer textEnterer

rotator

protected final com.robotium.solo.Rotator rotator

scroller

protected final com.robotium.solo.Scroller scroller

sleeper

protected final com.robotium.solo.Sleeper sleeper

swiper

protected final com.robotium.solo.Swiper swiper

tapper

protected final com.robotium.solo.Tapper tapper

waiter

protected final com.robotium.solo.Waiter waiter

setter

protected final com.robotium.solo.Setter setter

getter

protected final com.robotium.solo.Getter getter

webUtils

protected final com.robotium.solo.WebUtils webUtils

sender

protected final com.robotium.solo.Sender sender

screenshotTaker

protected final com.robotium.solo.ScreenshotTaker screenshotTaker

instrumentation

protected final android.app.Instrumentation instrumentation

zoomer

protected final com.robotium.solo.Zoomer zoomer

webUrl

protected String webUrl

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 the Instrumentation object and the start Activity.

Parameters:instrumentation - the Instrumentation instanceactivity - the start Activity or null if no Activity is specified

Solo

public Solo(android.app.Instrumentation instrumentation,
            Solo.Config config)
Constructor that takes the Instrumentation and Config objects.

Parameters:instrumentation - the Instrumentation instanceconfig - the Solo.Config instance

Solo

public Solo(android.app.Instrumentation instrumentation,
            Solo.Config config,
            android.app.Activity activity)
Constructor that takes the Instrumentation, Config and Activity objects.

Parameters:instrumentation - the Instrumentation instanceconfig - the Solo.Config instanceactivity - the start Activity or null if no Activity is specified

Solo

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

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

getConfig

public Solo.Config getConfig()
Returns the Config used by Robotium.

Returns:the Config used by Robotium

getViews

public ArrayList 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 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 viewsReturns:an ArrayList of the View objects contained in the specified View

getTopParent

public android.view.View getTopParent(android.view.View view)
Returns the absolute top parent View of the specified View.

Parameters:view - the View whose top parent is requestedReturns:the top parent View

waitForText

public boolean waitForText(String text)
Waits for the specified text to appear. Default timeout is 20 seconds.

Parameters:text - the text to wait for, specified as a regular expressionReturns:true if text is displayed and false if it is not displayed before the timeout

waitForText

public boolean waitForText(String text,
                           int minimumNumberOfMatches,
                           long timeout)
Waits for the specified text to appear.

Parameters:text - the text to wait for, specified as a regular expressionminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the the amount of time in milliseconds to waitReturns:true if text is displayed and false if it is not displayed before the timeout

waitForText

public boolean waitForText(String text,
                           int minimumNumberOfMatches,
                           long timeout,
                           boolean scroll)
Waits for the specified text to appear.

Parameters:text - the text to wait for, specified as a regular expressionminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if text is displayed and false if it is not displayed before the timeout

waitForText

public boolean waitForText(String text,
                           int minimumNumberOfMatches,
                           long timeout,
                           boolean scroll,
                           boolean onlyVisible)
Waits for the specified text to appear.

Parameters:text - the text to wait for, specified as a regular expressionminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the the amount of time in milliseconds to waitscroll - true if scrolling should be performedonlyVisible - true if only visible text views should be waited forReturns:true if text is displayed and false if it is not displayed before the timeout

waitForView

public boolean waitForView(int id)
Waits for a View matching the specified resource id. Default timeout is 20 seconds.

Parameters:id - the R.id of the View to wait forReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public boolean waitForView(int id,
                           int minimumNumberOfMatches,
                           int timeout)
Waits for a View matching the specified resource id.

Parameters:id - the R.id of the View to wait forminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the amount of time in milliseconds to waitReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public boolean waitForView(int id,
                           int minimumNumberOfMatches,
                           int timeout,
                           boolean scroll)
Waits for a View matching the specified resource id.

Parameters:id - the R.id of the View to wait forminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public  boolean waitForView(Class viewClass)
Waits for a View matching the specified class. Default timeout is 20 seconds.

Parameters:viewClass - the View class to wait forReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public  boolean waitForView(android.view.View view)
Waits for the specified View. Default timeout is 20 seconds.

Parameters:view - the View object to wait forReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public  boolean waitForView(android.view.View view,
                                                         int timeout,
                                                         boolean scroll)
Waits for the specified View.

Parameters:view - the View object to wait fortimeout - the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public  boolean waitForView(Class viewClass,
                                                         int minimumNumberOfMatches,
                                                         int timeout)
Waits for a View matching the specified class.

Parameters:viewClass - the View class to wait forminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the amount of time in milliseconds to waitReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForView

public  boolean waitForView(Class viewClass,
                                                         int minimumNumberOfMatches,
                                                         int timeout,
                                                         boolean scroll)
Waits for a View matching the specified class.

Parameters:viewClass - the View class to wait forminimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if the View is displayed and false if it is not displayed before the timeout

waitForWebElement

public boolean waitForWebElement(By by)
Waits for a WebElement matching the specified By object. Default timeout is 20 seconds.

Parameters:by - the By object. Examples are: By.id("id") and By.name("name")Returns:true if the WebElement is displayed and false if it is not displayed before the timeout

waitForWebElement

public boolean waitForWebElement(By by,
                                 int timeout,
                                 boolean scroll)
Waits for a WebElement matching the specified By object.

Parameters:by - the By object. Examples are: By.id("id") and By.name("name")timeout - the the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if the WebElement is displayed and false if it is not displayed before the timeout

waitForWebElement

public boolean waitForWebElement(By by,
                                 int minimumNumberOfMatches,
                                 int timeout,
                                 boolean scroll)
Waits for a WebElement matching the specified By object.

Parameters:by - the By object. Examples are: By.id("id") and By.name("name")minimumNumberOfMatches - the minimum number of matches that are expected to be found. 0 means any number of matchestimeout - the the amount of time in milliseconds to waitscroll - true if scrolling should be performedReturns:true if the WebElement is displayed and false if it is not displayed before the timeout

waitForCondition

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

Parameters:condition - the condition to wait fortimeout - the amount of time in milliseconds to waitReturns: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 in the EditText objects currently displayed and returns true if found. Will automatically scroll when needed.

Parameters:text - the text to search forReturns:true if an EditText displaying the specified text is found or false if it is not found

searchButton

public boolean searchButton(String text)
Searches for a Button displaying the specified text 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 expressionReturns:true if a Button displaying the specified text is found and false if it is not found

searchButton

public boolean searchButton(String text,
                            boolean onlyVisible)
Searches for a Button displaying the specified text 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 expressiononlyVisible - true if only Button visible on the screen should be searchedReturns:true if a Button displaying the specified text is found and false if it is not found

searchToggleButton

public boolean searchToggleButton(String text)
Searches for a ToggleButton displaying the specified text 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 expressionReturns:true if a ToggleButton displaying the specified text is found and false if it is not found

searchButton

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

Parameters:text - the text to search for. The parameter will be interpreted as a regular expressionminimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be foundReturns:true if a Button displaying the specified text is found a specified number of times and false if it is not found

searchButton

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

Parameters:text - the text to search for. The parameter will be interpreted as a regular expressionminimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be foundonlyVisible - true if only Button visible on the screen should be searchedReturns:true if a Button displaying the specified text is found a specified number of times and false if it is not found

searchToggleButton

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

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

searchText

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

Parameters:text - the text to search for. The parameter will be interpreted as a regular expressionReturns:true if the search string is found and false if it is not found

searchText

public boolean searchText(String text,
                          boolean onlyVisible)
Searches for the specified text and returns true if at least one item is found displaying the expected text. Will automatically scroll when needed.

Parameters:text - the text to search for. The parameter will be interpreted as a regular expressiononlyVisible - true if only texts visible on the screen should be searchedReturns:true if the search string is found and false if it is not found

searchText

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

Parameters:text - the text to search for. The parameter will be interpreted as a regular expressionminimumNumberOfMatches - the minimum number of matches expected to be found. 0 matches means that one or more matches are expected to be foundReturns:true if text is found a specified number of times and false if the text is not found

searchText

public boolean searchText(String text,
                          int minimumNumberOfMatches,
                          boolean scroll)
Searches for the specified text and returns true if the searched text is found a specified 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 foundscroll - true if scrolling should be performedReturns:true if text is found a specified number of times and false if the text is not found

searchText

public boolean searchText(String text,
                          int minimumNumberOfMatches,
                          boolean scroll,
                          boolean onlyVisible)
Searches for the specified text and returns true if the searched text is found a specified 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 foundscroll - true if scrolling should be performedonlyVisible - true if only texts visible on the screen should be searchedReturns:true if text is found a specified number of times and false if the text is not found

setActivityOrientation

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

Parameters:orientation - the orientation to 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 Activity matching the specified name is active.

Parameters:message - the message to display if the assert failsname - the name of the Activity that is expected to be active. Example is: "MyActivity"

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  Class activityClass)
Asserts that the Activity matching the specified class is active.

Parameters:message - the message to display if the assert failsactivityClass - the class of the Activity that is expected to be active. Example is: MyActivity.class

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  String name,
                                  boolean isNewInstance)
Asserts that the Activity matching the specified name is active, with the possibility to verify that the expected Activity is a new instance of the Activity.

Parameters:message - the message to display if the assert failsname - the name of the Activity that is expected to be active. Example is: "MyActivity"isNewInstance - true if the expected Activity is a new instance of the Activity

assertCurrentActivity

public void assertCurrentActivity(String message,
                                  Class activityClass,
                                  boolean isNewInstance)
Asserts that the Activity matching the specified class is active, with the possibility to verify that the expected Activity is a new instance of the Activity.

Parameters:message - the message to display if the assert failsactivityClass - the class of the Activity that is expected to be active. Example is: MyActivity.classisNewInstance - 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()
Waits for a Dialog to open. Default timeout is 20 seconds.

Returns:true if the Dialog is opened before the timeout and false if it is not opened

waitForDialogToClose

public boolean waitForDialogToClose()
Waits for a Dialog to close. Default timeout is 20 seconds.

Returns:true if the Dialog is closed before the timeout and false if it is not closed

waitForDialogToOpen

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

Parameters:timeout - the amount of time in milliseconds to waitReturns: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 waitReturns: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 the specified coordinates.

Parameters:x - the x coordinatey - the y coordinate

clickOnScreen

public void clickOnScreen(float x,
                          float y,
                          int numberOfClicks)
Clicks the specified coordinates rapidly a specified number of times. Requires API level >= 14.

Parameters:x - the x coordinatey - the y coordinatenumberOfClicks - the number of clicks to perform

clickLongOnScreen

public void clickLongOnScreen(float x,
                              float y)
Long clicks the specified coordinates.

Parameters:x - the x coordinatey - the y coordinate

clickLongOnScreen

public void clickLongOnScreen(float x,
                              float y,
                              int time)
Long clicks the specified coordinates for a specified amount of time.

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

clickOnButton

public void clickOnButton(String text)
Clicks a Button displaying the specified text. Will automatically scroll when needed.

Parameters:text - the text displayed by the Button. The parameter will be interpreted as a regular expression

clickOnImageButton

public void clickOnImageButton(int index)
Clicks an ImageButton matching the specified index.

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

clickOnToggleButton

public void clickOnToggleButton(String text)
Clicks a ToggleButton displaying the specified text.

Parameters:text - the text displayed by the ToggleButton. The parameter will be interpreted as a regular expression

clickOnMenuItem

public void clickOnMenuItem(String text)
Clicks a MenuItem displaying the specified text.

Parameters:text - the text displayed by the MenuItem. The parameter will be interpreted as a regular expression

clickOnMenuItem

public void clickOnMenuItem(String text,
                            boolean subMenu)
Clicks a MenuItem displaying the specified text.

Parameters:text - the text displayed by the MenuItem. The parameter will be interpreted as a regular expressionsubMenu - true if the menu item could be located in a sub menu

clickOnWebElement

public void clickOnWebElement(WebElement webElement)
Clicks the specified WebElement.

Parameters:webElement - the WebElement to click

clickOnWebElement

public void clickOnWebElement(By by)
Clicks a WebElement matching the specified By object.

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

clickOnWebElement

public void clickOnWebElement(By by,
                              int match)
Clicks a WebElement matching the specified By object.

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

clickOnWebElement

public void clickOnWebElement(By by,
                              int match,
                              boolean scroll)
Clicks a WebElement matching the specified By object.

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

pressMenuItem

public void pressMenuItem(int index)
Presses a MenuItem matching the specified 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 press

pressMenuItem

public void pressMenuItem(int index,
                          int itemsPerRow)
Presses a MenuItem matching the specified index. Supports three rows with a specified 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 pressitemsPerRow - the amount of menu items there are per row

pressSoftKeyboardNextButton

public void pressSoftKeyboardNextButton()
Presses the soft keyboard next button.


pressSoftKeyboardSearchButton

public void pressSoftKeyboardSearchButton()
Presses the soft keyboard search button.


pressSpinnerItem

public void pressSpinnerItem(int spinnerIndex,
                             int itemIndex)
Presses a Spinner (drop-down menu) item.

Parameters:spinnerIndex - the index of the Spinner menu to useitemIndex - the index of the Spinner item to press 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 the specified View.

Parameters:view - the View to click

clickOnView

public void clickOnView(android.view.View view,
                        boolean immediately)
Clicks the specified View.

Parameters:view - the View to clickimmediately - true if View should be clicked without any wait

clickLongOnView

public void clickLongOnView(android.view.View view)
Long clicks the specified View.

Parameters:view - the View to long click

clickLongOnView

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

Parameters:view - the View to long clicktime - the amount of time to long click

clickOnText

public void clickOnText(String text)
Clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.

Parameters:text - the text to click. The parameter will be interpreted as a regular expression

clickOnText

public void clickOnText(String text,
                        int match)
Clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionmatch - if multiple objects match the text, this determines which one to click

clickOnText

public void clickOnText(String text,
                        int match,
                        boolean scroll)
Clicks a View or WebElement displaying the specified text.

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionmatch - if multiple objects match the text, this determines which one to clickscroll - true if scrolling should be performed

clickLongOnText

public void clickLongOnText(String text)
Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.

Parameters:text - the text to click. The parameter will be interpreted as a regular expression

clickLongOnText

public void clickLongOnText(String text,
                            int match)
Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionmatch - if multiple objects match the text, this determines which one to click

clickLongOnText

public void clickLongOnText(String text,
                            int match,
                            boolean scroll)
Long clicks a View or WebElement displaying the specified text.

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionmatch - if multiple objects match the text, this determines which one to clickscroll - true if scrolling should be performed

clickLongOnText

public void clickLongOnText(String text,
                            int match,
                            int time)
Long clicks a View or WebElement displaying the specified text.

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionmatch - if multiple objects match the text, this determines which one to clicktime - the amount of time to long click

clickLongOnTextAndPress

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

Parameters:text - the text to click. The parameter will be interpreted as a regular expressionindex - the index of the menu item to press. 0 if only one is available

clickOnButton

public void clickOnButton(int index)
Clicks a Button matching the specified index.

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

clickOnRadioButton

public void clickOnRadioButton(int index)
Clicks a RadioButton matching the specified index.

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

clickOnCheckBox

public void clickOnCheckBox(int index)
Clicks a CheckBox matching the specified index.

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

clickOnEditText

public void clickOnEditText(int index)
Clicks an EditText matching the specified index.

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

clickInList

public ArrayList clickInList(int line)
Clicks the specified list line and returns an ArrayList of the TextView objects that the list line is displaying. Will use the first ListView it finds.

Parameters:line - the line to clickReturns:an ArrayList of the TextView objects located in the list line

clickInList

public ArrayList clickInList(int line,
                                                      int index)
Clicks the specified list line in the ListView matching the specified index and returns an ArrayList of the TextView objects that the list line is displaying.

Parameters:line - the line to clickindex - the index of the list. 0 if only one is availableReturns:an ArrayList of the TextView objects located in the list line

clickLongInList

public ArrayList clickLongInList(int line)
Long clicks the specified list line and returns an ArrayList of the TextView objects that the list line is displaying. Will use the first ListView it finds.

Parameters:line - the line to clickReturns:an ArrayList of the TextView objects located in the list line

clickLongInList

public ArrayList clickLongInList(int line,
                                                          int index)
Long clicks the specified list line in the ListView matching the specified index and returns an ArrayList of the TextView objects that the list line is displaying.

Parameters:line - the line to clickindex - the index of the list. 0 if only one is availableReturns:an ArrayList of the TextView objects located in the list line

clickLongInList

public ArrayList clickLongInList(int line,
                                                          int index,
                                                          int time)
Long clicks the specified list line in the ListView matching the specified index and returns an ArrayList of the TextView objects that the list line is displaying.

Parameters:line - the line to clickindex - the index of the list. 0 if only one is availabletime - the amount of time to long clickReturns:an ArrayList of the TextView objects located in the list line

clickOnActionBarItem

public void clickOnActionBarItem(int id)
Clicks an ActionBarItem matching the specified resource id.

Parameters:id - the R.id of the ActionBar item to click

clickOnActionBarHomeButton

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


drag

public void drag(float fromX,
                 float toX,
                 float fromY,
                 float toY,
                 int stepCount)
Simulate touching the specified location and dragging it to a new location.

Parameters:fromX - X coordinate of the initial touch, in screen coordinatestoX - X coordinate of the drag destination, in screen coordinatesfromY - Y coordinate of the initial touch, in screen coordinatestoY - Y coordinate of the drag destination, in screen coordinatesstepCount - how many move steps to include in the drag. Less steps results in a faster drag

scrollDown

public boolean scrollDown()
Scrolls down the screen.

Returns:true if more scrolling can be performed 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 performed 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 the specified AbsListView.

Parameters:list - the AbsListView to scrollReturns:true if more scrolling can be performed

scrollListToBottom

public boolean scrollListToBottom(android.widget.AbsListView list)
Scrolls to the bottom of the specified AbsListView.

Parameters:list - the AbsListView to scrollReturns:true if more scrolling can be performed

scrollUpList

public boolean scrollUpList(android.widget.AbsListView list)
Scrolls up the specified AbsListView.

Parameters:list - the AbsListView to scrollReturns:true if more scrolling can be performed

scrollListToTop

public boolean scrollListToTop(android.widget.AbsListView list)
Scrolls to the top of the specified AbsListView.

Parameters:list - the AbsListView to scrollReturns:true if more scrolling can be performed

scrollDownList

public boolean scrollDownList(int index)
Scrolls down a ListView matching the specified index.

Parameters:index - the index of the ListView to scroll. 0 if only one list is availableReturns:true if more scrolling can be performed

scrollListToBottom

public boolean scrollListToBottom(int index)
Scrolls a ListView matching the specified index to the bottom.

Parameters:index - the index of the ListView to scroll. 0 if only one list is availableReturns:true if more scrolling can be performed

scrollUpList

public boolean scrollUpList(int index)
Scrolls up a ListView matching the specified index.

Parameters:index - the index of the ListView to scroll. 0 if only one list is availableReturns:true if more scrolling can be performed

scrollListToTop

public boolean scrollListToTop(int index)
Scrolls a ListView matching the specified index to the top.

Parameters:index - the index of the ListView to scroll. 0 if only one list is availableReturns:true if more scrolling can be performed

scrollListToLine

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

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

scrollListToLine

public void scrollListToLine(int index,
                             int line)
Scroll a AbsListView matching the specified index to the specified line.

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

scrollToSide

public void scrollToSide(int side,
                         float scrollPosition,
                         int stepCount)
Scrolls horizontally.

Parameters:side - the side to scroll; RIGHT or LEFTscrollPosition - the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60stepCount - how many move steps to include in the scroll. Less steps results in a faster scroll

scrollToSide

public void scrollToSide(int side,
                         float scrollPosition)
Scrolls horizontally.

Parameters:side - the side to scroll; RIGHT or LEFTscrollPosition - the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60

scrollToSide

public void scrollToSide(int side)
Scrolls horizontally.

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

scrollViewToSide

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

Parameters:view - the View to scrollside - the side to scroll; RIGHT or LEFTscrollPosition - the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60stepCount - how many move steps to include in the scroll. Less steps results in a faster scroll

scrollViewToSide

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

Parameters:view - the View to scrollside - the side to scroll; RIGHT or LEFTscrollPosition - the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60

scrollViewToSide

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

Parameters:view - the View to scrollside - the side to scroll; RIGHT or LEFT

pinchToZoom

public void pinchToZoom(android.graphics.PointF startPoint1,
                        android.graphics.PointF startPoint2,
                        android.graphics.PointF endPoint1,
                        android.graphics.PointF endPoint2)
Zooms in or out if startPoint1 and startPoint2 are larger or smaller then endPoint1 and endPoint2. Requires API level >= 14.

Parameters:startPoint1 - First "finger" down on the screenstartPoint2 - Second "finger" down on the screenendPoint1 - Corresponding ending point of startPoint1endPoint2 - Corresponding ending point of startPoint2

swipe

public void swipe(android.graphics.PointF startPoint1,
                  android.graphics.PointF startPoint2,
                  android.graphics.PointF endPoint1,
                  android.graphics.PointF endPoint2)
Swipes with two fingers in a linear path determined by starting and ending points. Requires API level >= 14.

Parameters:startPoint1 - First "finger" down on the screenstartPoint2 - Second "finger" down on the screenendPoint1 - Corresponding ending point of startPoint1endPoint2 - Corresponding ending point of startPoint2

rotateLarge

public void rotateLarge(android.graphics.PointF center1,
                        android.graphics.PointF center2)
Draws two semi-circles at the specified centers. Both circles are larger than rotateSmall(). Requires API level >= 14.

Parameters:center1 - Center of semi-circle drawn from [0, Pi]center2 - Center of semi-circle drawn from [Pi, 3*Pi]

rotateSmall

public void rotateSmall(android.graphics.PointF center1,
                        android.graphics.PointF center2)
Draws two semi-circles at the specified centers. Both circles are smaller than rotateLarge(). Requires API level >= 14.

Parameters:center1 - Center of semi-circle drawn from [0, Pi]center2 - Center of semi-circle drawn from [Pi, 3*Pi]

setDatePicker

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

Parameters:index - the index of the DatePicker. 0 if only one is availableyear - the year e.g. 2011monthOfYear - the month which starts from zero e.g. 0 for JanuarydayOfMonth - the day e.g. 10

setDatePicker

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

Parameters:datePicker - the DatePicker objectyear - the year e.g. 2011monthOfYear - the month which starts from zero e.g. 03 for AprildayOfMonth - the day e.g. 10

setTimePicker

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

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

setTimePicker

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

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

setProgressBar

public void setProgressBar(int index,
                           int progress)
Sets the progress of a ProgressBar matching the specified index. Examples of ProgressBars are: SeekBar and RatingBar.

Parameters:index - the index of the ProgressBarprogress - the progress to set the ProgressBar

setProgressBar

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

Parameters:progressBar - the ProgressBarprogress - the progress to set the ProgressBar

setNavigationDrawer

public void setNavigationDrawer(int status)
Sets the status of the NavigationDrawer. Examples of status are: Solo.CLOSED and Solo.OPENED.

Parameters:status - the status that the NavigationDrawer should be set to

setSlidingDrawer

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

Parameters:index - the index of the SlidingDrawerstatus - the status to set the SlidingDrawer

setSlidingDrawer

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

Parameters:slidingDrawer - the SlidingDrawerstatus - the status to set the SlidingDrawer

enterText

public void enterText(int index,
                      String text)
Enters text in an EditText matching the specified index.

Parameters:index - the index of the EditText. 0 if only one is availabletext - the text to enter in the EditText field

enterText

public void enterText(android.widget.EditText editText,
                      String text)
Enters text in the specified EditText.

Parameters:editText - the EditText to enter text intext - the text to enter in the EditText field

enterTextInWebElement

public void enterTextInWebElement(By by,
                                  String text)
Enters text in a WebElement matching the specified By object.

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

typeText

public void typeText(int index,
                     String text)
Types text in an EditText matching the specified index.

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

typeText

public void typeText(android.widget.EditText editText,
                     String text)
Types text in the specified EditText.

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

typeTextInWebElement

public void typeTextInWebElement(By by,
                                 String text)
Types text in a WebElement matching the specified By object.

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

typeTextInWebElement

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

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

typeTextInWebElement

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

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

clearEditText

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

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

clearEditText

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

Parameters:editText - the EditText to clear

clearTextInWebElement

public void clearTextInWebElement(By by)
Clears text in a WebElement matching the specified By object.

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

clickOnImage

public void clickOnImage(int index)
Clicks an ImageView matching the specified index.

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

getEditText

public android.widget.EditText getEditText(int index)
Returns an EditText matching the specified index.

Parameters:index - the index of the EditText. 0 if only one is availableReturns:an EditText matching the specified index

getButton

public android.widget.Button getButton(int index)
Returns a Button matching the specified index.

Parameters:index - the index of the Button. 0 if only one is availableReturns:a Button matching the specified index

getText

public android.widget.TextView getText(int index)
Returns a TextView matching the specified index.

Parameters:index - the index of the TextView. 0 if only one is availableReturns:a TextView matching the specified index

getImage

public android.widget.ImageView getImage(int index)
Returns an ImageView matching the specified index.

Parameters:index - the index of the ImageView. 0 if only one is availableReturns:an ImageView matching the specified index

getImageButton

public android.widget.ImageButton getImageButton(int index)
Returns an ImageButton matching the specified index.

Parameters:index - the index of the ImageButton. 0 if only one is availableReturns:the ImageButton matching the specified index

getText

public android.widget.TextView getText(String text)
Returns a TextView displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressionReturns:the TextView displaying the specified text

getText

public android.widget.TextView getText(String text,
                                       boolean onlyVisible)
Returns a TextView displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressiononlyVisible - true if only visible texts on the screen should be returnedReturns:the TextView displaying the specified text

getButton

public android.widget.Button getButton(String text)
Returns a Button displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressionReturns:the Button displaying the specified text

getButton

public android.widget.Button getButton(String text,
                                       boolean onlyVisible)
Returns a Button displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressiononlyVisible - true if only visible buttons on the screen should be returnedReturns:the Button displaying the specified text

getEditText

public android.widget.EditText getEditText(String text)
Returns an EditText displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressionReturns:the EditText displaying the specified text

getEditText

public android.widget.EditText getEditText(String text,
                                           boolean onlyVisible)
Returns an EditText displaying the specified text.

Parameters:text - the text that is displayed, specified as a regular expressiononlyVisible - true if only visible EditTexts on the screen should be returnedReturns:the EditText displaying the specified text

getView

public android.view.View getView(int id)
Returns a View matching the specified resource id.

Parameters:id - the R.id of the View to returnReturns:a View matching the specified id

getView

public android.view.View getView(int id,
                                 int index)
Returns a View matching the specified resource id and index.

Parameters:id - the R.id of the View to returnindex - the index of the View. 0 if only one is availableReturns:a View matching the specified id and index

getView

public android.view.View getView(String id)
Returns a View matching the specified resource id.

Parameters:id - the id of the View to returnReturns:a View matching the specified id

getView

public android.view.View getView(String id,
                                 int index)
Returns a View matching the specified resource id and index.

Parameters:id - the id of the View to returnindex - the index of the View. 0 if only one is availableReturns:a View matching the specified id and index

getView

public  T getView(Class viewClass,
                                               int index)
Returns a View matching the specified class and index.

Parameters:viewClass - the class of the requested viewindex - the index of the View. 0 if only one is availableReturns:a View matching the specified class and index

getWebElement

public WebElement getWebElement(By by,
                                int index)
Returns a WebElement matching the specified By object and 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 availableReturns:a WebElement matching the specified index

getWebUrl

public String getWebUrl()
Returns the current web page URL.

Returns:the current web page URL

getCurrentViews

public ArrayList getCurrentViews()
Returns an ArrayList of the Views currently displayed in the focused Activity or Dialog.

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

getCurrentViews

public  ArrayList getCurrentViews(Class classToFilterBy)
Returns an ArrayList of Views matching the specified class located in the focused Activity or Dialog.

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

getCurrentViews

public  ArrayList getCurrentViews(Class classToFilterBy,
                                                                  boolean includeSubclasses)
Returns an ArrayList of Views matching the specified class located in the focused Activity or Dialog.

Parameters:classToFilterBy - return all instances of this class. Examples are: Button.class or ListView.classincludeSubclasses - include instances of the subclasses in the ArrayList that will be returnedReturns:an ArrayList of Views matching the specified Class located in the current Activity

getCurrentViews

public  ArrayList getCurrentViews(Class classToFilterBy,
                                                                  android.view.View parent)
Returns an ArrayList of Views matching the specified class located under the specified parent.

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

getCurrentViews

public  ArrayList getCurrentViews(Class classToFilterBy,
                                                                  boolean includeSubclasses,
                                                                  android.view.View parent)
Returns an ArrayList of Views matching the specified class located under the specified parent.

Parameters:classToFilterBy - return all instances of this class. Examples are: Button.class or ListView.classincludeSubclasses - include instances of subclasses in the ArrayList that will be returnedparent - the parent View for where to start the traversalReturns:an ArrayList of Views matching the specified Class located under the specified parent

getWebElements

public ArrayList getWebElements()
Returns an ArrayList of all the WebElements displayed in the active WebView.

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

getWebElements

public ArrayList getWebElements(By by)
Returns an ArrayList of all the WebElements displayed in the active WebView matching the specified By object.

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

getCurrentWebElements

public ArrayList getCurrentWebElements()
Returns an ArrayList of the currently displayed WebElements in the active WebView.

Returns:an ArrayList of the WebElement objects displayed in the active WebView

getCurrentWebElements

public ArrayList getCurrentWebElements(By by)
Returns an ArrayList of the currently displayed WebElements in the active WebView matching the specified By object.

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

isRadioButtonChecked

public boolean isRadioButtonChecked(int index)
Checks if a RadioButton matching the specified index is checked.

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

isRadioButtonChecked

public boolean isRadioButtonChecked(String text)
Checks if a RadioButton displaying the specified text is checked.

Parameters:text - the text that the RadioButton displays, specified as a regular expressionReturns:true if a RadioButton matching the specified text is checked and false if it is not checked

isCheckBoxChecked

public boolean isCheckBoxChecked(int index)
Checks if a CheckBox matching the specified index is checked.

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

isToggleButtonChecked

public boolean isToggleButtonChecked(String text)
Checks if a ToggleButton displaying the specified text is checked.

Parameters:text - the text that the ToggleButton displays, specified as a regular expressionReturns:true if a ToggleButton matching the specified text is checked and false if it is not checked

isToggleButtonChecked

public boolean isToggleButtonChecked(int index)
Checks if a ToggleButton matching the specified index is checked.

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

isCheckBoxChecked

public boolean isCheckBoxChecked(String text)
Checks if a CheckBox displaying the specified text is checked.

Parameters:text - the text that the CheckBox displays, specified as a regular expressionReturns:true if a CheckBox displaying the specified text is checked and false if it is not checked

isTextChecked

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

Parameters:text - the text that the CheckedTextView or CompoundButton objects display, specified as a regular expressionReturns:true if the specified text is checked and false if it is not checked

isSpinnerTextSelected

public boolean isSpinnerTextSelected(String text)
Checks if the specified 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 expressionReturns:true if the specified text is selected in any Spinner and false if it is not

isSpinnerTextSelected

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

Parameters:index - the index of the spinner to check. 0 if only one spinner is availabletext - the text that is expected to be selected, specified as a regular expressionReturns:true if the specified text is selected in the specified Spinner and false if it is not

hideSoftKeyboard

public void hideSoftKeyboard()
Hides the soft keyboard.


unlockScreen

public void unlockScreen()
Unlocks the lock screen.


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 an Activity matching the specified name.

Parameters:name - the name of the Activity to return to. Example is: "MyActivity"

waitForActivity

public boolean waitForActivity(String name)
Waits for an Activity matching the specified name. Default timeout is 20 seconds.

Parameters:name - the name of the Activity to wait for. Example is: "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 an Activity matching the specified name.

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

waitForActivity

public boolean waitForActivity(Class activityClass)
Waits for an Activity matching the specified class. Default timeout is 20 seconds.

Parameters:activityClass - the class of the Activity to wait for. Example is: MyActivity.classReturns:true if Activity appears before the timeout and false if it does not

waitForActivity

public boolean waitForActivity(Class activityClass,
                               int timeout)
Waits for an Activity matching the specified class.

Parameters:activityClass - the class of the Activity to wait for. Example is: MyActivity.classtimeout - the amount of time in milliseconds to waitReturns:true if Activity appears before the timeout and false if it does not

waitForEmptyActivityStack

public boolean waitForEmptyActivityStack(int timeout)
Wait for the activity stack to be empty.

Parameters:timeout - the amount of time in milliseconds to waitReturns:true if activity stack is empty before the timeout and false if it is not

waitForFragmentByTag

public boolean waitForFragmentByTag(String tag)
Waits for a Fragment matching the specified tag. Default timeout is 20 seconds.

Parameters:tag - the name of the tagReturns: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 matching the specified tag.

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

waitForFragmentById

public boolean waitForFragmentById(int id)
Waits for a Fragment matching the specified resource id. Default timeout is 20 seconds.

Parameters:id - the R.id of the fragmentReturns: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 matching the specified resource id.

Parameters:id - the R.id of the fragmenttimeout - the amount of time in milliseconds to waitReturns:true if fragment appears and false if it does not appear before the timeout

waitForLogMessage

public boolean waitForLogMessage(String logMessage)
Waits for the specified 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 forReturns:true if log message appears and false if it does not appear before the timeoutSee Also:clearLog()

waitForLogMessage

public boolean waitForLogMessage(String logMessage,
                                 int timeout)
Waits for the specified 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 fortimeout - the amount of time in milliseconds to waitReturns:true if log message appears and false if it does not appear before the timeoutSee Also:clearLog()

clearLog

public void clearLog()
Clears the log.


getString

public String getString(int id)
Returns a localized String matching the specified resource id.

Parameters:id - the R.id of the StringReturns:the localized String

getString

public String getString(String id)
Returns a localized String matching the specified resource id.

Parameters:id - the id of the StringReturns:the localized String

sleep

public void sleep(int time)
Robotium will sleep for the 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:ThrowableSee 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 the Solo.Config objects save path (default set to: /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 the specified name in the Solo.Config objects save path (default set to: /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 the image with the specified name in the Solo.Config objects save path (default set to: /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 screenshotquality - the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality)

startScreenshotSequence

public void startScreenshotSequence(String name)
Takes a screenshot sequence and saves the images with the specified name prefix in the Solo.Config objects save path (default set to: /sdcard/Robotium-Screenshots/). The name prefix is appended with "_" + sequence_number for each image in the sequence, where numbering starts at 0. Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test. At present multiple simultaneous screenshot sequences are not supported. This method will throw an exception if stopScreenshotSequence() has not been called to finish any prior sequences. Calling this method is equivalend to calling startScreenshotSequence(name, 80, 400, 100);

Parameters:name - the name prefix to give the screenshot

startScreenshotSequence

public void startScreenshotSequence(String name,
                                    int quality,
                                    int frameDelay,
                                    int maxFrames)
Takes a screenshot sequence and saves the images with the specified name prefix in the Solo.Config objects save path (default set to: /sdcard/Robotium-Screenshots/). The name prefix is appended with "_" + sequence_number for each image in the sequence, where numbering starts at 0. Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in the AndroidManifest.xml of the application under test. Taking a screenshot will take on the order of 40-100 milliseconds of time on the main UI thread. Therefore it is possible to mess up the timing of tests if the frameDelay value is set too small. At present multiple simultaneous screenshot sequences are not supported. This method will throw an exception if stopScreenshotSequence() has not been called to finish any prior sequences.

Parameters:name - the name prefix to give the screenshotquality - the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality)frameDelay - the time in milliseconds to wait between each framemaxFrames - the maximum number of frames that will comprise this sequence


3、樣例

package com.robotium.test;

import com.robotium.solo.Solo;
import com.example.android.notepad.NotesList;
import android.test.ActivityInstrumentationTestCase2;



public class NotePadTest extends ActivityInstrumentationTestCase2{

	private Solo solo;

	public NotePadTest() {
		super(NotesList.class);

	}

	@Override
	public void setUp() throws Exception {
		//setUp() is run before a test case is started. 
		//This is where the solo object is created.
		solo = new Solo(getInstrumentation(), getActivity());
	}

	@Override
	public void tearDown() throws Exception {
		//tearDown() is run after a test case has finished. 
		//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
		solo.finishOpenedActivities();
	}

	public void testAddNote() throws Exception {
		//Unlock the lock screen
		solo.unlockScreen();
		solo.clickOnMenuItem("Add note");
		//Assert that NoteEditor activity is opened
		solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");
		//In text field 0, enter Note 1
		solo.enterText(0, "Note 1");
		solo.goBack();
		//Clicks on menu item
		solo.clickOnMenuItem("Add note");
		//In text field 0, type Note 2
		solo.typeText(0, "Note 2");
		//Go back to first activity
		solo.goBack();
		//Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
		solo.takeScreenshot();
		boolean notesFound = solo.searchText("Note 1") && solo.searchText("Note 2");
		//Assert that Note 1 & Note 2 are found
		assertTrue("Note 1 and/or Note 2 are not found", notesFound);

	}
	
	public void testEditNote() throws Exception {
		// Click on the second list line
		solo.clickInList(2); 
		//Hides the soft keyboard
		solo.hideSoftKeyboard();
		// Change orientation of activity
		solo.setActivityOrientation(Solo.LANDSCAPE);
		// Change title
		solo.clickOnMenuItem("Edit title");
		//In first text field (0), add test
		solo.enterText(0, " test");
		solo.goBack();
		solo.setActivityOrientation(Solo.PORTRAIT);
		// (Regexp) case insensitive
		boolean noteFound = solo.waitForText("(?i).*?note 1 test"); 
		//Assert that Note 1 test is found
		assertTrue("Note 1 test is not found", noteFound); 

	}
	
	public void testRemoveNote() throws Exception {
		//(Regexp) case insensitive/text that contains "test"
		solo.clickOnText("(?i).*?test.*");
		//Delete Note 1 test
		solo.clickOnMenuItem("Delete");
		//Note 1 test should not be found
		boolean noteFound = solo.searchText("Note 1 test");
		//Assert that Note 1 test is not found
		assertFalse("Note 1 Test is found", noteFound);  
		solo.clickLongOnText("Note 2");
		//Clicks on Delete in the context menu
		solo.clickOnText("Delete");  
		//Will wait 100 milliseconds for the text: "Note 2"
		noteFound = solo.waitForText("Note 2", 1, 100);
		//Assert that Note 2 is not found
		assertFalse("Note 2 is found", noteFound);  
	}
}

4、總結:

後續將介紹 Android CodeCoverage

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved