com.baidu.cafe.local
Class LocalLib

java.lang.Object
  extended by com.jayway.android.robotium.solo.Solo
      extended by com.baidu.cafe.local.LocalLib

public class LocalLib
extends com.jayway.android.robotium.solo.Solo

It can help you as below. 1.get or set a object's private property and invoke a object's private function 2.find view by text or resid 3.get views which is generated dynamically 4.record human operations and generate Cafe codes


Nested Class Summary
static interface LocalLib.WaitCallBack
           
 
Field Summary
protected  java.lang.Object mActivitiyUtils
           
protected  java.lang.Object mAsserter
           
protected  java.lang.Object mChecker
           
protected  java.lang.Object mClicker
           
protected  java.lang.Object mDialogUtils
           
static android.app.Instrumentation mInstrumentation
           
static java.lang.String mPackageName
           
protected  java.lang.Object mPresser
           
protected  java.lang.Object mScroller
           
protected  java.lang.Object mSearcher
           
protected  java.lang.Object mSender
           
protected  java.lang.Object mSetter
           
protected  java.lang.Object mSleeper
           
static java.lang.String mTestCaseName
           
protected  java.lang.Object mTextEnterer
           
static int[] mTheLastClick
           
protected static java.lang.Object mViewFetcher
           
protected  java.lang.Object mWaiter
           
protected  java.lang.Object mWebUtils
           
static int SEARCHMODE_COMPLETE_MATCHING
           
static int SEARCHMODE_DEFAULT
           
static int SEARCHMODE_INCLUDE_MATCHING
           
static int WAIT_INTERVAL
           
 
Fields inherited from class com.jayway.android.robotium.solo.Solo
activityUtils, asserter, checker, clicker, CLOSED, DELETE, dialogUtils, DOWN, ENTER, getter, instrumentation, LANDSCAPE, LEFT, MENU, OPENED, PORTRAIT, presser, RIGHT, screenshotTaker, scroller, searcher, sender, setter, sleeper, textEnterer, UP, viewFetcher, waiter, webUrl, webUtils
 
Constructor Summary
LocalLib(android.app.Instrumentation instrumentation, android.app.Activity activity)
           
 
Method Summary
 void beginRecordCode()
          add listeners on all views for generating Cafe code automatically
 void clickInListWithFamilyString(int position, java.lang.String familyString)
           
 void clickOn(java.lang.String className, java.lang.String familyString, boolean longClick)
          Clicks on a View of a specific class, with a certain familyString.
 boolean clickOnExpandableListView(java.lang.String familyString, int flatListPosition)
           
 void clickOnScreenDown()
          click on screen, the point is on the down
 void clickOnScreenLeft()
          click on screen, the point is on the left
 void clickOnScreenRight()
          click on screen, the point is on the right
 void clickOnScreenUp()
          click on screen, the point is on the up
 void clickOnTab(int index, int item)
          Click on a tab with a certain item
 void clickOnViewWithoutScroll(android.view.View view, boolean longClick)
           
 void clickOnWebElementByFamilyString(java.lang.String familyString)
          Clicks on the WebElement by the given family string.
 void clickViaPerformClick(android.view.View view, boolean longClick)
           
 boolean clickViewById(java.lang.String resId)
          click a specified view
 boolean clickViewById(java.lang.String resId, int index)
           
 void clickViewWithoutAssert(android.view.View view)
           
 int countLevelFromViewToFather(android.view.View view, java.lang.Class<?> father)
          find parent until parent is father or java.lang.Object(to the end)
 void dragPercent(float fromXPersent, float toXPersent, float fromYPersent, float toYPersent, int stepCount)
          Simulate touching a specific location and dragging to a new location.
 void dragScreenToDown(int stepCount)
          drag on screen to Down
 void dragScreenToLeft(int stepCount)
          drag on screen to Left
 void dragScreenToRight(int stepCount)
          drag on screen to right
 void dragScreenToUp(int stepCount)
          drag on screen to up
 void dumpActivityText(boolean saveDuplicate)
          dump text of activity including webview
 void dumpPage()
           
 void enterText(java.lang.String familyString, java.lang.String text, boolean keepPreviousText)
          Sets an EditText text
 void enterTextInWebElementByFamilyString(java.lang.String familyString, java.lang.String text)
          Enters text in a WebElement by family string
static com.baidu.cafe.utils.ShellExecute.CommandResult executeOnDevice(java.lang.String command, java.lang.String directory)
          run shell command with tested app's permission
static com.baidu.cafe.utils.ShellExecute.CommandResult executeOnDevice(java.lang.String command, java.lang.String directory, long timeout)
          run shell command with tested app's permission
 void finalize()
           
 java.util.ArrayList<android.view.View> findViewsByText(java.lang.String text)
          Deprecated. 
 android.content.pm.ActivityInfo[] getActivitiesFromPackage(java.lang.String packageName)
           
 android.app.Activity getActivityAsync(java.lang.String activityName)
          you can use this function when getActivtiy is hang.
 java.util.ArrayList<java.lang.String> getAllClassNamesFromPackage(java.lang.String packageName)
          get all class names from a package via its dex file
 java.lang.String getAppNameByPID(int pid)
           
 java.util.ArrayList<android.widget.TabWidget> getCurrentTabs()
          Returns an ArrayList with the Tab located in the current activity
 int getCurrentViewIndex(android.view.View view)
          get view index by its class at current activity
<T extends android.view.View>
java.util.ArrayList<T>
getCurrentViews(java.lang.Class<T> classToFilterBy, boolean visible)
           
 float getDisplayX()
           
 float getDisplayY()
           
static double getDistance(float x1, float y1, float x2, float y2)
           
 java.lang.String getFamilyString(android.view.View v)
           
protected  java.lang.Object getField(java.lang.Object arg0, java.lang.String arg1)
           
 android.view.View getFocusView(java.util.ArrayList<android.view.View> views)
           
 android.app.Instrumentation getInstrumentation()
           
 java.lang.Object getListener(android.view.View view, java.lang.Class<?> targetClass, java.lang.String fieldName)
          Get listener from view.
 void getNewViewsBegin()
          call this function before new views appear
 java.util.ArrayList<android.view.View> getNewViewsEnd()
          call this function after new views appear
static java.lang.Object getObjectProperty(java.lang.Object owner, int classLevel, java.lang.String fieldName)
          get object's private property
static int getPackageRcv(java.lang.String packageName)
          count how many bytes from tcp app received until now
static int getPackageSnd(java.lang.String packageName)
          count how many bytes from tcp app sent until now
static java.util.ArrayList<java.lang.String> getPropertyNameByType(java.lang.Object owner, int classLevel, java.lang.Class<?> type)
          get object's private property by type
static java.util.ArrayList<java.lang.String> getPropertyNameByValue(java.lang.Object owner, int classLevel, java.lang.Class<?> valueType, java.lang.Object value)
           
 android.view.View getRecentDecorView()
           
static android.view.View getRecentDecorView(android.view.View[] views)
          Returns the most recent DecorView
 java.lang.String getRIdNameByValue(java.lang.String packageName, int value)
           
 java.lang.String getStringFromArguments(java.lang.String key)
           
 android.widget.TabWidget getTab(int index)
          This method returns a tab with a certain index.
 java.lang.String getTestedRString(java.lang.String stringName)
          Deprecated. 
 java.lang.String getTestRString(java.lang.String stringName)
          get R.string.yourTargetString from test package
 android.view.View getViewByFamilyString(java.lang.String familyString, java.lang.String className)
          This method is protected by assert.
 android.view.View getViewById(java.lang.String resId)
          Get view by ID
 android.view.View getViewById(java.lang.String resId, int index)
          Get view by ID
 android.view.View getViewById(java.lang.String resId, int index, int searchMode)
          Get View By Id
 android.view.View getViewByRString(java.lang.String R)
           
static int[] getViewCenter(android.view.View view)
           
<T extends android.view.View>
java.util.ArrayList<T>
getViews(java.lang.Class<T> classToFilterBy, boolean onlySufficientlyVisible)
           
 java.lang.String getViewText(android.view.View view)
           
 java.util.ArrayList<java.lang.String> getWebElementsString()
           
static android.view.View[] getWindowDecorViews()
          Returns the WindorDecorViews shown on the screen
 void hideInputMethod()
           
 void hideInputMethod(android.widget.EditText editText)
           
protected static java.lang.Object invoke(java.lang.Object arg0, java.lang.String arg1)
           
protected static java.lang.Object invoke(java.lang.Object arg0, java.lang.String arg1, java.lang.Class<?>[] arg2, java.lang.Object[] arg3)
           
 java.lang.Object invokeObjectMethod(java.lang.Object owner, int classLevel, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameters)
          invoke object's private method
 void isInputMethodShown()
           
 boolean isInScreen(android.view.View view)
           
 boolean isMenu(android.view.View view)
           
 boolean isScrollStoped(android.widget.ScrollView scrollView)
          This method will cost 100ms to judge whether scrollview stoped.
 boolean isSize0(android.view.View view)
           
 boolean isViewCovered(android.view.View view)
           
<T extends android.view.View>
java.util.ArrayList<T>
removeInvisibleViews(java.util.ArrayList<T> viewList)
           
<T extends android.view.View>
java.util.ArrayList<T>
removeOutOfScreenViews(java.util.ArrayList<T> viewList)
           
 boolean requestFocus(android.view.View view)
           
 void runOnMainSync(java.lang.Runnable r)
           
 void runOnUiThread(java.lang.Runnable r)
           
 void screenShot(java.lang.String fileName)
           
 void screenShotNamedCaseName(java.lang.String suffix)
           
 void screenShotNamedSuffix(java.lang.String suffix)
           
 void screenShotNamedTimeStamp()
          Take an activity snapshot named 'timestamp', and you can get it by adb pull /data/data//xxxxx.jpg .
 void scrollListToLineWithFamilyString(int line, java.lang.String familyString)
           
 void scrollScrollViewToWithFamilyString(java.lang.String familyString, int x, int y)
           
 boolean searchTextFromParent(android.view.View parent, java.lang.String text, int searchMode)
          Search text from parent view
 void sendMultiTouchMotionEvent(int pointerNumber, int[] start, int[] end, int step, int downDelay, int moveDelay, int upDelay)
          send a Multi-Touch Motion Event
 boolean setCheckedTextView(int index, boolean checked)
          set CheckedTextView checked or not
 void setListener(android.view.View view, java.lang.Class<?> targetClass, java.lang.String fieldName, java.lang.Object value)
          This method is used to replace listener.setOnListener().
 void setObjectProperty(java.lang.Object owner, int classLevel, java.lang.String fieldName, java.lang.Object value)
          set object's private property with custom value
 void showInputMethod(android.widget.EditText editText)
           
 void takeActivitySnapshot(java.lang.String path)
          Take an activity snapshot.
 void takeWebViewSnapshot(android.webkit.WebView webView, java.lang.String savePath)
           
 float toPercentX(float x)
           
 float toPercentY(float y)
           
 float toScreenX(float persent)
           
 float toScreenY(float persent)
           
 void traceFPS()
          print FPS of current activity at logcat with TAG FPS
 void travel()
           
 void travel(int depth)
           
 void travel(int depth, java.lang.String username, java.lang.String password)
           
 boolean waitEqual(java.lang.String expect, LocalLib.WaitCallBack callBack)
          Waits for value from WaitCallBack.getActualVaule() equaling to expect value until time is out.
 boolean waitEqual(java.lang.String expect, LocalLib.WaitCallBack callBack, long timeout)
          Waits for value from WaitCallBack.getActualVaule() equaling to expect value until time is out.
 void waitForTextByFamilyString(java.lang.String familyString, java.lang.String text)
          This method is protected by assert.
 boolean waitForTextVanish(java.lang.String text)
          Waits for a text to vanish.
 boolean waitForTextVanish(java.lang.String text, int minimumNumberOfMatches)
          Waits for a text to vanish.
 boolean waitForTextVanish(java.lang.String text, int minimumNumberOfMatches, long timeout)
          Waits for a text to vanish.
 boolean waitForTextVanish(java.lang.String text, int minimumNumberOfMatches, long timeout, boolean scroll)
          Waits for a text to vanish.
 boolean waitForView(java.lang.String className, int index, int timeout, boolean scroll)
           
 android.view.View waitForViewByFamilyString(java.lang.String familyString, java.lang.String className)
          This method is protected by assert.
 boolean waitforViewById(java.lang.String resId)
          wait for a specified view
 boolean waitforViewById(java.lang.String resId, long timeout)
          wait for a specified view
 boolean waitforViewById(java.lang.String resId, long timeout, boolean scroll)
          wait for a specified view
 boolean waitforViewById(java.lang.String resId, long timeout, boolean scroll, boolean onlyVisible)
          wait for a specified view
 boolean waitForViewVanishById(java.lang.String resId)
          Waits for a view to vanish
 boolean waitForViewVanishById(java.lang.String resId, long timeout)
          Waits for a view to vanish
 boolean waitForViewVanishById(java.lang.String resId, long timeout, boolean scroll)
          Waits for a view to vanish
 boolean waitForViewVanishById(java.lang.String resId, long timeout, boolean scroll, boolean onlyvisible)
          Waits for a view vanished
 com.jayway.android.robotium.solo.WebElement waitForWebElementByFamilyString(java.lang.String familyString, int timeout, boolean scroll)
          Waits for a WebElement by family string.
 void zoom(int[] start, int[] end)
          zoom screen
 
Methods inherited from class com.jayway.android.robotium.solo.Solo
assertCurrentActivity, assertCurrentActivity, assertCurrentActivity, assertCurrentActivity, assertMemoryNotLow, clearEditText, clearEditText, clearTextInWebElement, clickInList, clickInList, clickLongInList, clickLongInList, clickLongInList, clickLongOnScreen, clickLongOnScreen, clickLongOnText, clickLongOnText, clickLongOnText, clickLongOnText, clickLongOnTextAndPress, clickLongOnView, clickLongOnView, clickOnActionBarHomeButton, clickOnActionBarItem, clickOnButton, clickOnButton, clickOnCheckBox, clickOnEditText, clickOnImage, clickOnImageButton, clickOnMenuItem, clickOnMenuItem, clickOnRadioButton, clickOnScreen, clickOnText, clickOnText, clickOnText, clickOnToggleButton, clickOnView, clickOnView, clickOnWebElement, clickOnWebElement, clickOnWebElement, clickOnWebElement, drag, enterText, enterText, enterTextInWebElement, finishOpenedActivities, getActivityMonitor, getButton, getButton, getButton, getCurrentActivity, getCurrentViews, getCurrentViews, getCurrentViews, getCurrentWebElements, getCurrentWebElements, getEditText, getEditText, getEditText, getImage, getImageButton, getString, getText, getText, getText, getTopParent, getView, getView, getView, getViews, getViews, getWebElement, getWebUrl, goBack, goBackToActivity, hideSoftKeyboard, isCheckBoxChecked, isCheckBoxChecked, isRadioButtonChecked, isRadioButtonChecked, isSpinnerTextSelected, isSpinnerTextSelected, isTextChecked, isToggleButtonChecked, isToggleButtonChecked, pressMenuItem, pressMenuItem, pressSpinnerItem, scrollDown, scrollDownList, scrollDownList, scrollListToBottom, scrollListToBottom, scrollListToLine, scrollListToLine, scrollListToTop, scrollListToTop, scrollToBottom, scrollToSide, scrollToTop, scrollUp, scrollUpList, scrollUpList, scrollViewToSide, searchButton, searchButton, searchButton, searchButton, searchEditText, searchText, searchText, searchText, searchText, searchText, searchToggleButton, searchToggleButton, sendKey, setActivityOrientation, setDatePicker, setDatePicker, setProgressBar, setProgressBar, setSlidingDrawer, setSlidingDrawer, setTimePicker, setTimePicker, sleep, takeScreenshot, takeScreenshot, takeScreenshot, typeText, typeText, typeTextInWebElement, typeTextInWebElement, typeTextInWebElement, waitForActivity, waitForActivity, waitForActivity, waitForActivity, waitForCondition, waitForDialogToClose, waitForDialogToOpen, waitForFragmentById, waitForFragmentById, waitForFragmentByTag, waitForFragmentByTag, waitForLogMessage, waitForLogMessage, waitForText, waitForText, waitForText, waitForText, waitForView, waitForView, waitForView, waitForView, waitForView, waitForWebElement, waitForWebElement, waitForWebElement
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCHMODE_COMPLETE_MATCHING

public static final int SEARCHMODE_COMPLETE_MATCHING
See Also:
Constant Field Values

SEARCHMODE_DEFAULT

public static final int SEARCHMODE_DEFAULT
See Also:
Constant Field Values

SEARCHMODE_INCLUDE_MATCHING

public static final int SEARCHMODE_INCLUDE_MATCHING
See Also:
Constant Field Values

WAIT_INTERVAL

public static final int WAIT_INTERVAL
See Also:
Constant Field Values

mTestCaseName

public static java.lang.String mTestCaseName

mPackageName

public static java.lang.String mPackageName

mTheLastClick

public static int[] mTheLastClick

mInstrumentation

public static android.app.Instrumentation mInstrumentation

mAsserter

protected java.lang.Object mAsserter

mViewFetcher

protected static java.lang.Object mViewFetcher

mChecker

protected java.lang.Object mChecker

mClicker

protected java.lang.Object mClicker

mPresser

protected java.lang.Object mPresser

mSearcher

protected java.lang.Object mSearcher

mActivitiyUtils

protected java.lang.Object mActivitiyUtils

mDialogUtils

protected java.lang.Object mDialogUtils

mTextEnterer

protected java.lang.Object mTextEnterer

mScroller

protected java.lang.Object mScroller

mSleeper

protected java.lang.Object mSleeper

mWaiter

protected java.lang.Object mWaiter

mSetter

protected java.lang.Object mSetter

mWebUtils

protected java.lang.Object mWebUtils

mSender

protected java.lang.Object mSender
Constructor Detail

LocalLib

public LocalLib(android.app.Instrumentation instrumentation,
                android.app.Activity activity)
Method Detail

invokeObjectMethod

public java.lang.Object invokeObjectMethod(java.lang.Object owner,
                                           int classLevel,
                                           java.lang.String methodName,
                                           java.lang.Class<?>[] parameterTypes,
                                           java.lang.Object[] parameters)
                                    throws java.lang.SecurityException,
                                           java.lang.NoSuchMethodException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException
invoke object's private method

Parameters:
owner - : target object
classLevel - : 0 means itself, 1 means it's father, and so on...
methodName - : name of the target method
parameterTypes - : types of the target method's parameters
parameters - : parameters of the target method
Returns:
result of invoked method
Throws:
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

setObjectProperty

public void setObjectProperty(java.lang.Object owner,
                              int classLevel,
                              java.lang.String fieldName,
                              java.lang.Object value)
                       throws java.lang.SecurityException,
                              java.lang.NoSuchFieldException,
                              java.lang.IllegalArgumentException,
                              java.lang.IllegalAccessException
set object's private property with custom value

Parameters:
owner - : target object
classLevel - : 0 means itself, 1 means it's father, and so on...
fieldName - : name of the target field
value - : new value of the target field
Throws:
java.lang.NoSuchFieldException
java.lang.SecurityException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

getObjectProperty

public static java.lang.Object getObjectProperty(java.lang.Object owner,
                                                 int classLevel,
                                                 java.lang.String fieldName)
                                          throws java.lang.SecurityException,
                                                 java.lang.NoSuchFieldException,
                                                 java.lang.IllegalArgumentException,
                                                 java.lang.IllegalAccessException
get object's private property

Parameters:
owner - : target object
classLevel - : 0 means itself, 1 means it's father, and so on...
fieldName - : name of the target field
Returns:
value of the target field
Throws:
java.lang.NoSuchFieldException
java.lang.SecurityException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

getPropertyNameByType

public static java.util.ArrayList<java.lang.String> getPropertyNameByType(java.lang.Object owner,
                                                                          int classLevel,
                                                                          java.lang.Class<?> type)
get object's private property by type

Parameters:
owner - target object
classLevel - 0 means itself, 1 means it's father, and so on...
typeString - e.g. java.lang.String
Returns:
ArrayList of property's name

getPropertyNameByValue

public static java.util.ArrayList<java.lang.String> getPropertyNameByValue(java.lang.Object owner,
                                                                           int classLevel,
                                                                           java.lang.Class<?> valueType,
                                                                           java.lang.Object value)
                                                                    throws java.lang.IllegalArgumentException,
                                                                           java.lang.IllegalAccessException
Parameters:
owner - target object
classLevel - 0 means itself, 1 means it's father, and so on...
valueType - e.g. String.class
value - value of the target fields
Returns:
ArrayList of property's name
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException

beginRecordCode

public void beginRecordCode()
add listeners on all views for generating Cafe code automatically


getListener

public java.lang.Object getListener(android.view.View view,
                                    java.lang.Class<?> targetClass,
                                    java.lang.String fieldName)
Get listener from view. e.g. (OnClickListener) getListener(view, "mOnClickListener"); means get click listener. Listener is a private property of a view, that's why this function is written.

Parameters:
view - target view
targetClass - the class which fieldName belong to
fieldName - target listener. e.g. mOnClickListener, mOnLongClickListener, mOnTouchListener, mOnKeyListener
Returns:
listener object; null means no listeners has been found

setListener

public void setListener(android.view.View view,
                        java.lang.Class<?> targetClass,
                        java.lang.String fieldName,
                        java.lang.Object value)
This method is used to replace listener.setOnListener(). listener.setOnListener() is probably overrided by application, so its behavior can not be expected.

Parameters:
view -
targetClass -
fieldName -
value -

countLevelFromViewToFather

public int countLevelFromViewToFather(android.view.View view,
                                      java.lang.Class<?> father)
find parent until parent is father or java.lang.Object(to the end)

Parameters:
view - target view
father - target father
Returns:
positive means level from father; -1 means not found

getViewText

public java.lang.String getViewText(android.view.View view)

findViewsByText

@Deprecated
public java.util.ArrayList<android.view.View> findViewsByText(java.lang.String text)
Deprecated. 

find views via view's text, it only needs part of target view's text

Parameters:
text - the text of the view
Returns:
a ArrayList contains views found

getNewViewsBegin

public void getNewViewsBegin()
call this function before new views appear


getNewViewsEnd

public java.util.ArrayList<android.view.View> getNewViewsEnd()
call this function after new views appear

Returns:
A ArrayList contains views which are new. Null means no new views

getRIdNameByValue

public java.lang.String getRIdNameByValue(java.lang.String packageName,
                                          int value)

getTestRString

public java.lang.String getTestRString(java.lang.String stringName)
get R.string.yourTargetString from test package

Parameters:
stringName - name of your target string
Returns:
string value

getTestedRString

@Deprecated
public java.lang.String getTestedRString(java.lang.String stringName)
Deprecated. 

get R.string.yourTargetString from tested package

Parameters:
stringName - name of your target string
Returns:
string value

getActivityAsync

public android.app.Activity getActivityAsync(java.lang.String activityName)
you can use this function when getActivtiy is hang. when you want to reinit solo you should recall public void init(Activity macy)

Parameters:
activityName - example: the activity "TestAcy" you wanted, the param is "TestAcy.class.getName()"
Returns:
activity

executeOnDevice

public static com.baidu.cafe.utils.ShellExecute.CommandResult executeOnDevice(java.lang.String command,
                                                                              java.lang.String directory)
run shell command with tested app's permission

Parameters:
command - e.g. new String[]{"ls", "-l"}
directory - e.g. "/sdcard"
Returns:
the result string of the command

executeOnDevice

public static com.baidu.cafe.utils.ShellExecute.CommandResult executeOnDevice(java.lang.String command,
                                                                              java.lang.String directory,
                                                                              long timeout)
run shell command with tested app's permission

Parameters:
command - e.g. new String[]{"ls", "-l"}
directory - e.g. "/sdcard"
timeout - Millis. e.g. 5000 means 5s
Returns:
the result string of the command

waitForViewVanishById

public boolean waitForViewVanishById(java.lang.String resId)
Waits for a view to vanish

Parameters:
resId - the id you see in hierarchy . for example in Launcher "id/workspace" timeout is default 8000 scroll is default true only visible is default true
Returns:
true we get it

waitForViewVanishById

public boolean waitForViewVanishById(java.lang.String resId,
                                     long timeout)
Waits for a view to vanish

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
timeout - the delay milliseconds scroll is default true only visible is default true
Returns:
true we get it

waitForViewVanishById

public boolean waitForViewVanishById(java.lang.String resId,
                                     long timeout,
                                     boolean scroll)
Waits for a view to vanish

Parameters:
resId - the id you see in hierarchy . for example in Launcher "id/workspace"
timeout - the delay milliseconds
scroll - true you want to scroll onlyvisible is default true
Returns:
true we get it

waitForViewVanishById

public boolean waitForViewVanishById(java.lang.String resId,
                                     long timeout,
                                     boolean scroll,
                                     boolean onlyvisible)
Waits for a view vanished

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
timeout - the delay milliseconds
scroll - true you want to scroll
onlyvisible - true we only deal with the view visible
Returns:
true we get it

waitForTextVanish

public boolean waitForTextVanish(java.lang.String text)
Waits for a text to vanish.

Parameters:
text - the text to wait for
Returns:
true if text is shown and false if it is not shown before the timeout

waitForTextVanish

public boolean waitForTextVanish(java.lang.String text,
                                 int minimumNumberOfMatches)
Waits for a text to vanish.

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

waitForTextVanish

public boolean waitForTextVanish(java.lang.String text,
                                 int minimumNumberOfMatches,
                                 long timeout)
Waits for a text to vanish.

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

waitForTextVanish

public boolean waitForTextVanish(java.lang.String text,
                                 int minimumNumberOfMatches,
                                 long timeout,
                                 boolean scroll)
Waits for a text to vanish.

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

waitEqual

public boolean waitEqual(java.lang.String expect,
                         LocalLib.WaitCallBack callBack)
Waits for value from WaitCallBack.getActualVaule() equaling to expect value until time is out.

Parameters:
expect -
callBack -
Returns:
true: WaitCallBack.getActualVaule() equals to expectation; false: WaitCallBack.getActualVaule() differs from expectation

waitEqual

public boolean waitEqual(java.lang.String expect,
                         LocalLib.WaitCallBack callBack,
                         long timeout)
Waits for value from WaitCallBack.getActualVaule() equaling to expect value until time is out.

Parameters:
expect -
callBack -
timeout -
Returns:
true: WaitCallBack.getActualVaule() equals to expectation; false: WaitCallBack.getActualVaule() differs from expectation

zoom

public void zoom(int[] start,
                 int[] end)
zoom screen

Parameters:
start - the start position e.g. new int[]{0,0,1,2}; means two pointers start at {0,0} and {1,2}
end - the end position e.g. new int[]{100,110,200,220}; means two pointers end at {100,110} and {200,220}

sendMultiTouchMotionEvent

public void sendMultiTouchMotionEvent(int pointerNumber,
                                      int[] start,
                                      int[] end,
                                      int step,
                                      int downDelay,
                                      int moveDelay,
                                      int upDelay)
send a Multi-Touch Motion Event

Parameters:
pointerNumber - the number of pointer
start - the start position e.g. new int[]{0,0,1,2}; means two pointers start at {0,0} and {1,2}
end - the end position e.g. new int[]{100,110,200,220}; means two pointers end at {100,110} and {200,220}
step - the move step
downDelay - the delay after down event was sent
moveDelay - the delay after each move event was sent
upDelay - the delay before sending up event

setCheckedTextView

public boolean setCheckedTextView(int index,
                                  boolean checked)
set CheckedTextView checked or not

Parameters:
index -
checked -
Returns:
if set ok return true

getCurrentTabs

public java.util.ArrayList<android.widget.TabWidget> getCurrentTabs()
Returns an ArrayList with the Tab located in the current activity

Returns:
ArrayList of the Tabs contained in the current activity

getTab

public android.widget.TabWidget getTab(int index)
This method returns a tab with a certain index.

Parameters:
index - the index of the Tab
Returns:
the tab with the specific index

clickOnTab

public void clickOnTab(int index,
                       int item)
Click on a tab with a certain item

Parameters:
index - the index of the tab
item - the item of the tab will be clicked

clickOnScreenRight

public void clickOnScreenRight()
click on screen, the point is on the right


clickOnScreenLeft

public void clickOnScreenLeft()
click on screen, the point is on the left


clickOnScreenUp

public void clickOnScreenUp()
click on screen, the point is on the up


clickOnScreenDown

public void clickOnScreenDown()
click on screen, the point is on the down


dragScreenToRight

public void dragScreenToRight(int stepCount)
drag on screen to right


dragScreenToLeft

public void dragScreenToLeft(int stepCount)
drag on screen to Left


dragScreenToUp

public void dragScreenToUp(int stepCount)
drag on screen to up


dragScreenToDown

public void dragScreenToDown(int stepCount)
drag on screen to Down


waitforViewById

public boolean waitforViewById(java.lang.String resId)
wait for a specified view

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace" timeout is default 3000 scroll is default true onlyVisible is default true
Returns:
true we get it

waitforViewById

public boolean waitforViewById(java.lang.String resId,
                               long timeout)
wait for a specified view

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
timeout - the delay millisecond scroll is default true onlyVisible is default true
Returns:
true we get it

waitforViewById

public boolean waitforViewById(java.lang.String resId,
                               long timeout,
                               boolean scroll)
wait for a specified view

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
timeout - the delay millisecond
scroll - true you want to scroll onlyVisible is default true
Returns:
true we get it

waitforViewById

public boolean waitforViewById(java.lang.String resId,
                               long timeout,
                               boolean scroll,
                               boolean onlyVisible)
wait for a specified view

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
timeout - the delay millisecond
scroll - true you want to scroll
onlyVisible - true we only deal with the view visible
Returns:
true we get it

clickViewById

public boolean clickViewById(java.lang.String resId)
click a specified view

Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
Returns:
true we got it

clickViewById

public boolean clickViewById(java.lang.String resId,
                             int index)
Parameters:
resId - the id you see in hierarchy. for example in Launcher "id/workspace"
index - Clicks on an resId with a given index.
Returns:
true we got it

getViewById

public android.view.View getViewById(java.lang.String resId)
Get view by ID

Parameters:
resId - resource ID
Returns:
null means not found

getViewById

public android.view.View getViewById(java.lang.String resId,
                                     int index)
Get view by ID

Parameters:
resId - resource ID
index - the index of views
Returns:
null means not found

getViewById

public android.view.View getViewById(java.lang.String resId,
                                     int index,
                                     int searchMode)
Get View By Id

Parameters:
resId -
index - the index of views
searchMode - include SEARCHMODE_COMPLETE_MATCHING, SEARCHMODE_DEFAULT and SEARCHMODE_INCLUDE_MATCHING
Returns:
null means not found

searchTextFromParent

public boolean searchTextFromParent(android.view.View parent,
                                    java.lang.String text,
                                    int searchMode)
Search text from parent view

Parameters:
parent - parent view
text - text you want to search
searchMode - include SEARCHMODE_COMPLETE_MATCHING, SEARCHMODE_DEFAULT and SEARCHMODE_INCLUDE_MATCHING
Returns:
true means found otherwise false

screenShotNamedTimeStamp

public void screenShotNamedTimeStamp()
Take an activity snapshot named 'timestamp', and you can get it by adb pull /data/data//xxxxx.jpg .


screenShotNamedCaseName

public void screenShotNamedCaseName(java.lang.String suffix)

screenShotNamedSuffix

public void screenShotNamedSuffix(java.lang.String suffix)

screenShot

public void screenShot(java.lang.String fileName)

takeWebViewSnapshot

public void takeWebViewSnapshot(android.webkit.WebView webView,
                                java.lang.String savePath)

takeActivitySnapshot

public void takeActivitySnapshot(java.lang.String path)
Take an activity snapshot.


getRecentDecorView

public android.view.View getRecentDecorView()

getAllClassNamesFromPackage

public java.util.ArrayList<java.lang.String> getAllClassNamesFromPackage(java.lang.String packageName)
get all class names from a package via its dex file

Parameters:
packageName - e.g. "com.baidu.chunlei.exercise.test"
Returns:
names of classes

hideInputMethod

public void hideInputMethod()

hideInputMethod

public void hideInputMethod(android.widget.EditText editText)

showInputMethod

public void showInputMethod(android.widget.EditText editText)

isInputMethodShown

public void isInputMethodShown()

getActivitiesFromPackage

public android.content.pm.ActivityInfo[] getActivitiesFromPackage(java.lang.String packageName)

getWindowDecorViews

public static android.view.View[] getWindowDecorViews()
Returns the WindorDecorViews shown on the screen

Returns:
the WindorDecorViews shown on the screen

getRecentDecorView

public static android.view.View getRecentDecorView(android.view.View[] views)
Returns the most recent DecorView

Parameters:
views - the views to check
Returns:
the most recent DecorView

traceFPS

public void traceFPS()
print FPS of current activity at logcat with TAG FPS


getPackageRcv

public static int getPackageRcv(java.lang.String packageName)
count how many bytes from tcp app received until now

Parameters:
packageName -
Returns:

getPackageSnd

public static int getPackageSnd(java.lang.String packageName)
count how many bytes from tcp app sent until now

Parameters:
packageName -
Returns:

getAppNameByPID

public java.lang.String getAppNameByPID(int pid)

getDisplayX

public float getDisplayX()

getDisplayY

public float getDisplayY()

toScreenX

public float toScreenX(float persent)

toScreenY

public float toScreenY(float persent)

toPercentX

public float toPercentX(float x)

toPercentY

public float toPercentY(float y)

removeInvisibleViews

public <T extends android.view.View> java.util.ArrayList<T> removeInvisibleViews(java.util.ArrayList<T> viewList)

requestFocus

public boolean requestFocus(android.view.View view)

isMenu

public boolean isMenu(android.view.View view)

getCurrentViews

public <T extends android.view.View> java.util.ArrayList<T> getCurrentViews(java.lang.Class<T> classToFilterBy,
                                                                            boolean visible)

clickOn

public void clickOn(java.lang.String className,
                    java.lang.String familyString,
                    boolean longClick)
Clicks on a View of a specific class, with a certain familyString. This method is protected by assert.

Parameters:
className - what kind of View to click, e.g. Button.class or ImageView.class
familyString - the family relationship of the View to be clicked
longClick - true means long click

getViews

public <T extends android.view.View> java.util.ArrayList<T> getViews(java.lang.Class<T> classToFilterBy,
                                                                     boolean onlySufficientlyVisible)

clickViaPerformClick

public void clickViaPerformClick(android.view.View view,
                                 boolean longClick)

clickOnViewWithoutScroll

public void clickOnViewWithoutScroll(android.view.View view,
                                     boolean longClick)

getViewCenter

public static int[] getViewCenter(android.view.View view)

getViewByFamilyString

public android.view.View getViewByFamilyString(java.lang.String familyString,
                                               java.lang.String className)
This method is protected by assert.


waitForViewByFamilyString

public android.view.View waitForViewByFamilyString(java.lang.String familyString,
                                                   java.lang.String className)
This method is protected by assert.

Parameters:
familyString -
className -
Returns:

waitForTextByFamilyString

public void waitForTextByFamilyString(java.lang.String familyString,
                                      java.lang.String text)
This method is protected by assert.

Parameters:
familyString -
text -

enterText

public void enterText(java.lang.String familyString,
                      java.lang.String text,
                      boolean keepPreviousText)
Sets an EditText text

Parameters:
familyString - the familyString of the EditText
text - the text that should be set

clickOnExpandableListView

public boolean clickOnExpandableListView(java.lang.String familyString,
                                         int flatListPosition)

runOnMainSync

public void runOnMainSync(java.lang.Runnable r)

runOnUiThread

public void runOnUiThread(java.lang.Runnable r)

getInstrumentation

public android.app.Instrumentation getInstrumentation()

getViewByRString

public android.view.View getViewByRString(java.lang.String R)
Parameters:
R -
Returns:

getFocusView

public android.view.View getFocusView(java.util.ArrayList<android.view.View> views)

isInScreen

public boolean isInScreen(android.view.View view)

removeOutOfScreenViews

public <T extends android.view.View> java.util.ArrayList<T> removeOutOfScreenViews(java.util.ArrayList<T> viewList)

scrollListToLineWithFamilyString

public void scrollListToLineWithFamilyString(int line,
                                             java.lang.String familyString)

scrollScrollViewToWithFamilyString

public void scrollScrollViewToWithFamilyString(java.lang.String familyString,
                                               int x,
                                               int y)

isViewCovered

public boolean isViewCovered(android.view.View view)
Parameters:
view -
Returns:

isScrollStoped

public boolean isScrollStoped(android.widget.ScrollView scrollView)
This method will cost 100ms to judge whether scrollview stoped.

Parameters:
scrollView -
Returns:

isSize0

public boolean isSize0(android.view.View view)

waitForView

public boolean waitForView(java.lang.String className,
                           int index,
                           int timeout,
                           boolean scroll)

getFamilyString

public java.lang.String getFamilyString(android.view.View v)

clickInListWithFamilyString

public void clickInListWithFamilyString(int position,
                                        java.lang.String familyString)

dragPercent

public void dragPercent(float fromXPersent,
                        float toXPersent,
                        float fromYPersent,
                        float toYPersent,
                        int stepCount)
Simulate touching a specific location and dragging to a new location. This method was copied from TouchUtils.java in the Android Open Source Project, and modified here.

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

getDistance

public static double getDistance(float x1,
                                 float y1,
                                 float x2,
                                 float y2)

getCurrentViewIndex

public int getCurrentViewIndex(android.view.View view)
get view index by its class at current activity

Parameters:
view -
Returns:
-1 means not found;otherwise is then index of view

waitForWebElementByFamilyString

public com.jayway.android.robotium.solo.WebElement waitForWebElementByFamilyString(java.lang.String familyString,
                                                                                   int timeout,
                                                                                   boolean scroll)
Waits for a WebElement by family string.

Parameters:
familyString - timeout how long the function waits if there is no satisfied web element scroll true if need to scroll the screen, false otherwise
Returns:
WebElement wait for

clickOnWebElementByFamilyString

public void clickOnWebElementByFamilyString(java.lang.String familyString)
Clicks on the WebElement by the given family string.

Parameters:
webElement - the WebElement to click

enterTextInWebElementByFamilyString

public void enterTextInWebElementByFamilyString(java.lang.String familyString,
                                                java.lang.String text)
Enters text in a WebElement by family string

Parameters:
familyString - the String object, used to locates an identified element
text - the text to enter

dumpPage

public void dumpPage()

getWebElementsString

public java.util.ArrayList<java.lang.String> getWebElementsString()

dumpActivityText

public void dumpActivityText(boolean saveDuplicate)
dump text of activity including webview

Parameters:
saveDuplicate - true means save duplicate text

clickViewWithoutAssert

public void clickViewWithoutAssert(android.view.View view)

travel

public void travel(int depth,
                   java.lang.String username,
                   java.lang.String password)
Parameters:
depth -
username -
password -

travel

public void travel(int depth)

travel

public void travel()

getStringFromArguments

public java.lang.String getStringFromArguments(java.lang.String key)

finalize

public void finalize()
              throws java.lang.Throwable
Overrides:
finalize in class com.jayway.android.robotium.solo.Solo
Throws:
java.lang.Throwable

getField

protected java.lang.Object getField(java.lang.Object arg0,
                                    java.lang.String arg1)

invoke

protected static java.lang.Object invoke(java.lang.Object arg0,
                                         java.lang.String arg1)

invoke

protected static java.lang.Object invoke(java.lang.Object arg0,
                                         java.lang.String arg1,
                                         java.lang.Class<?>[] arg2,
                                         java.lang.Object[] arg3)