Appium 脚本在 4.4 运行成功,但在 4.1 上运行提示 appPackage/appActivity never started

panzhigang · 2014年07月16日 · 最后由 Moon 回复于 2015年08月30日 · 2363 次阅读

appium 1.2.0 android 4.1.1
启动代码如下:

public void setUp() throws Exception
{
    // 配置webdriver
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("automationName", "Selendroid");
    capabilities.setCapability("platformName", "Android");      
    capabilities.setCapability("deviceName", "192.168.56.101:5555");
    capabilities.setCapability("platformVersion", "4.1.1");
    capabilities.setCapability("app", "D:\\workspace\\wapjs_client\\apps\\jsmcc.apk");
    capabilities.setCapability("appPackage", "com.jsmcc");
    capabilities.setCapability("appActivity", ".ui.WelcomeActivity");
    // appium的独特地方,使用自己的AppiumDriver, 它本身是继承自WebDriver
    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

appium 报错日志为:

debug: Selendroid server is alive!
debug: Listening for Selendroid logs
debug: Creating Selendroid session
debug: Making http request with opts: {"url":"http://localhost:8080/wd/hub/sessi
on","method":"POST","json":{"desiredCapabilities":{"warnings":{},"desired":{"aut
omationName":"Selendroid","platformVersion":"4.1.1","app":"D:\\workspace\\wapjs_
client\\apps\\jsmcc.apk","platformName":"Android","deviceName":"192.168.56.101:5
555","browserName":"","appActivity":".ui.WelcomeActivity","appPackage":"com.jsmc
c"},"automationName":"Selendroid","platformVersion":"4.1.1","app":"D:\\workspace
\\wapjs_client\\apps\\jsmcc.apk","platformName":"Android","deviceName":"192.168.
56.101:5555","browserName":"","appActivity":".ui.WelcomeActivity","appPackage":"
com.jsmcc"}}}
debug: Successfully started selendroid session
debug: Waiting for pkg "com.jsmcc" and activity ".ui.WelcomeActivity" to be focu
sed
debug: Getting focused package and activity
debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "dumpsys window windows"
debug: [SELENDROID] http://localhost:8080/wd/hub/session/5ad873c4-d754-cd01-a387
-42a1aa5de440
debug: Getting focused package and activity
debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "dumpsys window windows"
debug: Getting focused package and activity
debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "dumpsys window windows"
error: com.jsmcc/.ui.WelcomeActivity never started. Current: com.jsmcc/.ui.Featu
reActivity
debug: Selendroid hasn't started app yet, let's do it manually with adb.startApp

debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "am start -S -a android.intent.action.MAIN -c android.intent.category
.LAUNCHER -f 0x10200000 -n com.jsmcc/.ui.WelcomeActivity"
debug: Waiting for pkg "com.jsmcc" and activity ".ui.WelcomeActivity" to be focu
sed
debug: Getting focused package and activity
debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "dumpsys window windows"
debug: Getting focused package and activity
debug: executing: "F:\android_sdk\sdk\platform-tools\adb.exe" -s 192.168.56.101:
5555 shell "dumpsys window windows"
debug: Getting focused package and activity
....
error: com.jsmcc/.ui.WelcomeActivity never started. Current: com.android.launche
r/com.android.launcher2.Launcher
debug: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: com.jsmcc/.ui.WelcomeA
ctivity never started. Current: com.android.launcher/com.android.launcher2.Launc
her
debug: Error: com.jsmcc/.ui.WelcomeActivity never started. Current: com.android.
launcher/com.android.launcher2.Launcher
    at null.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules
\appium\node_modules\appium-adb\lib\adb.js:1273:12)
    at null.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules
\appium\node_modules\appium-adb\lib\adb.js:1218:7)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modul
es\appium-adb\lib\adb.js:162:5
    at ChildProcess.exithandler (child_process.js:635:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Socket.<anonymous> (child_process.js:956:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:465:12)
debug: Responding to client with error: {"status":33,"value":{"message":"A new s
ession could not be created. (Original error: com.jsmcc/.ui.WelcomeActivity neve
r started. Current: com.android.launcher/com.android.launcher2.Launcher)","origV
alue":"com.jsmcc/.ui.WelcomeActivity never started. Current: com.android.launche
r/com.android.launcher2.Launcher"},"sessionId":null}

有没有谁碰到这样的问题啊?求大神帮助

共收到 10 条回复 时间 点赞
am start -S -a android.intent.action.MAIN -c android.intent.category
.LAUNCHER -f 0x10200000 -n com.jsmcc/.ui.WelcomeActivity

执行下这句看看,是不是能启动,还是启动后挂掉了?

@seveniruby 执行后显示,模拟器上是启动成功的

C:\Users\Administrator>adb shell
root@android:/ # am start -S -a android.intent.action.MAIN -c android.intent.cat
egory.LAUNCHER -f 0x10200000 -n com.jsmcc/.ui.WelcomeActivity
AUNCHER -f 0x10200000 -n com.jsmcc/.ui.WelcomeActivity                        <
Stopping: com.jsmcc
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.L
AUNCHER] flg=0x10200000 cmp=com.jsmcc/.ui.WelcomeActivity }

菜鸟表示不懂 appium,看你错误信息,没有启动 WelcomeActivity,是不是 WelcomeActivity 只在安装的时候启动 App 才会到这个 Activity 呢?再次启动就不经过该 Activity 呢?
只是一点点分析,如有误,请忽略。

appium 1.2 版,不用指定 appPackage 和 appActivity 了,只用正确指定 app 安装路径就 ok 了。appium 会自动识别。我现在跑脚本都没指定了。。

@kevinqinan WelcomeActivity 是一个欢迎页,要是换成别的话,页面不会成功加载,显示一半

@tianwei024 我试了下不指定 appPackage 和 appActivity,还是一样的错误,appium 版本是 1.2.0

LZ 的问题解决了吗?

@developer_luffy 还没有解决。。。

@panzhigang 我也遇见了,
我发的帖子,http://testerhome.com/topics/1455
楼主这个问题解决了吗?

解决方法:
设置多一个 capability, 如下
capabilities.setCapability("appWaitActivity", ".当前 activity");

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册