0

我正在尝试使用MonkeyTalk来自动化我的 Android 应用程序中的黑盒测试。我面临的问题是他们没有任何关于在 Maven 中使用它的文档。所以,经过大量的研究和尝试很多事情,我使构建工作。但是,当我安装 MonkeyTalk 代理时,我的应用程序崩溃了。

我不知道我的构建是否有问题,或者 MonkeyTalk 代理是否与我正在使用的库不兼容。所以,这是我用 maven 构建的:

首先,我下载了 MonkeyTalk 并使用以下命令安装了代理的 JAR:

mvn install:install-file -Dfile=monkeytalk-agent-1.0.53.jar -DgroupId="com.gorillalogic.monkeytalk" -DartifactId="monkeytalk-agent" -Dversion="1.0.53" -Dpackaging="jar"

因此,我添加了以下依赖项:

<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>

而且,由于我不希望每个版本都包含 MonkeyTalk 代理,所以我创建了一个配置文件,如下所示:

<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>

使用此配置,构建可以正常工作。我在日志中看到 aspectj 插件正在配置 MonkeyTalk。这是日志的一部分:

[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))

好的,但是当我安装应用程序并尝试打开它时,我只能打开第一个屏幕,这是最简单的,只有一些按钮可以通过社交网络登录或打开另一个 Activity。但是当我打开另一个更复杂的 Activity 时,应用程序崩溃了。这很奇怪,因为在每个 Android 版本中,它都会崩溃并出现不同的异常。

例如,此异常发生在 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

在 Android 2.2 中,我有这个例外:

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)

有更多使用 MonkeyTalk 经验的人知道为什么它的代理会破坏我的应用程序吗?这是我的Maven配置吗?

4

1 回答 1

1

如果 requestFeature 是可选的,请尝试删除该代码行。

或者按照上面的说明将代码行放在 super.onCreate() 之上。

这个博客可能会提到同样的问题。

于 2013-11-27T11:03:19.683 回答