Can somebody please give me the detailed steps involved in configuring Ant for Android project with MonkeyTalk. I have an Android project, MonkeyTalk agent and AntRunner.
I need to automate the Android build generation using Ant also, MonkeyTalk should be integrated in the build.
Is this possible using AntRunner?
For Dynamic instrumentation, you can try below sample Ant script:
<target name="instru">
<mt:instrument
src="/path/to/MyApp.apk"
dest="/path/to/MyApp-Instrumented.apk"
agent="/path/to/monkeytalk-agent-2.0.2.jar"
androidSdk="/path/to/android-sdk"
androidTarget="android-19"
log="log.txt"
verbose="true" />
</target>
Save the above script as build.xml , and you can run it from the commandline like this:
ant -lib /path/to/monkeytalkpro-ant-2.0.2.beta.jar instru
MonkeyTalk Professional offers app control of Android apps (see Pro Application Control). The MonkeyTalk Professional Ant library includes an App task to allow you to control the app under test. The App task includes the ability to install, uninstall, launch, start, stop, and restart an application. Currently, only Android is supported.
Here is a sample Ant script that exercises all the app control actions:
<property name="sdk.dir" value="/path/to/android-sdk" />
<property name="packageName" value="com.example.myapp" />
<property name="activityName" value="RootActivity" />
<target name="install">
<mt:app action="install"
binary="Out.apk"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="uninstall">
<mt:app action="uninstall"
packageName="${packageName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="launch">
<mt:app action="launch"
packageName="${packageName}"
activityName="${activityName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="restart">
<mt:app action="relaunch"
packageName="${packageName}"
activityName="${activityName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="stop">
<mt:app action="stop"
packageName="${packageName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="isInstalled">
<mt:app action="isInstalled"
packageName="${packageName}"
androidSdk="${sdk.dir}"
verbose="true" />
<echoproperties prefix="monkeytalk" />
</target>
<target name="isRunning">
<mt:app action="isRunning"
packageName="${packageName}"
androidSdk="${sdk.dir}"
verbose="true" />
<echoproperties prefix="monkeytalk" />
</target>
Running in CI When running tests on a continuous integration (CI) server, like Jenkins, you would typically combine all the above Ant tasks, plus the regular MonkeyTalk Run task for testing (see Ant Runner), into a single Ant script.
Here is a sample Ant script used in CI:
<property name="sdk.dir" value="/path/to/android-sdk" />
<property name="instrumentedApp" value="/path/to/MyApp-Instrumented.apk" />
<property name="packageName" value="com.example.myapp" />
<property name="activityName" value="RootActivity" />
<target name="instru">
<mt:instrument
src="/path/to/MyApp.apk"
dest="${instrumentedApp}"
agent="/path/to/monkeytalk-agent-2.0.2.jar"
androidSdk="${sdk.dir}" />
</target>
<target name="uninstall">
<mt:app action="uninstall"
packageName="${packageName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="install">
<mt:app action="install"
binary="${instrumentedApp}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="launch">
<mt:app action="launch"
packageName="${packageName}"
activityName="${activityName}"
androidSdk="${sdk.dir}"
verbose="true" />
</target>
<target name="test">
<mt:run
agent="AndroidEmulator"
adb="${sdk.dir}/platform-tools/adb"
thinktime="1000"
timeout="10000"
suite="${basedir}/mysuite.mts"
reportdir="${basedir}/myreports"
startup="30"
verbose="true" />
</target>
<target name="all">
<antcall target="instru" />
<antcall target="uninstall" />
<antcall target="install" />
<antcall target="launch" />
<antcall target="test" />
<antcall target="uninstall" />
</target>
The all target in the above script does all the work. First is instruments the app. Then it uninstalls to be sure the target device is clean. Then it installs and launches the instrumented app. Next it runs the MonkeyTalk test suite. And finally, it again uninstalls to clean up after itself. NOTE: this is Android-only (since the Dynamic Instrumentation and App Control are currently only available for Android).
You can run it from the commandline like this:
ant -lib /path/to/monkeytalkpro-ant-2.0.2.beta.jar all