idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
22,600
public boolean scrollWebView ( final WebView webView , int direction , final boolean allTheWay ) { if ( direction == DOWN ) { inst . runOnMainSync ( new Runnable ( ) { public void run ( ) { canScroll = webView . pageDown ( allTheWay ) ; } } ) ; } if ( direction == UP ) { inst . runOnMainSync ( new Runnable ( ) { public...
Scrolls a WebView .
22,601
public < T extends AbsListView > boolean scrollList ( T absListView , int direction , boolean allTheWay ) { if ( absListView == null ) { return false ; } if ( direction == DOWN ) { int listCount = absListView . getCount ( ) ; int lastVisiblePosition = absListView . getLastVisiblePosition ( ) ; if ( allTheWay ) { scroll...
Scrolls a list .
22,602
public < T extends AbsListView > void scrollListToLine ( final T view , final int line ) { if ( view == null ) Assert . fail ( "AbsListView is null!" ) ; final int lineToMoveTo ; if ( view instanceof GridView ) { lineToMoveTo = line + 1 ; } else { lineToMoveTo = line ; } inst . runOnMainSync ( new Runnable ( ) { public...
Scroll the list to a given line
22,603
public void scrollViewToSide ( View view , Side side , float scrollPosition , int stepCount ) { int [ ] corners = new int [ 2 ] ; view . getLocationOnScreen ( corners ) ; int viewHeight = view . getHeight ( ) ; int viewWidth = view . getWidth ( ) ; float x = corners [ 0 ] + viewWidth * scrollPosition ; float y = corner...
Scrolls view horizontally .
22,604
private View getScreenshotView ( ) { View decorView = viewFetcher . getRecentDecorView ( viewFetcher . getWindowDecorViews ( ) ) ; final long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; while ( decorView == null ) { final boolean timedOut = SystemClock . uptimeMillis ( ) > endTime ; if ( ...
Gets the proper view to use for a screenshot .
22,605
private void wrapAllGLViews ( View decorView ) { ArrayList < GLSurfaceView > currentViews = viewFetcher . getCurrentViews ( GLSurfaceView . class , true , decorView ) ; final CountDownLatch latch = new CountDownLatch ( currentViews . size ( ) ) ; for ( GLSurfaceView glView : currentViews ) { Object renderContainer = ne...
Extract and wrap the all OpenGL ES Renderer .
22,606
private Bitmap getBitmapOfWebView ( final WebView webView ) { Picture picture = webView . capturePicture ( ) ; Bitmap b = Bitmap . createBitmap ( picture . getWidth ( ) , picture . getHeight ( ) , Bitmap . Config . ARGB_8888 ) ; Canvas c = new Canvas ( b ) ; picture . draw ( c ) ; return b ; }
Returns a bitmap of a given WebView .
22,607
private Bitmap getBitmapOfView ( final View view ) { view . destroyDrawingCache ( ) ; view . buildDrawingCache ( false ) ; Bitmap orig = view . getDrawingCache ( ) ; Bitmap . Config config = null ; if ( orig == null ) { return null ; } config = orig . getConfig ( ) ; if ( config == null ) { config = Bitmap . Config . A...
Returns a bitmap of a given View .
22,608
private String getFileName ( final String name ) { SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMyy-hhmmss" ) ; String fileName = null ; if ( name == null ) { if ( config . screenshotFileType == ScreenshotFileType . JPEG ) { fileName = sdf . format ( new Date ( ) ) . toString ( ) + ".jpg" ; } else { fileName = sdf...
Returns a proper filename depending on if name is given or not .
22,609
private void initScreenShotSaver ( ) { if ( screenShotSaverThread == null || screenShotSaver == null ) { screenShotSaverThread = new HandlerThread ( "ScreenShotSaver" ) ; screenShotSaverThread . start ( ) ; screenShotSaver = new ScreenShotSaver ( screenShotSaverThread ) ; } }
This method initializes the aysnc screenshot saving logic
22,610
private void createStackAndPushStartActivity ( ) { activityStack = new Stack < WeakReference < Activity > > ( ) ; if ( activity != null && config . trackActivities ) { WeakReference < Activity > weakReference = new WeakReference < Activity > ( activity ) ; activity = null ; activityStack . push ( weakReference ) ; } }
Creates a new activity stack and pushes the start activity .
22,611
private void setupActivityMonitor ( ) { if ( config . trackActivities ) { try { IntentFilter filter = null ; activityMonitor = inst . addMonitor ( filter , null , false ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }
This is were the activityMonitor is set up . The monitor will keep check for the currently active activity .
22,612
private void removeActivityFromStack ( Activity activity ) { Iterator < WeakReference < Activity > > activityStackIterator = activityStack . iterator ( ) ; while ( activityStackIterator . hasNext ( ) ) { Activity activityFromWeakReference = activityStackIterator . next ( ) . get ( ) ; if ( activityFromWeakReference == ...
Removes a given activity from the activity stack
22,613
private void addActivityToStack ( Activity activity ) { activitiesStoredInActivityStack . push ( activity . toString ( ) ) ; weakActivityReference = new WeakReference < Activity > ( activity ) ; activity = null ; activityStack . push ( weakActivityReference ) ; }
Adds an activity to the stack
22,614
private final void waitForActivityIfNotAvailable ( ) { if ( activityStack . isEmpty ( ) || activityStack . peek ( ) . get ( ) == null ) { if ( activityMonitor != null ) { Activity activity = activityMonitor . getLastActivity ( ) ; while ( activity == null ) { sleeper . sleepMini ( ) ; activity = activityMonitor . getLa...
Waits for an activity to be started if one is not provided by the constructor .
22,615
public String getString ( int resId ) { Activity activity = getCurrentActivity ( false ) ; if ( activity == null ) { return "" ; } return activity . getString ( resId ) ; }
Returns a localized string .
22,616
private void stopActivityMonitor ( ) { try { if ( activityMonitor != null ) { inst . removeMonitor ( activityMonitor ) ; activityMonitor = null ; } } catch ( Exception ignored ) { } }
Removes the ActivityMonitor
22,617
public void finishOpenedActivities ( ) { activitySyncTimer . cancel ( ) ; if ( ! config . trackActivities ) { useGoBack ( 3 ) ; return ; } ArrayList < Activity > activitiesOpened = getAllOpenedActivities ( ) ; for ( int i = activitiesOpened . size ( ) - 1 ; i >= 0 ; i -- ) { sleeper . sleep ( MINISLEEP ) ; finishActivi...
All activites that have been opened are finished .
22,618
private void useGoBack ( int numberOfTimes ) { for ( int i = 0 ; i < numberOfTimes ; i ++ ) { try { inst . sendKeyDownUpSync ( KeyEvent . KEYCODE_BACK ) ; sleeper . sleep ( MINISLEEP ) ; inst . sendKeyDownUpSync ( KeyEvent . KEYCODE_BACK ) ; } catch ( Throwable ignored ) { } } }
Sends the back button command a given number of times
22,619
private void finishActivity ( Activity activity ) { if ( activity != null ) { try { activity . finish ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; } } }
Finishes an activity .
22,620
public View getScrollOrListParent ( View view ) { if ( ! ( view instanceof android . widget . AbsListView ) && ! ( view instanceof android . widget . ScrollView ) && ! ( view instanceof WebView ) ) { try { return getScrollOrListParent ( ( View ) view . getParent ( ) ) ; } catch ( Exception e ) { return null ; } } else ...
Returns the scroll or list parent view
22,621
public ArrayList < View > getAllViews ( boolean onlySufficientlyVisible ) { final View [ ] views = getWindowDecorViews ( ) ; final ArrayList < View > allViews = new ArrayList < View > ( ) ; final View [ ] nonDecorViews = getNonDecorViews ( views ) ; View view = null ; if ( nonDecorViews != null ) { for ( int i = 0 ; i ...
Returns views from the shown DecorViews .
22,622
public final View getRecentDecorView ( View [ ] views ) { if ( views == null ) return null ; final View [ ] decorViews = new View [ views . length ] ; int i = 0 ; View view ; for ( int j = 0 ; j < views . length ; j ++ ) { view = views [ j ] ; if ( isDecorView ( view ) ) { decorViews [ i ] = view ; i ++ ; } } return ge...
Returns the most recent DecorView
22,623
private final View getRecentContainer ( View [ ] views ) { View container = null ; long drawingTime = 0 ; View view ; for ( int i = 0 ; i < views . length ; i ++ ) { view = views [ i ] ; if ( view != null && view . isShown ( ) && view . hasWindowFocus ( ) && view . getDrawingTime ( ) > drawingTime ) { container = view ...
Returns the most recent view container
22,624
private final View [ ] getNonDecorViews ( View [ ] views ) { View [ ] decorViews = null ; if ( views != null ) { decorViews = new View [ views . length ] ; int i = 0 ; View view ; for ( int j = 0 ; j < views . length ; j ++ ) { view = views [ j ] ; if ( ! isDecorView ( view ) ) { decorViews [ i ] = view ; i ++ ; } } } ...
Returns all views that are non DecorViews
22,625
private boolean isDecorView ( View view ) { if ( view == null ) { return false ; } final String nameOfClass = view . getClass ( ) . getName ( ) ; return ( nameOfClass . equals ( "com.android.internal.policy.impl.PhoneWindow$DecorView" ) || nameOfClass . equals ( "com.android.internal.policy.impl.MultiPhoneWindow$MultiP...
Returns whether a view is a DecorView
22,626
@ SuppressWarnings ( "deprecation" ) public float getScrollListWindowHeight ( View view ) { final int [ ] xyParent = new int [ 2 ] ; View parent = getScrollOrListParent ( view ) ; final float windowHeight ; if ( parent == null ) { WindowManager windowManager = ( WindowManager ) instrumentation . getTargetContext ( ) . ...
Returns the height of the scroll or list view parent
22,627
public final < T extends View > T getFreshestView ( ArrayList < T > views ) { final int [ ] locationOnScreen = new int [ 2 ] ; T viewToReturn = null ; long drawingTime = 0 ; if ( views == null ) { return null ; } for ( T view : views ) { if ( view != null ) { view . getLocationOnScreen ( locationOnScreen ) ; if ( locat...
Tries to guess which view is the most likely to be interesting . Returns the most recently drawn view which presumably will be the one that the user was most recently interacting with .
22,628
public < T extends View > ViewGroup getRecyclerView ( int recyclerViewIndex , int timeOut ) { final long endTime = SystemClock . uptimeMillis ( ) + timeOut ; while ( SystemClock . uptimeMillis ( ) < endTime ) { View recyclerView = getRecyclerView ( true , recyclerViewIndex ) ; if ( recyclerView != null ) { return ( Vie...
Waits for a RecyclerView and returns it .
22,629
public View getRecyclerView ( boolean shouldSleep , int recyclerViewIndex ) { Set < View > uniqueViews = new HashSet < View > ( ) ; if ( shouldSleep ) { sleeper . sleep ( ) ; } @ SuppressWarnings ( "unchecked" ) ArrayList < View > views = RobotiumUtils . filterViewsToSet ( new Class [ ] { ViewGroup . class } , getAllVi...
Returns a RecyclerView or null if none is found
22,630
public List < View > getScrollableSupportPackageViews ( boolean shouldSleep ) { List < View > viewsToReturn = new ArrayList < View > ( ) ; if ( shouldSleep ) { sleeper . sleep ( ) ; } @ SuppressWarnings ( "unchecked" ) ArrayList < View > views = RobotiumUtils . filterViewsToSet ( new Class [ ] { ViewGroup . class } , g...
Returns a Set of all RecyclerView or empty Set if none is found
22,631
public View getIdenticalView ( View view ) { if ( view == null ) { return null ; } View viewToReturn = null ; List < ? extends View > visibleViews = RobotiumUtils . removeInvisibleViews ( getCurrentViews ( view . getClass ( ) , true ) ) ; for ( View v : visibleViews ) { if ( areViewsIdentical ( v , view ) ) { viewToRet...
Returns an identical View to the one specified .
22,632
@ SuppressWarnings ( "unchecked" ) public View [ ] getWindowDecorViews ( ) { Field viewsField ; Field instanceField ; try { viewsField = windowManager . getDeclaredField ( "mViews" ) ; instanceField = windowManager . getDeclaredField ( windowManagerString ) ; viewsField . setAccessible ( true ) ; instanceField . setAcc...
Returns the WindorDecorViews shown on the screen .
22,633
private void setWindowManagerString ( ) { if ( android . os . Build . VERSION . SDK_INT >= 17 ) { windowManagerString = "sDefaultWindowManager" ; } else if ( android . os . Build . VERSION . SDK_INT >= 13 ) { windowManagerString = "sWindowManager" ; } else { windowManagerString = "mWindowManager" ; } }
Sets the window manager string .
22,634
public static < T extends View > ArrayList < T > removeInvisibleViews ( Iterable < T > viewList ) { ArrayList < T > tmpViewList = new ArrayList < T > ( ) ; for ( T view : viewList ) { if ( view != null && view . isShown ( ) ) { tmpViewList . add ( view ) ; } } return tmpViewList ; }
Removes invisible Views .
22,635
public static < T > ArrayList < T > filterViews ( Class < T > classToFilterBy , Iterable < ? > viewList ) { ArrayList < T > filteredViews = new ArrayList < T > ( ) ; for ( Object view : viewList ) { if ( view != null && classToFilterBy . isAssignableFrom ( view . getClass ( ) ) ) { filteredViews . add ( classToFilterBy...
Filters Views based on the given class type .
22,636
public static ArrayList < View > filterViewsToSet ( Class < View > classSet [ ] , Iterable < View > viewList ) { ArrayList < View > filteredViews = new ArrayList < View > ( ) ; for ( View view : viewList ) { if ( view == null ) continue ; for ( Class < View > filter : classSet ) { if ( filter . isAssignableFrom ( view ...
Filters all Views not within the given set .
22,637
public static void sortViewsByLocationOnScreen ( List < ? extends View > views , boolean yAxisFirst ) { Collections . sort ( views , new ViewLocationComparator ( yAxisFirst ) ) ; }
Orders Views by their location on - screen .
22,638
public static int getNumberOfMatches ( String regex , TextView view , Set < TextView > uniqueTextViews ) { if ( view == null ) { return uniqueTextViews . size ( ) ; } Pattern pattern = null ; try { pattern = Pattern . compile ( regex ) ; } catch ( PatternSyntaxException e ) { pattern = Pattern . compile ( regex , Patte...
Checks if a View matches a certain string and returns the amount of total matches .
22,639
public void clickOnScreen ( float x , float y , View view ) { boolean successfull = false ; int retry = 0 ; SecurityException ex = null ; while ( ! successfull && retry < 20 ) { long downTime = SystemClock . uptimeMillis ( ) ; long eventTime = SystemClock . uptimeMillis ( ) ; MotionEvent event = MotionEvent . obtain ( ...
Clicks on a given coordinate on the screen .
22,640
public void clickLongOnScreen ( float x , float y , int time , View view ) { boolean successfull = false ; int retry = 0 ; SecurityException ex = null ; long downTime = SystemClock . uptimeMillis ( ) ; long eventTime = SystemClock . uptimeMillis ( ) ; MotionEvent event = MotionEvent . obtain ( downTime , eventTime , Mo...
Long clicks a given coordinate on the screen .
22,641
public void clickOnScreen ( View view , boolean longClick , int time ) { if ( view == null ) Assert . fail ( "View is null and can therefore not be clicked!" ) ; float [ ] xyToClick = getClickCoordinates ( view ) ; float x = xyToClick [ 0 ] ; float y = xyToClick [ 1 ] ; if ( x == 0 || y == 0 ) { sleeper . sleepMini ( )...
Private method used to click on a given view .
22,642
private float [ ] getClickCoordinates ( View view ) { int [ ] xyLocation = new int [ 2 ] ; float [ ] xyToClick = new float [ 2 ] ; int trialCount = 0 ; view . getLocationOnScreen ( xyLocation ) ; while ( xyLocation [ 0 ] == 0 && xyLocation [ 1 ] == 0 && trialCount < 10 ) { sleeper . sleep ( 300 ) ; view . getLocationOn...
Returns click coordinates for the specified view .
22,643
private void openMenu ( ) { sleeper . sleepMini ( ) ; if ( ! dialogUtils . waitForDialogToOpen ( MINI_WAIT , false ) ) { try { sender . sendKeyCode ( KeyEvent . KEYCODE_MENU ) ; dialogUtils . waitForDialogToOpen ( WAIT_TIME , true ) ; } catch ( SecurityException e ) { Assert . fail ( "Can not open the menu!" ) ; } } }
Opens the menu and waits for it to open .
22,644
public void clickOnMenuItem ( String text , boolean subMenu ) { sleeper . sleepMini ( ) ; TextView textMore = null ; int [ ] xy = new int [ 2 ] ; int x = 0 ; int y = 0 ; if ( ! dialogUtils . waitForDialogToOpen ( MINI_WAIT , false ) ) { try { sender . sendKeyCode ( KeyEvent . KEYCODE_MENU ) ; dialogUtils . waitForDialo...
Clicks on a menu item with a given text .
22,645
public void clickOnActionBarItem ( int resourceId ) { sleeper . sleep ( ) ; Activity activity = activityUtils . getCurrentActivity ( ) ; if ( activity != null ) { inst . invokeMenuActionSync ( activity , resourceId , 0 ) ; } }
Clicks on an ActionBar item with a given resource id
22,646
public void clickOnWebElement ( By by , int match , boolean scroll , boolean useJavaScriptToClick ) { WebElement webElement = null ; if ( useJavaScriptToClick ) { webElement = waiter . waitForWebElement ( by , match , Timeout . getSmallTimeout ( ) , false ) ; if ( webElement == null ) { Assert . fail ( "WebElement with...
Clicks on a web element using the given By method .
22,647
private View getViewOnAbsListLine ( AbsListView absListView , int index , int lineIndex ) { final long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; View view = absListView . getChildAt ( lineIndex ) ; while ( view == null ) { final boolean timedOut = SystemClock . uptimeMillis ( ) > endTim...
Returns the view in the specified list line
22,648
private View getViewOnRecyclerItemIndex ( ViewGroup recyclerView , int recyclerViewIndex , int itemIndex ) { final long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; View view = recyclerView . getChildAt ( itemIndex ) ; while ( view == null ) { final boolean timedOut = SystemClock . uptimeM...
Returns the view in the specified item index
22,649
public String getAttribute ( String attributeName ) { if ( attributeName != null ) { return this . attributes . get ( attributeName ) ; } return null ; }
Returns the value for the specified attribute .
22,650
public void assertMemoryNotLow ( ) { ActivityManager . MemoryInfo mi = new ActivityManager . MemoryInfo ( ) ; ( ( ActivityManager ) activityUtils . getCurrentActivity ( ) . getSystemService ( "activity" ) ) . getMemoryInfo ( mi ) ; Assert . assertFalse ( "Low memory available: " + mi . availMem + " bytes!" , mi . lowMe...
Asserts that the available memory is not considered low by the system .
22,651
public void setSlidingDrawer ( final SlidingDrawer slidingDrawer , final int status ) { if ( slidingDrawer != null ) { Activity activity = activityUtils . getCurrentActivity ( false ) ; if ( activity != null ) { activity . runOnUiThread ( new Runnable ( ) { public void run ( ) { try { switch ( status ) { case CLOSED : ...
Sets the status of a given SlidingDrawer . Examples are Solo . CLOSED and Solo . OPENED .
22,652
public void setNavigationDrawer ( final int status ) { final View homeView = getter . getView ( "home" , 0 ) ; final View leftDrawer = getter . getView ( "left_drawer" , 0 ) ; try { switch ( status ) { case CLOSED : if ( leftDrawer != null && homeView != null && leftDrawer . isShown ( ) ) { clicker . clickOnScreen ( ho...
Sets the status of the NavigationDrawer . Examples are Solo . CLOSED and Solo . OPENED .
22,653
private boolean isDialogOpen ( ) { final Activity activity = activityUtils . getCurrentActivity ( false ) ; final View [ ] views = viewFetcher . getWindowDecorViews ( ) ; View view = viewFetcher . getRecentDecorView ( views ) ; if ( ! isDialog ( activity , view ) ) { for ( View v : views ) { if ( isDialog ( activity , ...
Checks if a dialog is open .
22,654
private boolean isDialog ( Activity activity , View decorView ) { if ( decorView == null || ! decorView . isShown ( ) || activity == null ) { return false ; } Context viewContext = null ; if ( decorView != null ) { viewContext = decorView . getContext ( ) ; } if ( viewContext instanceof ContextThemeWrapper ) { ContextT...
Checks that the specified DecorView and the Activity DecorView are not equal .
22,655
public void hideSoftKeyboard ( EditText editText , boolean shouldSleepFirst , boolean shouldSleepAfter ) { InputMethodManager inputMethodManager ; Activity activity = activityUtils . getCurrentActivity ( shouldSleepFirst ) ; if ( activity == null ) { inputMethodManager = ( InputMethodManager ) instrumentation . getTarg...
Hides the soft keyboard
22,656
private boolean isActivityMatching ( Activity currentActivity , String name ) { if ( currentActivity != null && currentActivity . getClass ( ) . getSimpleName ( ) . equals ( name ) ) { return true ; } return false ; }
Compares Activity names .
22,657
private boolean isActivityMatching ( Class < ? extends Activity > activityClass , Activity currentActivity ) { if ( currentActivity != null && currentActivity . getClass ( ) . equals ( activityClass ) ) { return true ; } return false ; }
Compares Activity classes .
22,658
private ActivityMonitor getActivityMonitor ( ) { IntentFilter filter = null ; ActivityMonitor activityMonitor = instrumentation . addMonitor ( filter , null , false ) ; return activityMonitor ; }
Creates a new ActivityMonitor and returns it
22,659
public < T extends View > boolean waitForViews ( boolean scrollMethod , Class < ? extends T > ... classes ) { final long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; while ( SystemClock . uptimeMillis ( ) < endTime ) { for ( Class < ? extends T > classToWaitFor : classes ) { if ( waitForVi...
Waits for two views to be shown .
22,660
public boolean waitForView ( View view ) { View viewToWaitFor = waitForView ( view , Timeout . getLargeTimeout ( ) , true , true ) ; if ( viewToWaitFor != null ) { return true ; } return false ; }
Waits for a given view . Default timeout is 20 seconds .
22,661
public WebElement waitForWebElement ( final By by , int minimumNumberOfMatches , int timeout , boolean scroll ) { final long endTime = SystemClock . uptimeMillis ( ) + timeout ; while ( true ) { final boolean timedOut = SystemClock . uptimeMillis ( ) > endTime ; if ( timedOut ) { searcher . logMatchesFound ( by . getVa...
Waits for a web element .
22,662
public < T extends View > T waitForAndGetView ( int index , Class < T > classToFilterBy ) { long endTime = SystemClock . uptimeMillis ( ) + Timeout . getSmallTimeout ( ) ; while ( SystemClock . uptimeMillis ( ) <= endTime && ! waitForView ( classToFilterBy , index , true , true ) ) ; int numberOfUniqueViews = searcher ...
Waits for and returns a View .
22,663
public boolean waitForFragment ( String tag , int id , int timeout ) { long endTime = SystemClock . uptimeMillis ( ) + timeout ; while ( SystemClock . uptimeMillis ( ) <= endTime ) { if ( getSupportFragment ( tag , id ) != null ) return true ; if ( getFragment ( tag , id ) != null ) return true ; } return false ; }
Waits for a Fragment with a given tag or id to appear .
22,664
private Fragment getSupportFragment ( String tag , int id ) { FragmentActivity fragmentActivity = null ; try { fragmentActivity = ( FragmentActivity ) activityUtils . getCurrentActivity ( false ) ; } catch ( Throwable ignored ) { } if ( fragmentActivity != null ) { try { if ( tag == null ) return fragmentActivity . get...
Returns a SupportFragment with a given tag or id .
22,665
private StringBuilder getLog ( StringBuilder stringBuilder ) { Process p = null ; BufferedReader reader = null ; String line = null ; try { p = Runtime . getRuntime ( ) . exec ( "logcat -d" ) ; reader = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ; stringBuilder . setLength ( 0 ) ; while ( (...
Returns the log in the given stringBuilder .
22,666
public void clearLog ( ) { Process p = null ; try { p = Runtime . getRuntime ( ) . exec ( "logcat -c" ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Clears the log .
22,667
private void destroy ( Process p , BufferedReader reader ) { p . destroy ( ) ; try { reader . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Destroys the process and closes the BufferedReader .
22,668
private android . app . Fragment getFragment ( String tag , int id ) { try { if ( tag == null ) return activityUtils . getCurrentActivity ( ) . getFragmentManager ( ) . findFragmentById ( id ) ; else return activityUtils . getCurrentActivity ( ) . getFragmentManager ( ) . findFragmentByTag ( tag ) ; } catch ( Throwable...
Returns a Fragment with a given tag or id .
22,669
private ArrayList < TextView > createAndReturnTextViewsFromWebElements ( boolean javaScriptWasExecuted ) { ArrayList < TextView > webElementsAsTextViews = new ArrayList < TextView > ( ) ; if ( javaScriptWasExecuted ) { for ( WebElement webElement : webElementCreator . getWebElementsFromWebViews ( ) ) { if ( isWebElemen...
Creates and returns TextView objects based on WebElements
22,670
public ArrayList < WebElement > getWebElements ( final By by , boolean onlySufficientlyVisbile ) { boolean javaScriptWasExecuted = executeJavaScript ( by , false ) ; if ( config . useJavaScriptToClickWebElements ) { if ( ! javaScriptWasExecuted ) { return new ArrayList < WebElement > ( ) ; } return webElementCreator . ...
Returns an ArrayList of WebElements of the specified By object currently shown in the active WebView .
22,671
private ArrayList < WebElement > getWebElements ( boolean javaScriptWasExecuted , boolean onlySufficientlyVisbile ) { ArrayList < WebElement > webElements = new ArrayList < WebElement > ( ) ; if ( javaScriptWasExecuted ) { for ( WebElement webElement : webElementCreator . getWebElementsFromWebViews ( ) ) { if ( ! onlyS...
Returns the sufficiently shown WebElements
22,672
private String prepareForStartOfJavascriptExecution ( List < WebView > webViews ) { webElementCreator . prepareForStart ( ) ; WebChromeClient currentWebChromeClient = getCurrentWebChromeClient ( ) ; if ( currentWebChromeClient != null && ! currentWebChromeClient . getClass ( ) . isAssignableFrom ( RobotiumWebClient . c...
Prepares for start of JavaScript execution
22,673
private WebChromeClient getCurrentWebChromeClient ( ) { WebChromeClient currentWebChromeClient = null ; Object currentWebView = viewFetcher . getFreshestView ( viewFetcher . getCurrentViews ( WebView . class , true ) ) ; if ( android . os . Build . VERSION . SDK_INT >= 16 ) { try { currentWebView = new Reflect ( curren...
Returns the current WebChromeClient through reflection
22,674
public void enterTextIntoWebElement ( final By by , final String text ) { if ( by instanceof By . Id ) { executeJavaScriptFunction ( "enterTextById(\"" + by . getValue ( ) + "\", \"" + text + "\");" ) ; } else if ( by instanceof By . Xpath ) { executeJavaScriptFunction ( "enterTextByXpath(\"" + by . getValue ( ) + "\",...
Enters text into a web element using the given By method
22,675
public boolean executeJavaScript ( final By by , boolean shouldClick ) { if ( by instanceof By . Id ) { return executeJavaScriptFunction ( "id(\"" + by . getValue ( ) + "\", \"" + String . valueOf ( shouldClick ) + "\");" ) ; } else if ( by instanceof By . Xpath ) { return executeJavaScriptFunction ( "xpath(\"" + by . ...
Executes JavaScript determined by the given By object
22,676
private boolean executeJavaScriptFunction ( final String function ) { List < WebView > webViews = viewFetcher . getCurrentViews ( WebView . class , true ) ; final WebView webView = viewFetcher . getFreshestView ( ( ArrayList < WebView > ) webViews ) ; if ( webView == null ) { return false ; } final String javaScript = ...
Executes the given JavaScript function
22,677
public String splitNameByUpperCase ( String name ) { String [ ] texts = name . split ( "(?=\\p{Upper})" ) ; StringBuilder stringToReturn = new StringBuilder ( ) ; for ( String string : texts ) { if ( stringToReturn . length ( ) > 0 ) { stringToReturn . append ( " " + string . toLowerCase ( ) ) ; } else { stringToReturn...
Splits a name by upper case .
22,678
private String getJavaScriptAsString ( ) { InputStream fis = getClass ( ) . getResourceAsStream ( "RobotiumWeb.js" ) ; StringBuffer javaScript = new StringBuffer ( ) ; try { BufferedReader input = new BufferedReader ( new InputStreamReader ( fis ) ) ; String line = null ; while ( ( line = input . readLine ( ) ) != null...
Returns the JavaScript file RobotiumWeb . js as a String
22,679
public < T extends View > boolean searchFor ( Set < T > uniqueViews , Class < T > viewClass , final int index ) { ArrayList < T > allViews = RobotiumUtils . removeInvisibleViews ( viewFetcher . getCurrentViews ( viewClass , true ) ) ; int uniqueViewsFound = ( getNumberOfUniqueViews ( uniqueViews , allViews ) ) ; if ( u...
Searches for a view class .
22,680
public < T extends View > boolean searchFor ( View view ) { ArrayList < View > views = viewFetcher . getAllViews ( true ) ; for ( View v : views ) { if ( v . equals ( view ) ) { return true ; } } return false ; }
Searches for a given view .
22,681
public WebElement searchForWebElement ( final By by , int minimumNumberOfMatches ) { if ( minimumNumberOfMatches < 1 ) { minimumNumberOfMatches = 1 ; } List < WebElement > viewsFromScreen = webUtils . getWebElements ( by , true ) ; addViewsToList ( webElements , viewsFromScreen ) ; return getViewFromList ( webElements ...
Searches for a web element .
22,682
private void addViewsToList ( List < WebElement > allWebElements , List < WebElement > webElementsOnScreen ) { int [ ] xyViewFromSet = new int [ 2 ] ; int [ ] xyViewFromScreen = new int [ 2 ] ; for ( WebElement textFromScreen : webElementsOnScreen ) { boolean foundView = false ; textFromScreen . getLocationOnScreen ( x...
Adds views to a given list .
22,683
private WebElement getViewFromList ( List < WebElement > webElements , int match ) { WebElement webElementToReturn = null ; if ( webElements . size ( ) >= match ) { try { webElementToReturn = webElements . get ( -- match ) ; } catch ( Exception ignored ) { } } if ( webElementToReturn != null ) webElements . clear ( ) ;...
Returns a text view with a given match .
22,684
public < T extends View > int getNumberOfUniqueViews ( Set < T > uniqueViews , ArrayList < T > views ) { for ( int i = 0 ; i < views . size ( ) ; i ++ ) { uniqueViews . add ( views . get ( i ) ) ; } numberOfUniqueViews = uniqueViews . size ( ) ; return numberOfUniqueViews ; }
Returns the number of unique views .
22,685
public void setMobileData ( Boolean turnedOn ) { ConnectivityManager dataManager = ( ConnectivityManager ) instrumentation . getTargetContext ( ) . getSystemService ( Context . CONNECTIVITY_SERVICE ) ; Method dataClass = null ; try { dataClass = ConnectivityManager . class . getDeclaredMethod ( "setMobileDataEnabled" ,...
Sets if mobile data should be turned on or off . Requires android . permission . CHANGE_NETWORK_STATE in the AndroidManifest . xml of the application under test .
22,686
public void setWiFiData ( Boolean turnedOn ) { WifiManager wifiManager = ( WifiManager ) instrumentation . getTargetContext ( ) . getSystemService ( Context . WIFI_SERVICE ) ; try { wifiManager . setWifiEnabled ( turnedOn ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Sets if wifi data should be turned on or off . Requires android . permission . CHANGE_WIFI_STATE in the AndroidManifest . xml of the application under test .
22,687
public ActivityMonitor getActivityMonitor ( ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "getActivityMonitor()" ) ; } return activityUtils . getActivityMonitor ( ) ; }
Returns the ActivityMonitor used by Robotium .
22,688
public ArrayList < View > getViews ( ) { try { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "getViews()" ) ; } return viewFetcher . getViews ( null , false ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } }
Returns an ArrayList of all the View objects located in the focused Activity or Dialog .
22,689
public View getTopParent ( View view ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "getTopParent(" + view + ")" ) ; } View topParent = viewFetcher . getTopParent ( view ) ; return topParent ; }
Returns the absolute top parent View of the specified View .
22,690
public boolean waitForText ( String text , int minimumNumberOfMatches , long timeout , boolean scroll , boolean onlyVisible ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForText(\"" + text + "\", " + minimumNumberOfMatches + ", " + timeout + ", " + scroll + ", " + onlyVisible + ")" ) ...
Waits for the specified text to appear .
22,691
public boolean waitForView ( int id ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + id + ")" ) ; } return waitForView ( id , 0 , Timeout . getLargeTimeout ( ) , true ) ; }
Waits for a View matching the specified resource id . Default timeout is 20 seconds .
22,692
public boolean waitForView ( Object tag ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + tag + ")" ) ; } return waitForView ( tag , 0 , Timeout . getLargeTimeout ( ) , true ) ; }
Waits for a View matching the specified tag . Default timeout is 20 seconds .
22,693
public boolean waitForView ( Object tag , int minimumNumberOfMatches , int timeout ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + tag + ", " + minimumNumberOfMatches + ", " + timeout + ")" ) ; } return waitForView ( tag , minimumNumberOfMatches , timeout , true ) ; }
Waits for a View matching the specified tag .
22,694
public < T extends View > boolean waitForView ( final Class < T > viewClass ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + viewClass + ")" ) ; } return waiter . waitForView ( viewClass , 0 , Timeout . getLargeTimeout ( ) , true ) ; }
Waits for a View matching the specified class . Default timeout is 20 seconds .
22,695
public < T extends View > boolean waitForView ( View view ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + view + ")" ) ; } return waiter . waitForView ( view ) ; }
Waits for the specified View . Default timeout is 20 seconds .
22,696
public < T extends View > boolean waitForView ( View view , int timeout , boolean scroll ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + view + ", " + timeout + ", " + scroll + ")" ) ; } boolean checkIsShown = false ; if ( ! scroll ) { checkIsShown = true ; } View viewToWait...
Waits for the specified View .
22,697
public < T extends View > boolean waitForView ( final Class < T > viewClass , final int minimumNumberOfMatches , final int timeout ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForView(" + viewClass + ", " + minimumNumberOfMatches + ", " + timeout + ")" ) ; } int index = minimumNumber...
Waits for a View matching the specified class .
22,698
public boolean waitForWebElement ( By by ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForWebElement(" + by + ")" ) ; } return ( waiter . waitForWebElement ( by , 0 , Timeout . getLargeTimeout ( ) , true ) != null ) ; }
Waits for a WebElement matching the specified By object . Default timeout is 20 seconds .
22,699
public boolean waitForWebElement ( By by , int timeout , boolean scroll ) { if ( config . commandLogging ) { Log . d ( config . commandLoggingTag , "waitForWebElement(" + by + ", " + timeout + ", " + scroll + ")" ) ; } return ( waiter . waitForWebElement ( by , 0 , timeout , scroll ) != null ) ; }
Waits for a WebElement matching the specified By object .