Appium 当 apk 包的 activity 与打开应用后其它的 activity 不匹配时候,应该怎么办?

sincool · 2015年11月26日 · 最后由 sincool 回复于 2015年11月26日 · 2136 次阅读
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = 'SM-N9100'
desired_caps['app'] = 'C:\\Users\\cvtpc\\Downloads\\youqianhua.apk'
desired_caps['appPackage'] = 'com.youqian.activity'
desired_caps['appActivity'] = 'com.youqian.activity.guide.SplashActivity'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
sleep(3)

driver.keyevent(26)

driver.quit()

appium 配置的 activity 选择的是 com.youqian.activity.guide.SplashActivity,运行以上代码报错:
Original error: com.youqian.activity/.guide.SplashActivity never started. Current: com.youqian.activity/.guide.GuideActivity
但是我去掉

driver.keyevent(26)

driver.quit()

去掉这 2 行,可以运行成功,就是安装和打开,不报错。
这个报错的意思是我应该用'com.youqian.activity.guide.GuideActivity,而不是 SplashActivity

然后我就在 appium 中把 activity 改成 com.youqian.activity.guide.GuideActivity,代码中也改成对应的 activity,但是因为这个 apk 包实际上就是 com.youqian.activity.guide.GuideActivity 打包,所以毫无疑问,根本运行不起来。。。

我问了开发,关于打包,是有 2 个 JAVA,一个 SplashActivity.java,一个是 GuideActivity.java,都可以使用
是不是 apk 包打成了 SplashActivity 但实际上里面的操作使用的却是 GuideActivity 的内容,所以导致有问题????

共收到 3 条回复 时间 点赞

应用首次启动,有引导活动

desired_caps['appPackage'] = 'com.youqian.activity'
desired_caps['appWaitActivity'] = '.guide.GuideActivity'
desired_caps['appActivity'] = '.guide.SplashActivity'

非首次启动,进入登录活动

desired_caps['appPackage'] = 'com.youqian.activity'
desired_caps['appWaitActivity'] = '.account.LoginActivity'
desired_caps['appActivity'] = '.guide.SplashActivity'

adb logcat -b events | findstr com.youqian查看日志

应用首次启动:

I/am_create_activity(  672): [0,1116450712,82,com.youqian.activity/.guide.SplashActivity,android.intent.action.MAIN,NULL,NULL,270532608]
I/am_restart_activity(  672): [3930,1116450712,82,com.youqian.activity/.guide.SplashActivity]
I/am_create_activity(  672): [0,1116775088,82,com.youqian.activity/.guide.GuideActivity,NULL,NULL,NULL,0]
I/am_pause_activity(  672): [3930,1116450712,com.youqian.activity/.guide.SplashActivity]
I/am_finish_activity(  672): [0,1116450712,82,com.youqian.activity/.guide.SplashActivity,app-request]
I/am_restart_activity(  672): [3930,1116775088,82,com.youqian.activity/.guide.GuideActivity]
I/am_on_resume_called( 3930): [0,com.youqian.activity.guide.GuideActivity]
I/am_destroy_activity(  672): [0,1116450712,82,com.youqian.activity/.guide.SplashActivity,finish-idle]
I/am_activity_launch_time(  672): [0,1116775088,com.youqian.activity/.guide.GuideActivity,148,285]

非首次启动:

I/am_create_activity(  672): [0,1123634640,83,com.youqian.activity/.guide.SplashActivity,android.intent.action.MAIN,NULL,NULL,270532608]
I/am_restart_activity(  672): [3930,1123634640,83,com.youqian.activity/.guide.SplashActivity]
I/am_create_activity(  672): [0,1126943744,83,com.youqian.activity/.account.LoginActivity,NULL,NULL,NULL,0]
I/am_pause_activity(  672): [3930,1123634640,com.youqian.activity/.guide.SplashActivity]
I/am_finish_activity(  672): [0,1123634640,83,com.youqian.activity/.guide.SplashActivity,app-request]
I/am_restart_activity(  672): [3930,1126943744,83,com.youqian.activity/.account.LoginActivity]
I/am_on_resume_called( 3930): [0,com.youqian.activity.account.LoginActivity]
I/am_destroy_activity(  672): [0,1123634640,83,com.youqian.activity/.guide.SplashActivity,finish-idle]
I/am_activity_launch_time(  672): [0,1126943744,com.youqian.activity/.account.LoginActivity,143,253]

所以你们的应用每次启动都会有个短暂的黑屏

#2 楼 @sanlengjingvv 感谢感谢,问题已解决!

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