Android(安卓)自动化测试(5)
关于Android的自动化测试之UI测试,之前介绍过Android 自动化测试(4)<uiautomator>, 在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
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.Instrumentationinstrumentation, android.app.Activityactivity)
- Constructor that takes the Instrumentation object and the start Activity.
- Parameters:
-
instrumentation
- theInstrumentation
instance -
activity
- the startActivity
ornull
if no Activity is specified
Solo
public Solo(android.app.Instrumentationinstrumentation, Solo.Configconfig)
- Constructor that takes the Instrumentation and Config objects.
- Parameters:
-
instrumentation
- theInstrumentation
instance -
config
- theSolo.Config
instance
Solo
public Solo(android.app.Instrumentationinstrumentation, Solo.Configconfig, android.app.Activityactivity)
- Constructor that takes the Instrumentation, Config and Activity objects.
- Parameters:
-
instrumentation
- theInstrumentation
instance -
config
- theSolo.Config
instance -
activity
- the startActivity
ornull
if no Activity is specified
Solo
public Solo(android.app.Instrumentationinstrumentation)
- Constructor that takes the instrumentation object.
- Parameters:
-
instrumentation
- theInstrumentation
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<android.view.View> getViews()
- Returns an ArrayList of all the View objects located in the focused Activity or Dialog.
-
- Returns:
- an
ArrayList
of theView
objects located in the focused window
getViews
public ArrayList<android.view.View> getViews(android.view.Viewparent)
- 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 theView
objects contained in the specifiedView
getTopParent
public android.view.View getTopParent(android.view.Viewview)
- Returns the absolute top parent View of the specified View.
-
- Parameters:
-
view
- theView
whose top parent is requested - Returns:
- the top parent
View
waitForText
public boolean waitForText(Stringtext)
- Waits for the specified text to appear. Default timeout is 20 seconds.
-
- Parameters:
-
text
- the text to wait for, specified as a regular expression - Returns:
-
true
if text is displayed andfalse
if it is not displayed before the timeout
waitForText
public boolean waitForText(Stringtext, intminimumNumberOfMatches, longtimeout)
- Waits for the specified text to appear.
-
- Parameters:
-
text
- the text to wait for, specified as a regular expression -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.0
means any number of matches -
timeout
- the the amount of time in milliseconds to wait - Returns:
-
true
if text is displayed andfalse
if it is not displayed before the timeout
waitForText
public boolean waitForText(Stringtext, intminimumNumberOfMatches, longtimeout, booleanscroll)
- Waits for the specified text to appear.
-
- Parameters:
-
text
- the text to wait for, specified as a regular expression -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.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 displayed andfalse
if it is not displayed before the timeout
waitForText
public boolean waitForText(Stringtext, intminimumNumberOfMatches, longtimeout, booleanscroll, booleanonlyVisible)
- Waits for the specified text to appear.
-
- Parameters:
-
text
- the text to wait for, specified as a regular expression -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.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 displayed andfalse
if it is not displayed before the timeout
waitForView
public boolean waitForView(intid)
- Waits for a View matching the specified resource id. Default timeout is 20 seconds.
-
- Parameters:
-
id
- the R.id of theView
to wait for - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public boolean waitForView(intid, intminimumNumberOfMatches, inttimeout)
- Waits for a View matching the specified resource id.
-
- Parameters:
-
id
- the R.id of theView
to wait for -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.0
means any number of matches -
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public boolean waitForView(intid, intminimumNumberOfMatches, inttimeout, booleanscroll)
- Waits for a View matching the specified resource id.
-
- Parameters:
-
id
- the R.id of theView
to wait for -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.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 theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public <T extends android.view.View> boolean waitForView(Class<T>viewClass)
- Waits for a View matching the specified class. Default timeout is 20 seconds.
-
- Parameters:
-
viewClass
- theView
class to wait for - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public <T extends android.view.View> boolean waitForView(android.view.Viewview)
- Waits for the specified View. Default timeout is 20 seconds.
-
- Parameters:
-
view
- theView
object to wait for - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public <T extends android.view.View> boolean waitForView(android.view.Viewview, inttimeout, booleanscroll)
- Waits for the specified View.
-
- Parameters:
-
view
- theView
object to wait for -
timeout
- the amount of time in milliseconds to wait -
scroll
-true
if scrolling should be performed - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public <T extends android.view.View> boolean waitForView(Class<T>viewClass, intminimumNumberOfMatches, inttimeout)
- Waits for a View matching the specified class.
-
- Parameters:
-
viewClass
- theView
class to wait for -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.0
means any number of matches -
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if theView
is displayed andfalse
if it is not displayed before the timeout
waitForView
public <T extends android.view.View> boolean waitForView(Class<T>viewClass, intminimumNumberOfMatches, inttimeout, booleanscroll)
- Waits for a View matching the specified class.
-
- Parameters:
-
viewClass
- theView
class to wait for -
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.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 theView
is displayed andfalse
if it is not displayed before the timeout
waitForWebElement
public boolean waitForWebElement(Byby)
- Waits for a WebElement matching the specified By object. Default timeout is 20 seconds.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
- Returns:
-
true
if theWebElement
is displayed andfalse
if it is not displayed before the timeout
waitForWebElement
public boolean waitForWebElement(Byby, inttimeout, booleanscroll)
- Waits for a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
timeout
- the the amount of time in milliseconds to wait -
scroll
-true
if scrolling should be performed - Returns:
-
true
if theWebElement
is displayed andfalse
if it is not displayed before the timeout
waitForWebElement
public boolean waitForWebElement(Byby, intminimumNumberOfMatches, inttimeout, booleanscroll)
- Waits for a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
minimumNumberOfMatches
- the minimum number of matches that are expected to be found.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 theWebElement
is displayed andfalse
if it is not displayed before the timeout
waitForCondition
public boolean waitForCondition(Conditioncondition, inttimeout)
- 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 andfalse
if it is not satisfied before the timeout
searchEditText
public boolean searchEditText(Stringtext)
- 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 for - Returns:
-
true
if anEditText
displaying the specified text is found orfalse
if it is not found
searchButton
public boolean searchButton(Stringtext)
- 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 expression - Returns:
-
true
if aButton
displaying the specified text is found andfalse
if it is not found
searchButton
public boolean searchButton(Stringtext, booleanonlyVisible)
- 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 expression -
onlyVisible
-true
if onlyButton
visible on the screen should be searched - Returns:
-
true
if aButton
displaying the specified text is found andfalse
if it is not found
searchToggleButton
public boolean searchToggleButton(Stringtext)
- 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 expression - Returns:
-
true
if aToggleButton
displaying the specified text is found andfalse
if it is not found
searchButton
public boolean searchButton(Stringtext, intminimumNumberOfMatches)
- 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 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 aButton
displaying the specified text is found a specified number of times andfalse
if it is not found
searchButton
public boolean searchButton(Stringtext, intminimumNumberOfMatches, booleanonlyVisible)
- 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 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 onlyButton
visible on the screen should be searched - Returns:
-
true
if aButton
displaying the specified text is found a specified number of times andfalse
if it is not found
searchToggleButton
public boolean searchToggleButton(Stringtext, intminimumNumberOfMatches)
- 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 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 aToggleButton
displaying the specified text is found a specified number of times andfalse
if it is not found
searchText
public boolean searchText(Stringtext)
- 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 expression - Returns:
-
true
if the search string is found andfalse
if it is not found
searchText
public boolean searchText(Stringtext, booleanonlyVisible)
- 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 expression -
onlyVisible
-true
if only texts visible on the screen should be searched - Returns:
-
true
if the search string is found andfalse
if it is not found
searchText
public boolean searchText(Stringtext, intminimumNumberOfMatches)
- 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 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 is found a specified number of times andfalse
if the text is not found
searchText
public boolean searchText(Stringtext, intminimumNumberOfMatches, booleanscroll)
- 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 found -
scroll
-true
if scrolling should be performed - Returns:
-
true
if text is found a specified number of times andfalse
if the text is not found
searchText
public boolean searchText(Stringtext, intminimumNumberOfMatches, booleanscroll, booleanonlyVisible)
- 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 found -
scroll
-true
if scrolling should be performed -
onlyVisible
-true
if only texts visible on the screen should be searched - Returns:
-
true
if text is found a specified number of times andfalse
if the text is not found
setActivityOrientation
public void setActivityOrientation(intorientation)
- Sets the Orientation (Landscape/Portrait) for the current Activity.
-
- Parameters:
-
orientation
- the orientation to set.Solo.
LANDSCAPE
for landscape orSolo.
PORTRAIT
for portrait.
getCurrentActivity
public android.app.Activity getCurrentActivity()
- Returns the current Activity.
-
- Returns:
- the current Activity
assertCurrentActivity
public void assertCurrentActivity(Stringmessage, Stringname)
- Asserts that the Activity matching the specified name is active.
-
- Parameters:
-
message
- the message to display if the assert fails -
name
- the name of theActivity
that is expected to be active. Example is:"MyActivity"
assertCurrentActivity
public void assertCurrentActivity(Stringmessage, ClassactivityClass)
- Asserts that the Activity matching the specified class is active.
-
- Parameters:
-
message
- the message to display if the assert fails -
activityClass
- the class of the Activity that is expected to be active. Example is:MyActivity.class
assertCurrentActivity
public void assertCurrentActivity(Stringmessage, Stringname, booleanisNewInstance)
- 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 fails -
name
- the name of the Activity that is expected to be active. Example is:"MyActivity"
-
isNewInstance
-true
if the expectedActivity
is a new instance of theActivity
assertCurrentActivity
public void assertCurrentActivity(Stringmessage, ClassactivityClass, booleanisNewInstance)
- 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 fails -
activityClass
- the class of the Activity that is expected to be active. Example is:MyActivity.class
-
isNewInstance
-true
if the expectedActivity
is a new instance of theActivity
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 theDialog
is opened before the timeout andfalse
if it is not opened
waitForDialogToClose
public boolean waitForDialogToClose()
- Waits for a Dialog to close. Default timeout is 20 seconds.
-
- Returns:
-
true
if theDialog
is closed before the timeout andfalse
if it is not closed
waitForDialogToOpen
public boolean waitForDialogToOpen(longtimeout)
- Waits for a Dialog to open.
-
- Parameters:
-
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if theDialog
is opened before the timeout andfalse
if it is not opened
waitForDialogToClose
public boolean waitForDialogToClose(longtimeout)
- Waits for a Dialog to close.
-
- Parameters:
-
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if theDialog
is closed before the timeout andfalse
if it is not closed
goBack
public void goBack()
- Simulates pressing the hardware back key.
-
clickOnScreen
public void clickOnScreen(floatx, floaty)
- Clicks the specified coordinates.
-
- Parameters:
-
x
- the x coordinate -
y
- the y coordinate
clickOnScreen
public void clickOnScreen(floatx, floaty, intnumberOfClicks)
- Clicks the specified coordinates rapidly a specified number of times. Requires API level >= 14.
-
- Parameters:
-
x
- the x coordinate -
y
- the y coordinate -
numberOfClicks
- the number of clicks to perform
clickLongOnScreen
public void clickLongOnScreen(floatx, floaty)
- Long clicks the specified coordinates.
-
- Parameters:
-
x
- the x coordinate -
y
- the y coordinate
clickLongOnScreen
public void clickLongOnScreen(floatx, floaty, inttime)
- Long clicks the specified coordinates for a specified amount of time.
-
- Parameters:
-
x
- the x coordinate -
y
- the y coordinate -
time
- the amount of time to long click
clickOnButton
public void clickOnButton(Stringtext)
- Clicks a Button displaying the specified text. Will automatically scroll when needed.
-
- Parameters:
-
text
- the text displayed by theButton
. The parameter will be interpreted as a regular expression
clickOnImageButton
public void clickOnImageButton(intindex)
- Clicks an ImageButton matching the specified index.
-
- Parameters:
-
index
- the index of theImageButton
to click. 0 if only one is available
clickOnToggleButton
public void clickOnToggleButton(Stringtext)
- Clicks a ToggleButton displaying the specified text.
-
- Parameters:
-
text
- the text displayed by theToggleButton
. The parameter will be interpreted as a regular expression
clickOnMenuItem
public void clickOnMenuItem(Stringtext)
- 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(Stringtext, booleansubMenu)
- Clicks a MenuItem displaying the specified text.
-
- Parameters:
-
text
- the text displayed by the MenuItem. 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(WebElementwebElement)
- Clicks the specified WebElement.
-
- Parameters:
-
webElement
- the WebElement to click
clickOnWebElement
public void clickOnWebElement(Byby)
- Clicks a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
clickOnWebElement
public void clickOnWebElement(Byby, intmatch)
- Clicks a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
match
- if multiple objects match, this determines which one to click
clickOnWebElement
public void clickOnWebElement(Byby, intmatch, booleanscroll)
- Clicks a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
match
- if multiple objects match, this determines which one to click -
scroll
-true
if scrolling should be performed
pressMenuItem
public void pressMenuItem(intindex)
- Presses a MenuItem matching the specified index. Index
0
is the first item in the first row, Index3
is the first item in the second row and index6
is the first item in the third row. -
- Parameters:
-
index
- the index of theMenuItem
to press
pressMenuItem
public void pressMenuItem(intindex, intitemsPerRow)
- 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 theMenuItem
to press -
itemsPerRow
- 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(intspinnerIndex, intitemIndex)
- Presses a Spinner (drop-down menu) item.
-
- Parameters:
-
spinnerIndex
- the index of theSpinner
menu to use -
itemIndex
- the index of theSpinner
item to press relative to the currently selected item. A Negative number moves up on theSpinner
, positive moves down
clickOnView
public void clickOnView(android.view.Viewview)
- Clicks the specified View.
-
- Parameters:
-
view
- theView
to click
clickOnView
public void clickOnView(android.view.Viewview, booleanimmediately)
- Clicks the specified View.
-
- Parameters:
-
view
- theView
to click -
immediately
-true
if View should be clicked without any wait
clickLongOnView
public void clickLongOnView(android.view.Viewview)
- Long clicks the specified View.
-
- Parameters:
-
view
- theView
to long click
clickLongOnView
public void clickLongOnView(android.view.Viewview, inttime)
- Long clicks the specified View for a specified amount of time.
-
- Parameters:
-
view
- theView
to long click -
time
- the amount of time to long click
clickOnText
public void clickOnText(Stringtext)
- 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(Stringtext, intmatch)
- 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 -
match
- if multiple objects match the text, this determines which one to click
clickOnText
public void clickOnText(Stringtext, intmatch, booleanscroll)
- Clicks a View or WebElement displaying the specified text.
-
- Parameters:
-
text
- the text to click. The parameter will be interpreted as a regular expression -
match
- if multiple objects match the text, this determines which one to click -
scroll
-true
if scrolling should be performed
clickLongOnText
public void clickLongOnText(Stringtext)
- 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(Stringtext, intmatch)
- 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 -
match
- if multiple objects match the text, this determines which one to click
clickLongOnText
public void clickLongOnText(Stringtext, intmatch, booleanscroll)
- Long clicks a View or WebElement displaying the specified text.
-
- Parameters:
-
text
- the text to click. The parameter will be interpreted as a regular expression -
match
- if multiple objects match the text, this determines which one to click -
scroll
-true
if scrolling should be performed
clickLongOnText
public void clickLongOnText(Stringtext, intmatch, inttime)
- Long clicks a View or WebElement displaying the specified text.
-
- Parameters:
-
text
- the text to click. The parameter will be interpreted as a regular expression -
match
- if multiple objects match the text, this determines which one to click -
time
- the amount of time to long click
clickLongOnTextAndPress
public void clickLongOnTextAndPress(Stringtext, intindex)
- 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 expression -
index
- the index of the menu item to press.0
if only one is available
clickOnButton
public void clickOnButton(intindex)
- Clicks a Button matching the specified index.
-
- Parameters:
-
index
- the index of theButton
to click.0
if only one is available
clickOnRadioButton
public void clickOnRadioButton(intindex)
- Clicks a RadioButton matching the specified index.
-
- Parameters:
-
index
- the index of theRadioButton
to click.0
if only one is available
clickOnCheckBox
public void clickOnCheckBox(intindex)
- Clicks a CheckBox matching the specified index.
-
- Parameters:
-
index
- the index of theCheckBox
to click.0
if only one is available
clickOnEditText
public void clickOnEditText(intindex)
- Clicks an EditText matching the specified index.
-
- Parameters:
-
index
- the index of theEditText
to click.0
if only one is available
clickInList
public ArrayList<android.widget.TextView> clickInList(intline)
- 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 click - Returns:
- an
ArrayList
of theTextView
objects located in the list line
clickInList
public ArrayList<android.widget.TextView> clickInList(intline, intindex)
- 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 click -
index
- the index of the list.0
if only one is available - Returns:
- an
ArrayList
of theTextView
objects located in the list line
clickLongInList
public ArrayList<android.widget.TextView> clickLongInList(intline)
- 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 click - Returns:
- an
ArrayList
of theTextView
objects located in the list line
clickLongInList
public ArrayList<android.widget.TextView> clickLongInList(intline, intindex)
- 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 click -
index
- the index of the list.0
if only one is available - Returns:
- an
ArrayList
of theTextView
objects located in the list line
clickLongInList
public ArrayList<android.widget.TextView> clickLongInList(intline, intindex, inttime)
- 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 click -
index
- the index of the list.0
if only one is available -
time
- the amount of time to long click - Returns:
- an
ArrayList
of theTextView
objects located in the list line
clickOnActionBarItem
public void clickOnActionBarItem(intid)
- 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(floatfromX, floattoX, floatfromY, floattoY, intstepCount)
- Simulate touching the specified location and dragging it to a new location.
-
- Parameters:
-
fromX
- X coordinate of the initial touch, in screen coordinates -
toX
- X coordinate of the drag destination, in screen coordinates -
fromY
- Y 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. Less steps results in a faster drag
scrollDown
public boolean scrollDown()
- Scrolls down the screen.
-
- Returns:
-
true
if more scrolling can be performed andfalse
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 andfalse
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.AbsListViewlist)
- Scrolls down the specified AbsListView.
-
- Parameters:
-
list
- theAbsListView
to scroll - Returns:
-
true
if more scrolling can be performed
scrollListToBottom
public boolean scrollListToBottom(android.widget.AbsListViewlist)
- Scrolls to the bottom of the specified AbsListView.
-
- Parameters:
-
list
- theAbsListView
to scroll - Returns:
-
true
if more scrolling can be performed
scrollUpList
public boolean scrollUpList(android.widget.AbsListViewlist)
- Scrolls up the specified AbsListView.
-
- Parameters:
-
list
- theAbsListView
to scroll - Returns:
-
true
if more scrolling can be performed
scrollListToTop
public boolean scrollListToTop(android.widget.AbsListViewlist)
- Scrolls to the top of the specified AbsListView.
-
- Parameters:
-
list
- theAbsListView
to scroll - Returns:
-
true
if more scrolling can be performed
scrollDownList
public boolean scrollDownList(intindex)
- Scrolls down a ListView matching the specified index.
-
- Parameters:
-
index
- the index of theListView
to scroll.0
if only one list is available - Returns:
-
true
if more scrolling can be performed
scrollListToBottom
public boolean scrollListToBottom(intindex)
- Scrolls a ListView matching the specified index to the bottom.
-
- Parameters:
-
index
- the index of theListView
to scroll.0
if only one list is available - Returns:
-
true
if more scrolling can be performed
scrollUpList
public boolean scrollUpList(intindex)
- Scrolls up a ListView matching the specified index.
-
- Parameters:
-
index
- the index of theListView
to scroll.0
if only one list is available - Returns:
-
true
if more scrolling can be performed
scrollListToTop
public boolean scrollListToTop(intindex)
- Scrolls a ListView matching the specified index to the top.
-
- Parameters:
-
index
- the index of theListView
to scroll.0
if only one list is available - Returns:
-
true
if more scrolling can be performed
scrollListToLine
public void scrollListToLine(android.widget.AbsListViewabsListView, intline)
- Scroll the specified AbsListView to the specified line.
-
- Parameters:
-
absListView
- theAbsListView
to scroll -
line
- the line to scroll to
scrollListToLine
public void scrollListToLine(intindex, intline)
- Scroll a AbsListView matching the specified index to the specified line.
-
- Parameters:
-
index
- the index of theAbsListView
to scroll -
line
- the line to scroll to
scrollToSide
public void scrollToSide(intside, floatscrollPosition, intstepCount)
- Scrolls horizontally.
-
- Parameters:
-
side
- the side to scroll;RIGHT
orLEFT
-
scrollPosition
- the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60 -
stepCount
- how many move steps to include in the scroll. Less steps results in a faster scroll
scrollToSide
public void scrollToSide(intside, floatscrollPosition)
- Scrolls horizontally.
-
- Parameters:
-
side
- the side to scroll;RIGHT
orLEFT
-
scrollPosition
- the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60
scrollToSide
public void scrollToSide(intside)
- Scrolls horizontally.
-
- Parameters:
-
side
- the side to scroll;RIGHT
orLEFT
scrollViewToSide
public void scrollViewToSide(android.view.Viewview, intside, floatscrollPosition, intstepCount)
- Scrolls a View horizontally.
-
- Parameters:
-
view
- the View to scroll -
side
- the side to scroll;RIGHT
orLEFT
-
scrollPosition
- the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.60 -
stepCount
- how many move steps to include in the scroll. Less steps results in a faster scroll
scrollViewToSide
public void scrollViewToSide(android.view.Viewview, intside, floatscrollPosition)
- Scrolls a View horizontally.
-
- Parameters:
-
view
- the View to scroll -
side
- the side to scroll;RIGHT
orLEFT
-
scrollPosition
- 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.Viewview, intside)
- Scrolls a View horizontally.
-
- Parameters:
-
view
- the View to scroll -
side
- the side to scroll;RIGHT
orLEFT
pinchToZoom
public void pinchToZoom(android.graphics.PointFstartPoint1, android.graphics.PointFstartPoint2, android.graphics.PointFendPoint1, android.graphics.PointFendPoint2)
- 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 screen -
startPoint2
- Second "finger" down on the screen -
endPoint1
- Corresponding ending point of startPoint1 -
endPoint2
- Corresponding ending point of startPoint2
swipe
public void swipe(android.graphics.PointFstartPoint1, android.graphics.PointFstartPoint2, android.graphics.PointFendPoint1, android.graphics.PointFendPoint2)
- 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 screen -
startPoint2
- Second "finger" down on the screen -
endPoint1
- Corresponding ending point of startPoint1 -
endPoint2
- Corresponding ending point of startPoint2
rotateLarge
public void rotateLarge(android.graphics.PointFcenter1, android.graphics.PointFcenter2)
- 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.PointFcenter1, android.graphics.PointFcenter2)
- 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(intindex, intyear, intmonthOfYear, intdayOfMonth)
- Sets the date in a DatePicker matching the specified index.
-
- Parameters:
-
index
- the index of theDatePicker
.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.DatePickerdatePicker, intyear, intmonthOfYear, intdayOfMonth)
- Sets the date in the specified DatePicker.
-
- Parameters:
-
datePicker
- theDatePicker
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(intindex, inthour, intminute)
- Sets the time in a TimePicker matching the specified index.
-
- Parameters:
-
index
- the index of theTimePicker
.0
if only one is available -
hour
- the hour e.g. 15 -
minute
- the minute e.g. 30
setTimePicker
public void setTimePicker(android.widget.TimePickertimePicker, inthour, intminute)
- Sets the time in the specified TimePicker.
-
- Parameters:
-
timePicker
- theTimePicker
object -
hour
- the hour e.g. 15 -
minute
- the minute e.g. 30
setProgressBar
public void setProgressBar(intindex, intprogress)
- Sets the progress of a ProgressBar matching the specified index. Examples of ProgressBars are:
SeekBar
andRatingBar
. -
- Parameters:
-
index
- the index of theProgressBar
-
progress
- the progress to set theProgressBar
setProgressBar
public void setProgressBar(android.widget.ProgressBarprogressBar, intprogress)
- Sets the progress of the specified ProgressBar. Examples of ProgressBars are:
SeekBar
andRatingBar
. -
- Parameters:
-
progressBar
- theProgressBar
-
progress
- the progress to set theProgressBar
setNavigationDrawer
public void setNavigationDrawer(intstatus)
- Sets the status of the NavigationDrawer. Examples of status are:
Solo.CLOSED
andSolo.OPENED
. -
- Parameters:
-
status
- the status that theNavigationDrawer
should be set to
setSlidingDrawer
public void setSlidingDrawer(intindex, intstatus)
- Sets the status of a SlidingDrawer matching the specified index. Examples of status are:
Solo.CLOSED
andSolo.OPENED
. -
- Parameters:
-
index
- the index of theSlidingDrawer
-
status
- the status to set theSlidingDrawer
setSlidingDrawer
public void setSlidingDrawer(android.widget.SlidingDrawerslidingDrawer, intstatus)
- Sets the status of the specified SlidingDrawer. Examples of status are:
Solo.CLOSED
andSolo.OPENED
. -
- Parameters:
-
slidingDrawer
- theSlidingDrawer
-
status
- the status to set theSlidingDrawer
enterText
public void enterText(intindex, Stringtext)
- Enters text in an EditText matching the specified index.
-
- Parameters:
-
index
- the index of theEditText
.0
if only one is available -
text
- the text to enter in theEditText
field
enterText
public void enterText(android.widget.EditTexteditText, Stringtext)
- Enters text in the specified EditText.
-
- Parameters:
-
editText
- theEditText
to enter text in -
text
- the text to enter in theEditText
field
enterTextInWebElement
public void enterTextInWebElement(Byby, Stringtext)
- Enters text in a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
text
- the text to enter in theWebElement
field
typeText
public void typeText(intindex, Stringtext)
- Types text in an EditText matching the specified index.
-
- Parameters:
-
index
- the index of theEditText
.0
if only one is available -
text
- the text to type in theEditText
field
typeText
public void typeText(android.widget.EditTexteditText, Stringtext)
- Types text in the specified EditText.
-
- Parameters:
-
editText
- theEditText
to type text in -
text
- the text to type in theEditText
field
typeTextInWebElement
public void typeTextInWebElement(Byby, Stringtext)
- Types text in a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
text
- the text to enter in theWebElement
field
typeTextInWebElement
public void typeTextInWebElement(Byby, Stringtext, intmatch)
- Types text in a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
text
- the text to enter in theWebElement
field -
match
- if multiple objects match, this determines which one will be typed in
typeTextInWebElement
public void typeTextInWebElement(WebElementwebElement, Stringtext)
- Types text in the specified WebElement.
-
- Parameters:
-
webElement
- the WebElement to type text in -
text
- the text to enter in theWebElement
field
clearEditText
public void clearEditText(intindex)
- Clears the value of an EditText.
-
- Parameters:
-
index
- the index of theEditText
to clear. 0 if only one is available
clearEditText
public void clearEditText(android.widget.EditTexteditText)
- Clears the value of an EditText.
-
- Parameters:
-
editText
- theEditText
to clear
clearTextInWebElement
public void clearTextInWebElement(Byby)
- Clears text in a WebElement matching the specified By object.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
clickOnImage
public void clickOnImage(intindex)
- Clicks an ImageView matching the specified index.
-
- Parameters:
-
index
- the index of theImageView
to click.0
if only one is available
getEditText
public android.widget.EditText getEditText(intindex)
- Returns an EditText matching the specified index.
-
- Parameters:
-
index
- the index of theEditText
.0
if only one is available - Returns:
- an
EditText
matching the specified index
getButton
public android.widget.Button getButton(intindex)
- Returns a Button matching the specified index.
-
- Parameters:
-
index
- the index of theButton
.0
if only one is available - Returns:
- a
Button
matching the specified index
getText
public android.widget.TextView getText(intindex)
- Returns a TextView matching the specified index.
-
- Parameters:
-
index
- the index of theTextView
.0
if only one is available - Returns:
- a
TextView
matching the specified index
getImage
public android.widget.ImageView getImage(intindex)
- Returns an ImageView matching the specified index.
-
- Parameters:
-
index
- the index of theImageView
.0
if only one is available - Returns:
- an
ImageView
matching the specified index
getImageButton
public android.widget.ImageButton getImageButton(intindex)
- Returns an ImageButton matching the specified index.
-
- Parameters:
-
index
- the index of theImageButton
.0
if only one is available - Returns:
- the
ImageButton
matching the specified index
getText
public android.widget.TextView getText(Stringtext)
- Returns a TextView displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression - Returns:
- the
TextView
displaying the specified text
getText
public android.widget.TextView getText(Stringtext, booleanonlyVisible)
- Returns a TextView displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression -
onlyVisible
-true
if only visible texts on the screen should be returned - Returns:
- the
TextView
displaying the specified text
getButton
public android.widget.Button getButton(Stringtext)
- Returns a Button displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression - Returns:
- the
Button
displaying the specified text
getButton
public android.widget.Button getButton(Stringtext, booleanonlyVisible)
- Returns a Button displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression -
onlyVisible
-true
if only visible buttons on the screen should be returned - Returns:
- the
Button
displaying the specified text
getEditText
public android.widget.EditText getEditText(Stringtext)
- Returns an EditText displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression - Returns:
- the
EditText
displaying the specified text
getEditText
public android.widget.EditText getEditText(Stringtext, booleanonlyVisible)
- Returns an EditText displaying the specified text.
-
- Parameters:
-
text
- the text that is displayed, specified as a regular expression -
onlyVisible
-true
if only visible EditTexts on the screen should be returned - Returns:
- the
EditText
displaying the specified text
getView
public android.view.View getView(intid)
- Returns a View matching the specified resource id.
-
- Parameters:
-
id
- the R.id of theView
to return - Returns:
- a
View
matching the specified id
getView
public android.view.View getView(intid, intindex)
- Returns a View matching the specified resource id and index.
-
- Parameters:
-
id
- the R.id of theView
to return -
index
- the index of theView
.0
if only one is available - Returns:
- a
View
matching the specified id and index
getView
public android.view.View getView(Stringid)
- Returns a View matching the specified resource id.
-
- Parameters:
-
id
- the id of theView
to return - Returns:
- a
View
matching the specified id
getView
public android.view.View getView(Stringid, intindex)
- Returns a View matching the specified resource id and index.
-
- Parameters:
-
id
- the id of theView
to return -
index
- the index of theView
.0
if only one is available - Returns:
- a
View
matching the specified id and index
getView
public <T extends android.view.View> T getView(Class<T>viewClass, intindex)
- Returns a View matching the specified class and index.
-
- Parameters:
-
viewClass
- the class of the requested view -
index
- the index of theView
.0
if only one is available - Returns:
- a
View
matching the specified class and index
getWebElement
public WebElement getWebElement(Byby, intindex)
- Returns a WebElement matching the specified By object and index.
-
- Parameters:
-
by
- the By object. Examples are:By.id("id")
andBy.name("name")
-
index
- the index of theWebElement
.0
if only one is available - Returns:
- 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<android.view.View> getCurrentViews()
- Returns an ArrayList of the Views currently displayed in the focused Activity or Dialog.
-
- Returns:
- an
ArrayList
of theView
objects currently displayed in the focused window
getCurrentViews
public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T>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
orListView.class
- Returns:
- an
ArrayList
ofView
s matching the specifiedClass
located in the currentActivity
getCurrentViews
public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T>classToFilterBy, booleanincludeSubclasses)
- 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
orListView.class
-
includeSubclasses
- include instances of the subclasses in theArrayList
that will be returned - Returns:
- an
ArrayList
ofView
s matching the specifiedClass
located in the currentActivity
getCurrentViews
public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T>classToFilterBy, android.view.Viewparent)
- 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
orListView.class
-
parent
- the parentView
for where to start the traversal - Returns:
- an
ArrayList
ofView
s matching the specifiedClass
located under the specifiedparent
getCurrentViews
public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T>classToFilterBy, booleanincludeSubclasses, android.view.Viewparent)
- 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
orListView.class
-
includeSubclasses
- include instances of subclasses in theArrayList
that will be returned -
parent
- the parentView
for where to start the traversal - Returns:
- an
ArrayList
ofView
s matching the specifiedClass
located under the specifiedparent
getWebElements
public ArrayList<WebElement> getWebElements()
- Returns an ArrayList of all the WebElements displayed in the active WebView.
-
- Returns:
- an
ArrayList
of all theWebElement
objects currently displayed in the active WebView
getWebElements
public ArrayList<WebElement> getWebElements(Byby)
- 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")
andBy.name("name")
- Returns:
- an
ArrayList
of all theWebElement
objects displayed in the active WebView
getCurrentWebElements
public ArrayList<WebElement> getCurrentWebElements()
- Returns an ArrayList of the currently displayed WebElements in the active WebView.
-
- Returns:
- an
ArrayList
of theWebElement
objects displayed in the active WebView
getCurrentWebElements
public ArrayList<WebElement> getCurrentWebElements(Byby)
- 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")
andBy.name("name")
- Returns:
- an
ArrayList
of theWebElement
objects currently displayed in the active WebView
isRadioButtonChecked
public boolean isRadioButtonChecked(intindex)
- Checks if a RadioButton matching the specified index is checked.
-
- Parameters:
-
index
- of theRadioButton
to check.0
if only one is available - Returns:
-
true
ifRadioButton
is checked andfalse
if it is not checked
isRadioButtonChecked
public boolean isRadioButtonChecked(Stringtext)
- Checks if a RadioButton displaying the specified text is checked.
-
- Parameters:
-
text
- the text that theRadioButton
displays, specified as a regular expression - Returns:
-
true
if aRadioButton
matching the specified text is checked andfalse
if it is not checked
isCheckBoxChecked
public boolean isCheckBoxChecked(intindex)
- Checks if a CheckBox matching the specified index is checked.
-
- Parameters:
-
index
- of theCheckBox
to check.0
if only one is available - Returns:
-
true
ifCheckBox
is checked andfalse
if it is not checked
isToggleButtonChecked
public boolean isToggleButtonChecked(Stringtext)
- Checks if a ToggleButton displaying the specified text is checked.
-
- Parameters:
-
text
- the text that theToggleButton
displays, specified as a regular expression - Returns:
-
true
if aToggleButton
matching the specified text is checked andfalse
if it is not checked
isToggleButtonChecked
public boolean isToggleButtonChecked(intindex)
- Checks if a ToggleButton matching the specified index is checked.
-
- Parameters:
-
index
- of theToggleButton
to check.0
if only one is available - Returns:
-
true
ifToggleButton
is checked andfalse
if it is not checked
isCheckBoxChecked
public boolean isCheckBoxChecked(Stringtext)
- Checks if a CheckBox displaying the specified text is checked.
-
- Parameters:
-
text
- the text that theCheckBox
displays, specified as a regular expression - Returns:
-
true
if aCheckBox
displaying the specified text is checked andfalse
if it is not checked
isTextChecked
public boolean isTextChecked(Stringtext)
- Checks if the specified text is checked.
-
- Parameters:
-
text
- the text that theCheckedTextView
orCompoundButton
objects display, specified as a regular expression - Returns:
-
true
if the specified text is checked andfalse
if it is not checked
isSpinnerTextSelected
public boolean isSpinnerTextSelected(Stringtext)
- 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 expression - Returns:
-
true
if the specified text is selected in anySpinner
and false if it is not
isSpinnerTextSelected
public boolean isSpinnerTextSelected(intindex, Stringtext)
- 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 available -
text
- the text that is expected to be selected, specified as a regular expression - Returns:
-
true
if the specified text is selected in the specifiedSpinner
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(intkey)
- Sends a key: Right, Left, Up, Down, Enter, Menu or Delete.
-
- Parameters:
-
key
- the key to be sent. UseSolo.
RIGHT
,LEFT
,UP
,DOWN
,ENTER
,MENU
,DELETE
goBackToActivity
public void goBackToActivity(Stringname)
- Returns to an Activity matching the specified name.
-
- Parameters:
-
name
- the name of theActivity
to return to. Example is:"MyActivity"
waitForActivity
public boolean waitForActivity(Stringname)
- Waits for an Activity matching the specified name. Default timeout is 20 seconds.
-
- Parameters:
-
name
- the name of theActivity
to wait for. Example is:"MyActivity"
- Returns:
-
true
ifActivity
appears before the timeout andfalse
if it does not
waitForActivity
public boolean waitForActivity(Stringname, inttimeout)
- Waits for an Activity matching the specified name.
-
- Parameters:
-
name
- the name of theActivity
to wait for. Example is:"MyActivity"
-
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
ifActivity
appears before the timeout andfalse
if it does not
waitForActivity
public boolean waitForActivity(Class<? extends android.app.Activity>activityClass)
- Waits for an Activity matching the specified class. Default timeout is 20 seconds.
-
- Parameters:
-
activityClass
- the class of theActivity
to wait for. Example is:MyActivity.class
- Returns:
-
true
ifActivity
appears before the timeout andfalse
if it does not
waitForActivity
public boolean waitForActivity(Class<? extends android.app.Activity>activityClass, inttimeout)
- Waits for an Activity matching the specified class.
-
- Parameters:
-
activityClass
- the class of theActivity
to wait for. Example is:MyActivity.class
-
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
ifActivity
appears before the timeout andfalse
if it does not
waitForEmptyActivityStack
public boolean waitForEmptyActivityStack(inttimeout)
- Wait for the activity stack to be empty.
-
- Parameters:
-
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if activity stack is empty before the timeout andfalse
if it is not
waitForFragmentByTag
public boolean waitForFragmentByTag(Stringtag)
- Waits for a Fragment matching the specified tag. Default timeout is 20 seconds.
-
- Parameters:
-
tag
- the name of the tag - Returns:
-
true
if fragment appears andfalse
if it does not appear before the timeout
waitForFragmentByTag
public boolean waitForFragmentByTag(Stringtag, inttimeout)
- Waits for a Fragment matching the specified tag.
-
- Parameters:
-
tag
- the name of the tag -
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if fragment appears andfalse
if it does not appear before the timeout
waitForFragmentById
public boolean waitForFragmentById(intid)
- Waits for a Fragment matching the specified resource id. Default timeout is 20 seconds.
-
- Parameters:
-
id
- the R.id of the fragment - Returns:
-
true
if fragment appears andfalse
if it does not appear before the timeout
waitForFragmentById
public boolean waitForFragmentById(intid, inttimeout)
- Waits for a Fragment matching the specified resource id.
-
- Parameters:
-
id
- the R.id of the fragment -
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if fragment appears andfalse
if it does not appear before the timeout
waitForLogMessage
public boolean waitForLogMessage(StringlogMessage)
- 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 for - Returns:
-
true
if log message appears andfalse
if it does not appear before the timeout - See Also:
-
clearLog()
waitForLogMessage
public boolean waitForLogMessage(StringlogMessage, inttimeout)
- 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 for -
timeout
- the amount of time in milliseconds to wait - Returns:
-
true
if log message appears andfalse
if it does not appear before the timeout - See Also:
-
clearLog()
clearLog
public void clearLog()
- Clears the log.
-
getString
public String getString(intid)
- Returns a localized String matching the specified resource id.
-
- Parameters:
-
id
- the R.id of the String - Returns:
- the localized String
getString
public String getString(Stringid)
- Returns a localized String matching the specified resource id.
-
- Parameters:
-
id
- the id of the String - Returns:
- the localized String
sleep
public void sleep(inttime)
- 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 classObject
-
- 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 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(Stringname)
- 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(Stringname, intquality)
- 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 screenshot -
quality
- the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality)
startScreenshotSequence
public void startScreenshotSequence(Stringname)
- 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(Stringname, intquality, intframeDelay, intmaxFrames)
- 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 screenshot -
quality
- the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality) -
frameDelay
- the time in milliseconds to wait between each frame -
maxFrames
- 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<NotesList>{private Solo solo;public NotePadTest() {super(NotesList.class);}@Overridepublic 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());}@Overridepublic 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 screensolo.unlockScreen();solo.clickOnMenuItem("Add note");//Assert that NoteEditor activity is openedsolo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");//In text field 0, enter Note 1solo.enterText(0, "Note 1");solo.goBack();//Clicks on menu itemsolo.clickOnMenuItem("Add note");//In text field 0, type Note 2solo.typeText(0, "Note 2");//Go back to first activitysolo.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 foundassertTrue("Note 1 and/or Note 2 are not found", notesFound);}public void testEditNote() throws Exception {// Click on the second list linesolo.clickInList(2); //Hides the soft keyboardsolo.hideSoftKeyboard();// Change orientation of activitysolo.setActivityOrientation(Solo.LANDSCAPE);// Change titlesolo.clickOnMenuItem("Edit title");//In first text field (0), add testsolo.enterText(0, " test");solo.goBack();solo.setActivityOrientation(Solo.PORTRAIT);// (Regexp) case insensitiveboolean noteFound = solo.waitForText("(?i).*?note 1 test"); //Assert that Note 1 test is foundassertTrue("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 testsolo.clickOnMenuItem("Delete");//Note 1 test should not be foundboolean noteFound = solo.searchText("Note 1 test");//Assert that Note 1 test is not foundassertFalse("Note 1 Test is found", noteFound); solo.clickLongOnText("Note 2");//Clicks on Delete in the context menusolo.clickOnText("Delete"); //Will wait 100 milliseconds for the text: "Note 2"noteFound = solo.waitForText("Note 2", 1, 100);//Assert that Note 2 is not foundassertFalse("Note 2 is found", noteFound); }}
4、总结:
后续将介绍 Android CodeCoverage
更多相关文章
- android Instrumentation
- Android中遍历文件夹、比较文件类型测试
- Android(安卓)本地推送消息到通知栏 NotificationManager 、注册
- Android自动化测试之MonkeyRunner之MonkeyRunner(九)
- Android单元测试Unable to find instrumentation target package
- Android(安卓)CTS(兼容性测试)
- 四极管:Android操作系统的结构
- Android的多媒体框架OpenCore(PacketVideo)介绍
- Andrid 控件集合大全