I'm trying to use the MonkeyTalk to automate the black-box tests in my Android app. The problem I'm facing is that they don't have anything documented about using it with Maven. So, after a lot of research and trying a lot of things, I made the build to work. But, my app is crashing when I install the MonkeyTalk agent.
I don't know if it's something wrong with my build or if the MonkeyTalk agent is incompatible with the libraries I'm using. So, here is what I've done to build with maven:
First, I've downloaded the MonkeyTalk and installed the JAR of the agent using this command:
mvn install:install-file -Dfile=monkeytalk-agent-1.0.53.jar -DgroupId="com.gorillalogic.monkeytalk" -DartifactId="monkeytalk-agent" -Dversion="1.0.53" -Dpackaging="jar"
So, I added the following dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
<scope>provided</scope>
</dependency>
And, since I don't want the MonkeyTalk agent to be included in every release, I've created a profile as follows:
<profile>
<id>monkeytalk</id>
<dependencies>
<dependency>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-agent</artifactId>
<version>1.0.53</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<aspectLibraries>
<aspectLibrary>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-agent</artifactId>
</aspectLibrary>
</aspectLibraries>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<outxml>true</outxml>
</configuration>
<executions>
<execution>
<!--<phase>process-sources</phase>-->
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
With this configuration, the build works normally. I see in the log that the aspectj plugin is configuring the MonkeyTalk. Here is part of the log:
[INFO] Join point 'method-call(void android.widget.TextView.setText(java.lang.CharSequence))' in Type 'com.devspark.appmsg.AppMsg' (AppMsg.java:144) advised by before advice from 'com.gorillalogic.fonemonkey.aspects.SetText' (monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
[INFO] Join point 'method-call(void com.devspark.appmsg.AppMsg.setText(java.lang.CharSequence))' in Type 'com.devspark.appmsg.AppMsg' (AppMsg.java:286) advised by before advice from 'com.gorillalogic.fonemonkey.aspects.SetText' (monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
[INFO] Join point 'method-call(void android.widget.TextView.setText(java.lang.CharSequence))' in Type 'com.devspark.appmsg.AppMsg' (AppMsg.java:302) advised by before advice from 'com.gorillalogic.fonemonkey.aspects.SetText' (monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
Ok, but when I install the app and try to open it, I can only open the first screen, that is the most simple, having just some buttons that either login via a social network or open another Activity. But when I open another Activity, that is much more complex, the app crashes. And it's very strange, because in each Android version, it crashes with a different exception.
This exception, for example, happens with Android 4.3:
08-22 16:49:54.012: INFO/ActivityManager(534): START u0 {cmp=com.soongz/.ui.CadastroActivity} from pid 17633
08-22 16:49:54.803: ERROR/AndroidRuntime(17633): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.soongz/com.soongz.ui.CadastroActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
at android.app.Activity.requestWindowFeature(Activity.java:3264)
at android.support.v7.app.ActionBarActivityDelegateICS.supportRequestWindowFeature(ActionBarActivityDelegateICS.java:126)
at android.support.v7.app.ActionBarActivity.supportRequestWindowFeature(ActionBarActivity.java:150)
at com.soongz.ui.BaseActionBarActivity.createView(BaseActionBarActivity.java:72)
at com.soongz.ui.CadastroActivity.createView(CadastroActivity.java:110)
at br.com.cybereagle.androidlibrary.ui.helper.RetainedActivityHelper.onCreate(RetainedActivityHelper.java:42)
at br.com.cybereagle.androidlibrary.ui.RetainedRoboActionBarActivity.onCreate(RetainedRoboActionBarActivity.java:45)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 11 more
08-22 16:49:54.813: WARN/ActivityManager(534): Force finishing activity com.soongz/.ui.CadastroActivity
08-22 16:49:54.813: WARN/ActivityManager(534): Force finishing activity com.soongz/.ui.MainActivity
In Android 2.2, I have this exception:
08-22 17:32:32.503: ERROR/AndroidRuntime(698): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.gorillalogic.fonemonkey.automators.AutomationManager
at com.gorillalogic.fonemonkey.aspects.SetListener.ajc$after$com_gorillalogic_fonemonkey_aspects_SetListener$1$bfeaeda5(SetListener.aj:30)
at com.soongz.service.autenticacao.AbstractAutenticador.<init>(AbstractAutenticador.java:51)
at com.soongz.service.autenticacao.AutenticadorFacebook.<init>(AutenticadorFacebook.java:38)
at com.soongz.ui.MainActivity.initializeUnretainedInstanceFields(MainActivity.java:54)
at br.com.cybereagle.androidlibrary.ui.helper.RetainedActivityHelper.onCreate(RetainedActivityHelper.java:34)
at br.com.cybereagle.androidlibrary.ui.RetainedRoboFragmentActivity.onCreate(RetainedRoboFragmentActivity.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Does someone with more experience with MonkeyTalk knows why its agent is breaking my app? Is it my maven configuration?