positron
Class Positron
java.lang.Object
android.app.Instrumentation
positron.Positron
public abstract class Positron
- extends Instrumentation
Subclass this to test your application with Positron.
First, implement suite() and return a junit TestSuite of the tests to run.
Your tests will want to extend positron.TestCase.
Declare the subclass in your AndroidManifest.xml with :
Notice you must put your subclass inside your.package in this example.
- Author:
- philhsmith
Method Summary |
List<Activity> |
activities()
Get a snapshot of the known activity stack. |
Activity |
activity()
|
|
at(Class<T> asA,
Object from,
String path)
Evaluate the ViewShorthand path starting from the given point. |
|
at(Class<T> asA,
String path)
Evaluate the ViewShorthand path starting from the current activity. |
Object |
at(String path)
Evaluate the ViewShorthand path starting from the current activity. |
void |
backup()
Backup all databases in the tested application. |
void |
backup(String database)
Backup the given database. |
boolean |
booleanAt(String path)
Evaluate the ViewShorthand path starting from the current activity. |
void |
callActivityOnResume(Activity activity)
|
void |
click()
sendKeyDownUp(KEYCODE_DPAD_CENTER) |
double |
doubleAt(String path)
Evaluate the ViewShorthand path starting from the current activity. |
Bitmap |
dupWindowBitmap(Activity activity)
dupWindowBitmapSync, resuming momentarily if necessary. |
Bitmap |
dupWindowBitmapSync(Activity activity)
|
void |
execSql(String database,
int... scriptsAsRawResources)
Execute the given Sql scripts (as raw resources in the target context.) |
void |
finish()
|
void |
finish(Activity activity)
|
void |
finishAll()
|
int |
intAt(String path)
Evaluate the ViewShorthand path starting from the current activity. |
void |
invokeMenuAction(Activity targetActivity,
int id,
int flag)
invokeMenuActionSync, resuming momentarily if necessary. |
void |
invokeMenuActionSync(Activity targetActivity,
int id,
int flag)
|
void |
onCreate(Bundle arguments)
|
void |
onStart()
|
void |
pause()
|
boolean |
paused()
|
void |
pauseNow()
|
void |
press(Object... keys)
sendKeyDownUpSync on all keys in order, resuming momentarily if necessary. |
void |
restore()
Restore all databases in the tested application that have backups. |
void |
restore(String database)
Restore the given database from a previous backup call. |
void |
resume()
|
void |
sendCharacter(int keyCode)
sendCharacterSync, resuming momentarily if necessary. |
void |
sendCharacterSync(int keyCode)
|
void |
sendKey(KeyEvent event)
sendKeySync, resuming momentarily if necessary. |
void |
sendKeyDownUp(int key)
sendKeyDownUpSync, resuming momentarily if necessary. |
void |
sendKeyDownUpSync(int key)
|
void |
sendKeySync(KeyEvent event)
|
void |
sendString(String text)
sendStringSync, resuming momentarily if necessary. |
void |
sendStringSync(String text)
|
Activity |
startActivity(Intent intent)
startActivitySync, resuming momentarily if necessary. |
Activity |
startActivitySync(Intent intent)
|
protected Activity |
startActivitySync(String className)
Shortcut to startActivitySync the named class in the target context. |
String |
stringAt(String path)
Evaluate the ViewShorthand path starting from the current activity. |
protected abstract TestSuite |
suite()
|
View |
viewAt(String path)
Evaluate the ViewShorthand path starting from the current activity. |
void |
waitForIdle()
waitForIdleSync, resuming momentarily if necessary. |
void |
waitForIdleSync()
|
Methods inherited from class android.app.Instrumentation |
addMonitor, addMonitor, addMonitor, callActivityOnCompleteThaw, callActivityOnCreate, callActivityOnFreeze, callActivityOnNewIntent, callActivityOnPause, callActivityOnPostCreate, callActivityOnRestart, callActivityOnStart, callApplicationOnCreate, checkMonitorHit, execStartActivity, finish, getAllocCounts, getContext, getTargetContext, isProfiling, newActivity, newApplication, onDestroy, onException, removeMonitor, runOnMainSync, start, startAllocCounting, startProfiling, stopAllocCounting, stopProfiling, waitForIdle, waitForMonitor |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TAG
public static final String TAG
- See Also:
- Constant Field Values
Positron
public Positron()
onCreate
public void onCreate(Bundle arguments)
- Overrides:
onCreate
in class Instrumentation
onStart
public void onStart()
- Overrides:
onStart
in class Instrumentation
callActivityOnResume
public void callActivityOnResume(Activity activity)
- Overrides:
callActivityOnResume
in class Instrumentation
activities
public List<Activity> activities()
- Get a snapshot of the known activity stack.
activity
public Activity activity()
finish
public void finish(Activity activity)
finish
public void finish()
finishAll
public void finishAll()
pause
public void pause()
pauseNow
public void pauseNow()
resume
public void resume()
paused
public boolean paused()
backup
public void backup()
- Backup all databases in the tested application.
backup
public void backup(String database)
- Backup the given database.
execSql
public void execSql(String database,
int... scriptsAsRawResources)
- Execute the given Sql scripts (as raw resources in the target context.)
restore
public void restore()
- Restore all databases in the tested application that have backups.
restore
public void restore(String database)
- Restore the given database from a previous backup call.
This deletes the backup as well.
suite
protected abstract TestSuite suite()
- Returns:
- A TestSuite of positron.TestCases to run.
startActivitySync
protected Activity startActivitySync(String className)
- Shortcut to startActivitySync the named class in the target context.
- Parameters:
className
- fully-qualified class name of the action to start.
dupWindowBitmap
public Bitmap dupWindowBitmap(Activity activity)
- dupWindowBitmapSync, resuming momentarily if necessary.
invokeMenuAction
public void invokeMenuAction(Activity targetActivity,
int id,
int flag)
- invokeMenuActionSync, resuming momentarily if necessary.
sendCharacter
public void sendCharacter(int keyCode)
- sendCharacterSync, resuming momentarily if necessary.
sendKeyDownUp
public void sendKeyDownUp(int key)
- sendKeyDownUpSync, resuming momentarily if necessary.
click
public void click()
- sendKeyDownUp(KEYCODE_DPAD_CENTER)
press
public void press(Object... keys)
- sendKeyDownUpSync on all keys in order, resuming momentarily if necessary.
Combined with the renamed constants available in positron.TestCase, this
enables things like press(UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, "ba")
which may otherwise be cumbersome.
- Parameters:
keys
- A mixture of ints and Strings. ints are sent with sendKeyDownUpSync,
Strings are send with sendStringSync.
- Throws:
IllegalArgumentException
- if something other than an int or String was passed.
at
public <T> T at(Class<T> asA,
Object from,
String path)
- Evaluate the ViewShorthand path starting from the given point.
- Returns:
- The result as the passed type.
at
public Object at(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as an Object.
at
public <T> T at(Class<T> asA,
String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as the passed type.
viewAt
public View viewAt(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as a View.
stringAt
public String stringAt(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as a String. If the result would be a CharSequence, call toString on it.
intAt
public int intAt(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as an int.
booleanAt
public boolean booleanAt(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as a boolean.
doubleAt
public double doubleAt(String path)
- Evaluate the ViewShorthand path starting from the current activity.
- Returns:
- The result as a double.
sendKey
public void sendKey(KeyEvent event)
- sendKeySync, resuming momentarily if necessary.
sendString
public void sendString(String text)
- sendStringSync, resuming momentarily if necessary.
startActivity
public Activity startActivity(Intent intent)
- startActivitySync, resuming momentarily if necessary.
waitForIdle
public void waitForIdle()
- waitForIdleSync, resuming momentarily if necessary.
dupWindowBitmapSync
public Bitmap dupWindowBitmapSync(Activity activity)
- Overrides:
dupWindowBitmapSync
in class Instrumentation
invokeMenuActionSync
public void invokeMenuActionSync(Activity targetActivity,
int id,
int flag)
- Overrides:
invokeMenuActionSync
in class Instrumentation
sendCharacterSync
public void sendCharacterSync(int keyCode)
- Overrides:
sendCharacterSync
in class Instrumentation
sendKeyDownUpSync
public void sendKeyDownUpSync(int key)
- Overrides:
sendKeyDownUpSync
in class Instrumentation
sendKeySync
public void sendKeySync(KeyEvent event)
- Overrides:
sendKeySync
in class Instrumentation
sendStringSync
public void sendStringSync(String text)
- Overrides:
sendStringSync
in class Instrumentation
startActivitySync
public Activity startActivitySync(Intent intent)
- Overrides:
startActivitySync
in class Instrumentation
waitForIdleSync
public void waitForIdleSync()
- Overrides:
waitForIdleSync
in class Instrumentation