Selendroid无法启动某些应用程序。

3

我得到了启动设备应用的平均设置,有时候它可以完美地工作(应用程序可以通过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。

你可以尝试使用不同的端口。不知道你是通过命令行还是从代码中启动selendroid服务器。 - Madis Kangro
我正在从代码中启动服务器,已经尝试更改端口但没有解决问题,而且其他应用程序在该端口上工作正常。我已经能够将问题缩小到“main_activity”丢失。但我仍然不知道Selendroid从哪里获取它,以及它怎么可能会丢失...?! - dustin
1个回答

1

好的,我终于做到了:

问题在于这个特定的应用程序有一个AndroidManifest.xml文件(可以使用例如https://code.google.com/p/xml-apk-parser/读取),使用标签“activity-alias”。在这个标签内部,有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”方法来明确告诉Selendroid要使用哪个活动:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接