Selendroid 不会启动某些应用程序

Selendroid won't start some apps

我得到了在设备上启动应用程序的平均设置,有时它工作得很好(应用程序启动并可以由 selendroid 控制)有时(在 firefox.apk 的情况下)会发生这种情况:

Aug 10, 2015 3:02:13 PM io.selendroid.standalone.io.ShellCommand exec
INFORMATION: Executing shell command: C:\Users\Dustin Altermann\AppData\Local\Android\sdk\platform-tools\adb.exe -s BX903DKMSR shell am instrument -e main_activity -e server_port 8080 io.selendroid.org.mozilla.firefox/io.selendroid.server.ServerInstrumentation
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.io.ShellCommand exec
INFORMATION: Shell command output
-->
usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P ] [--start-profiler ]
[--R COUNT] [-S] [--opengl-trace]
am startservice
am force-stop
am kill
am kill-all
am broadcast
am instrument [-r] [-e ] [-p ] [-w]
[--no-window-animation]
am profile start
am profile stop []
am dumpheap [flags]
am set-debug-app [-w] [--persistent]
am clear-debug-app
am monitor [--gdb ]
am screen-compat [on|off]
am display-size [reset|MxN]
am to-uri [INTENT]
am to-intent-uri [INTENT]

am start: start an Activity. Options are:
-D: enable debugging
-W: wait for launch to complete
--start-profiler : start profiler and send results to
-P : like above, but profiling stops when app goes idle
-R: repeat the activity launch times. Prior to each repeat,
the top activity will be finished.
-S: force stop the target app before starting the activity
--opengl-trace: enable tracing of OpenGL functions

am startservice: start a Service.

am force-stop: force stop everything associated with .

am kill: Kill all processes associated with . Only kills.
processes that are safe to kill -- that is, will not impact the user experience.

am kill-all: Kill all background processes.

am broadcast: send a broadcast Intent.

am instrument: start an Instrumentation. Typically this target is the form /. Options are:
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with
[-e perf true] to generate raw output for performance measurements.
-e : set argument to . For test runners a
common form is [-e [,...]].
-p : write profiling data to
-w: wait for instrumentation to finish before returning. Required for test runners.
--no-window-animation: turn off window animations will running.

am profile: start and stop profiler on a process.

am dumpheap: dump the heap of a process. Options are:
-n: dump native heap instead of managed heap

am set-debug-app: set application to debug. Options are:
-w: wait for debugger when application starts
--persistent: retain this value

am clear-debug-app: clear the previously set-debug-app.

am monitor: start monitoring for crashes or ANRs.
--gdb: start gdbserv on the given port at crash/ANR

am screen-compat: control screen compatibility mode of .

am display-size: override display size.

am to-uri: print the given Intent specification as a URI.

am to-intent-uri: print the given Intent specification as an intent: URI.

specifications include these flags and arguments:
[-a ] [-d ] [-t ]
[-c [-c ] ...]
[-e|--es ...]
[--esn ...]
[--ez ...]
[--ei ...]
[--el ...]
[--ef ...]
[--eu ...]
[--ecn ]
[--eia [, [--ela [, [--efa [, [-n ] [-f ]
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--selector]
[ | | ]

Error: Bad component name: server_port
<--
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.io.ShellCommand exec
INFORMATION: Executing shell command: C:\Users\Dustin Altermann\AppData\Local\Android\sdk\platform-tools\adb.exe -s BX903DKMSR forward tcp:8080 tcp:8080
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.io.ShellCommand exec
INFORMATION: Shell command output
-->

<--
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.android.impl.AbstractDevice startLogging
INFORMATION: starting logcat:
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.server.model.SelendroidStandaloneDriver waitForServerStart
INFORMATION: Waiting for the Selendroid server to start.
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.android.impl.AbstractDevice isSelendroidRunning
INFORMATION: Checking if the Selendroid server is running: http://localhost:8080/wd/hub/status
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8080: Connection reset
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: Retrying request to {}->http://localhost:8080
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8080: Connection reset
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: Retrying request to {}->http://localhost:8080
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8080: Connection reset
Aug 10, 2015 3:02:13 PM org.apache.http.impl.execchain.RetryExec execute
INFORMATION: Retrying request to {}->http://localhost:8080
Aug 10, 2015 3:02:13 PM io.selendroid.standalone.android.impl.AbstractDevice isSelendroidRunning
INFORMATION: Can't connect to Selendroid server, assuming it is not running.

应用程序无法启动,selendroid 一直在尝试但没有任何反应。我可以毫无问题地手动启动该应用程序。 我不明白其中的区别或如何缩小问题范围。

顺便说一句:如果有人想自己尝试,我使用了 Google Play 商店中的 firefox.apk。

好的,我终于做到了:

问题是这个特定的应用程序有一个使用标签 "activity-alias" 的 AndroidManifest.xml 文件(使用例如 https://code.google.com/p/xml-apk-parser/ 读取它)。在这个标签内有 Selendroid 需要确定所谓的 "main_activity":

的字段
<activity-alias android:label="Firefox" android:name=".App" android:targetActivity="org.mozilla.gecko.BrowserApp">
    <intent-filter android:priority="999">
        <action android:name="android.intent.action.MAIN">
        </action>
        <category android:name="android.intent.category.LAUNCHER">
        </category>
        <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER">
        </category>
        <category android:name="android.intent.category.DEFAULT">
        </category>
    </intent-filter>

不幸的是,Selendroid 不理解这个标签,因此找不到 "main_activity"。

解决方案:我不得不使用"SelendroidCapabilities.setLaunchActivity"-方法来明确告诉Selendroidactivity使用什么:

SelendroidCapabilities caps = new SelendroidCapabilities("org.mozilla.firefox:39.0");
caps.setLaunchActivity("org.mozilla.gecko.BrowserApp");