public class SoloTest
extends java.lang.Object
Prerequisite:
1. Set the android sdk dir (use one of 2 ways): 1.1 set environment ANDROID_HOME 1.2 launch application with JVM property as: -Dandroid-home="D:\\your\\android-sdk-dir" 2. (Optional)Set the ant sdk dir if you need rebuild the test-runner-apk (use one of 2 ways): 2.1 set environment ANT_HOME 2.2 launch application with JVM property as: -Dant-home="D:\\your\\ant-sdk-dir" 3. Command-line args to set the APK of AUT, SAFSMessenger and SAFSTestRunner to be installed: aut="C:\\SAFS\\samples\\Droid\\SpinnerSample\\bin\\SpinnerActivity-debug.apk" (sets installAUT=true) messenger="C:\\SAFS\\samples\\Droid\\SAFSTCPMessenger\\bin\\SAFSTCPMessenger-debug.apk" (sets installMessenger=true) runner="C:\\SAFS\\samples\\Droid\\SAFSTestRunner\\bin\\SAFSTestRunner-debug.apk" (sets installRunner=true) (or runnersource=d:\\testRunnerSourcePath like below:) runnersource="C:\\SAFS\\samples\\Droid\\SAFSTestRunner" (sets rebuildRunner=true) OR, to bypass individual installs and use what is already installed: -noaut -nomessenger -norunner 4. Command-line arg to set the instrument: instrument=org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner 5. Command-line arg to set the avd name to launch, or the device/emulator serial number to look for: avd="avdName" or avd="devOrEmuSerial" 6. Command-line arg to set the persistence of launched emulator: persistavd="True" or persistavd="False" (default=false) 7. Command-line arg to set to resign AUT automatically: resignjar=C:\\safs\\lib\\re-sign.jar 8. Command-line arg to set to remove installed APKs automatically after test finish: -removeinstalledapk
Run as: java org.safs.android.remotecontrol.SoloTest aut="C:\\buildFilePath\\SpinnerActivity-debug.apk" messenger="c:\\buildFilePath\\SAFSTCPMessenger-debug.apk" runner="c:\\buildFilePath\\SAFSTestRunner-debug.apk" instrument=org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner or, rebuild testrunner and use it java -Dant-home="C:\\pathTo\\ant-sdk" org.safs.android.remotecontrol.SoloTest aut="C:\\buildFilePath\\SpinnerActivity-debug.apk" messenger="c:\\buildFilePath\\SAFSTCPMessenger-debug.apk" runnersource="c:\\buildSourcePath\\" instrument=org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner or, assuming everything is already installed: java -Dandroid-home="C:\\pathTo\\android-sdk" org.safs.android.remotecontrol.SoloTest -noaut -nomessenger -norunner instrument=org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ARG_KEY_AUT_APK |
static java.lang.String |
ARG_KEY_AVD |
static java.lang.String |
ARG_KEY_INSTRUMENT_ARG |
static java.lang.String |
ARG_KEY_MESSENGER_APK |
static java.lang.String |
ARG_KEY_NO_AUT |
static java.lang.String |
ARG_KEY_NO_MESSENGER |
static java.lang.String |
ARG_KEY_NO_RUNNER |
static java.lang.String |
ARG_KEY_PERSIST_AVD |
static java.lang.String |
ARG_KEY_REMOVE_INSTALLED_APK |
static java.lang.String |
ARG_KEY_RESIGN_JAR |
static java.lang.String |
ARG_KEY_TESTRUNNER_APK |
static java.lang.String |
ARG_KEY_TESTRUNNER_SOURCE |
boolean |
argAUTpassed
true if we received the 'aut' command-line argument, or setAUTApk() was called.
|
boolean |
argINSTRUMENTpassed
true if we received the 'instrument' command-line argument, or setInstrumentArg() was called.
|
boolean |
argMESSENGERpassed
true if we received the 'messenger' command-line argument, or setMessengerApk() was called.
|
boolean |
argRESIGNJARpassed
true if we received the 'resignjar' command-line argument, or setResignJar() was called.
|
boolean |
argRUNNERpassed
true if we received the 'runner' command-line argument, or setTestRunnerApk() was called.
|
boolean |
argRUNNERSOURCEpassed
true if we received the 'runnersource' command-line argument, or setTestRunnerSourceDir() was called.
|
protected java.lang.String |
avdSerialNo
avdSerialNo is device or emulator's serial number, it is "" by default
it will be modified by the value pass in as 'avd=' argument If there is no device/emulator is attached/launched, we will try to launch the emulator with this serial number. If there is one device/emulator is attached/launched, we will ignore this serial number. If there are multiple devices/emulators are attached/launched, we use this serial number to locate the device/emulator. |
static java.lang.String |
DEFAULT_AUT_APK
Modify
DEFAULT_AUT_APK according to your system.Modify DEFAULT_MESSENGER_APK according to your system.Modify DEFAULT_TESTRUNNER_APK according to your system.Modify DEFAULT_TESTRUNNER_SOURCE_DIR according to your system.Modify DEFAULT_INSTRUMENT_ARG according to your system. |
static java.lang.String |
DEFAULT_INSTRUMENT_ARG |
static java.lang.String |
DEFAULT_MESSENGER_APK |
static java.lang.String |
DEFAULT_TESTRUNNER_APK |
static java.lang.String |
DEFAULT_TESTRUNNER_SOURCE_DIR |
SAFSDriverCommands |
driver |
SAFSEngineCommands |
engine |
protected java.lang.String |
mainActivityUID
This field will store the activity UID of you launch AUT.
It will be set in method initialize() It will be used in method goBackToViewUID(String) to prevent infinite loop. |
protected boolean |
persistEmulators
If this is true, we will keep the launched emulator running even after the
test has finished. The default value is false. it will be modified by the value pass in as 'persistavd=' argument |
boolean |
removeinstalledapk
default is false.
|
Timeout |
robotiumTimeout |
RobotiumUtils |
robotiumUtils |
Solo |
solo |
protected boolean |
unlockEmulatorScreen
flag defaults to true to unlock the screen of any emulator we wish to connect to.
|
protected boolean |
weLaunchedEmulator |
Constructor and Description |
---|
SoloTest()
Instantiates the Solo instance but does not yet initialize it.
|
SoloTest(java.lang.String[] args) |
SoloTest(java.lang.String messengerApk,
java.lang.String testRunnerApk,
java.lang.String instrumentArg) |
Modifier and Type | Method and Description |
---|---|
void |
debug(java.lang.String message) |
void |
error(java.lang.String message) |
void |
fail(java.lang.String message) |
java.lang.String |
getAUTApk() |
java.lang.String |
getInstrumentArg() |
java.lang.String |
getMessengerApk() |
java.lang.String |
getResignJar() |
java.lang.String |
getTestRunnerApk() |
java.lang.String |
getTestRunnerSourceDir() |
protected void |
goBackToViewUID(java.lang.String viewUID) |
void |
info(java.lang.String message) |
protected boolean |
initialize()
Initialize the Solo object and the SAFSEngineCommands instance and launches the main application.
You will not modify this method in the sub-class, normally |
boolean |
isRemoveinstalledapk() |
static void |
main(java.lang.String[] args) |
void |
pass(java.lang.String message) |
protected void |
pause(int millis) |
protected boolean |
preparation()
Install the apk of SAFSTCPMessenger and SAFSTestRunner
Forward the tcp port from on-computer-2411 to on-device-2410 |
boolean |
prepareDevice() |
void |
process()
A template method.
|
(package private) void |
removeInstalledAPK() |
protected void |
scrollToBottoum() |
protected void |
scrollToTop() |
void |
setAUTApk(java.lang.String autApk) |
void |
setInstallAUT(boolean installAUT) |
void |
setInstallMessenger(boolean installMessenger) |
void |
setInstallRunner(boolean installRunner) |
void |
setInstrumentArg(java.lang.String instrumentArg) |
void |
setMessengerApk(java.lang.String messengerApk) |
void |
setProtocolDebug(boolean enableProtocolDebug)
Turn on or off the protocol's debug message
|
void |
setRebuildRunner(boolean rebuildRunner)
Rebuilding testrunner will depend on
autApk and testRunnerSourceDir |
void |
setRemoveinstalledapk(boolean removeinstalledapk) |
void |
setResignJar(java.lang.String resignJar) |
void |
setRunnerDebug(boolean enableRunnerDebug)
Turn on or off the runner's debug message
|
void |
setTestRunnerApk(java.lang.String testRunnerApk) |
void |
setTestRunnerSourceDir(java.lang.String testRunnerSourceDir) |
protected boolean |
stopEmulator()
Stop the emulator launched by us only if we have launched it and
we don't want to persist it. |
protected boolean |
terminate()
Terminate the remote engine.
Terminate the local controller runner. Terminate the emulator if we have started it. You will not modify this method in the sub-class. |
protected void |
test()
Use solo and engine to test.
You will extend this method in the sub-class, normally In the SAFSTestRunner project, there is a file AndroidManifest.xml: There is a tag For example, android:targetPackage="your.test.application.package" And you need to override this method to do the test work. |
void |
warn(java.lang.String message) |
protected java.lang.String |
wrapRegex(java.lang.String text)
Wrap the text with regex prefix and suffix ".*"
When you call some method like Solo.clickOnText(String) , the parametercan be regex string to match more, you can call this method to wrap the parameter. |
public Solo solo
public SAFSEngineCommands engine
public SAFSDriverCommands driver
public RobotiumUtils robotiumUtils
public Timeout robotiumTimeout
protected java.lang.String avdSerialNo
protected boolean persistEmulators
protected boolean weLaunchedEmulator
protected boolean unlockEmulatorScreen
protected java.lang.String mainActivityUID
initialize()
goBackToViewUID(String)
to prevent infinite loop.public boolean argAUTpassed
public boolean argMESSENGERpassed
public boolean argRUNNERpassed
public boolean argINSTRUMENTpassed
public boolean argRESIGNJARpassed
public boolean argRUNNERSOURCEpassed
public boolean removeinstalledapk
public static final java.lang.String DEFAULT_AUT_APK
DEFAULT_AUT_APK
according to your system.DEFAULT_MESSENGER_APK
according to your system.DEFAULT_TESTRUNNER_APK
according to your system.DEFAULT_TESTRUNNER_SOURCE_DIR
according to your system.DEFAULT_INSTRUMENT_ARG
according to your system.public static final java.lang.String DEFAULT_MESSENGER_APK
public static final java.lang.String DEFAULT_TESTRUNNER_APK
public static final java.lang.String DEFAULT_TESTRUNNER_SOURCE_DIR
public static final java.lang.String DEFAULT_INSTRUMENT_ARG
public static final java.lang.String ARG_KEY_RESIGN_JAR
public static final java.lang.String ARG_KEY_AUT_APK
public static final java.lang.String ARG_KEY_MESSENGER_APK
public static final java.lang.String ARG_KEY_TESTRUNNER_APK
public static final java.lang.String ARG_KEY_TESTRUNNER_SOURCE
public static final java.lang.String ARG_KEY_INSTRUMENT_ARG
public static final java.lang.String ARG_KEY_AVD
public static final java.lang.String ARG_KEY_PERSIST_AVD
public static final java.lang.String ARG_KEY_NO_MESSENGER
public static final java.lang.String ARG_KEY_NO_RUNNER
public static final java.lang.String ARG_KEY_NO_AUT
public static final java.lang.String ARG_KEY_REMOVE_INSTALLED_APK
public SoloTest()
public SoloTest(java.lang.String messengerApk, java.lang.String testRunnerApk, java.lang.String instrumentArg)
public SoloTest(java.lang.String[] args)
args
- Array of Strings: "aut=xxx", "messenger=xxx", "runner=xxx", "runnersource=xxx", "instrument=xxx"public java.lang.String getTestRunnerSourceDir()
public void setTestRunnerSourceDir(java.lang.String testRunnerSourceDir)
public boolean isRemoveinstalledapk()
public void setRemoveinstalledapk(boolean removeinstalledapk)
public java.lang.String getResignJar()
public void setResignJar(java.lang.String resignJar)
public java.lang.String getAUTApk()
public void setAUTApk(java.lang.String autApk)
public java.lang.String getMessengerApk()
public void setMessengerApk(java.lang.String messengerApk)
public java.lang.String getTestRunnerApk()
public void setTestRunnerApk(java.lang.String testRunnerApk)
public java.lang.String getInstrumentArg()
public void setInstrumentArg(java.lang.String instrumentArg)
public void setProtocolDebug(boolean enableProtocolDebug)
enable
- public void setRunnerDebug(boolean enableRunnerDebug)
enable
- public void setInstallAUT(boolean installAUT)
public void setInstallMessenger(boolean installMessenger)
public void setInstallRunner(boolean installRunner)
public void setRebuildRunner(boolean rebuildRunner)
autApk
and testRunnerSourceDir
rebuildRunner
- public final void process()
preparation()
,
initialize()
,
test()
,
terminate()
protected final boolean preparation()
public boolean prepareDevice()
protected final boolean initialize()
protected final boolean terminate()
final void removeInstalledAPK()
protected final boolean stopEmulator()
protected void test()
public void debug(java.lang.String message)
public void info(java.lang.String message)
public void warn(java.lang.String message)
public void pass(java.lang.String message)
public void fail(java.lang.String message)
public void error(java.lang.String message)
protected void goBackToViewUID(java.lang.String viewUID) throws java.lang.Exception
viewUID
- java.lang.Exception
protected void pause(int millis)
protected void scrollToTop()
protected void scrollToBottoum()
protected java.lang.String wrapRegex(java.lang.String text)
Solo.clickOnText(String)
, the parametertext
- Stringpublic static void main(java.lang.String[] args)
args
- Array of String passed from command line:
messenger=xxx
runner=xxx
runnersource=xxx
instrument=xxxCopyright © SAS Institute. All Rights Reserved.