Appium 如何在 Appium 测试代码中指定 Scheme 跳转

张小川 · 2018年03月06日 · 最后由 上帝De助手 回复于 2019年01月10日 · 3308 次阅读

环境:Mac , Appium 1.7.1 ,python
前提:使用 Appium 进行 Android 自动化测试过程中,有部分页面进入过程需要很多操作步骤,所以采取了 Appium 的 start_activity 方法,直接跳转
问题:部分页面不存在直接进入的 Activity ,但是可以通过 Scheme 跳转的方式进入,问题是进入页面,但是存在报错,提示 Activity never started
代码如下

from action.PageAction import *

driver = open_app()
print 'open app finish'
driver.start_activity('com.autohome.usedcar', 'com.autohome.usedcar.uccontent.MainTabActivity') #进入首页,正常执行
print 'start maintab finish'

scheme_url = 'usedcar://scheme.che168.com/salecar?param=%7bc2bState%3a0%7d'
driver.start_activity('com.autohome.usedcar', 'com.autohome.usedcar.uccarlist.SchemeActivity', optional_intent_arguments=scheme_url) #进入发车页
print 'SchemeActivity'
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/zhangbingwei/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","MZJZFQS8WOFEP7Q4","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'com.autohome.usedcar' and fully qualified activity name : 'com.autohome.usedcar.FragmentRootActivity'
[debug] [ADB] Incorrect package and activity. Retrying.[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/zhangbingwei/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","MZJZFQS8WOFEP7Q4","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'com.autohome.usedcar' and fully qualified activity name : 'com.autohome.usedcar.FragmentRootActivity'
[debug] [ADB] Incorrect package and activity. Retrying.[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/zhangbingwei/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","MZJZFQS8WOFEP7Q4","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'com.autohome.usedcar' and fully qualified activity name : 'com.autohome.usedcar.FragmentRootActivity'
[debug] [ADB] Incorrect package and activity. Retrying.[error] [ADB] Error: Error occured while starting App. Original error: 'com.autohome.usedcar.uccarlist.SchemeActivity' never started
    at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13)
    at ADB.callee$0$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/apk-utils.js:101:9)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
 Error: Error occured while starting App. Original error: 'com.autohome.usedcar.uccarlist.SchemeActivity' never started
    at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13)
    at ADB.callee$0$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/apk-utils.js:101:9)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
共收到 4 条回复 时间 点赞

你确定你们的 APP 支持 Schema 跳转吗?需要在 Activity 中设置 intent-filter。Activity 不是你想跳转就跳转到哪的。
还有:你这日志贴太多了。。。贴关键的就可以。。。

arrow 回复

支持,现在的情况是,实际上页面已经跳进去了,但是执行的最后报错,提示 Activity 没有打开, Original error: 'com.autohome.usedcar.uccarlist.SchemeActivity' never started

有了解的吗?还请告知。现在我的 case 能够正常执行,这个就是报了一个错,但是没有影响后续功能。比较想不通

错误信息:Incorrect package and activity. Retrying.[debug] [ADB] Getting focused package and activity
解决方法:在调用 start_activity 方法时,添加 2 个参数(app_wait_package, app_wait_activity)即可。
原因分析:这 2 个参数默认不传的话默认会使用 app_package, app_activity 的值。如果你不使用跳转 scheme 的话就不会有错,因为它们是一致的。一旦你使用的跳转的 scheme,那么久需要对应的添加 app_wait_package, app_wait_activity 的参数,并且要与你跳转的最终页面是一致的。

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