编写集成测试的人肯定听说过Spoon和Spoon-Gradle-Plugin,它们为您的测试提供了有用的功能。我正在使用stanfy/spoon-gradle-plugin。
我在测试中使用类com.squareup.spoon.Spoon.java
提供的截图方法。在我通过"./gradlew spoon"
命令运行测试后,它为我生成xml文件,其中包含每个测试的日志和屏幕截图。这适用于系统版本低于6.0的每个Android设备。当我使用Marshmallow在设备上运行测试时,我的控制台在测试结束时看起来像这样:
2015-12-18 15:58:00 [STRL.testRunEnded] elapsedTime=408847
03:58:00 I/XmlResultReporter: XML test result file generated at /Users/F1sherKK/Dev/myapp-Android/app/build/spoon-log/normal/debugRelease/junit-reports/05f3785c3444f1bf.xml. Total tests 32, failure 1, passed 31,
2015-12-18 15:58:00 [SDR.run] About to grab screenshots and prepare output for [05f3785c3444f1bf]
2015-12-18 15:58:00 [SDR.pullDirectory] Internal path is /data/data/com.myapp.sendmoney.debug1/app_spoon-screenshots
2015-12-18 15:58:00 [SDR.pullDirectory] External path is /sdcard/app_spoon-screenshots
2015-12-18 15:58:00 [SDR.pullDirectory] Pulling files from external dir on [05f3785c3444f1bf]
2015-12-18 15:58:05 [SDR.pullDirectory] Pulling files from internal dir on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.pullDirectory] Done pulling app_spoon-screenshots from on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.pullDirectory] Internal path is /data/data/com.myapp.sendmoney.debug1/app_spoon-files
2015-12-18 15:58:06 [SDR.pullDirectory] External path is /sdcard/app_spoon-files
2015-12-18 15:58:06 [SDR.pullDirectory] Pulling files from external dir on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.pullDirectory] Pulling files from internal dir on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.pullDirectory] Done pulling app_spoon-files from on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.handleImages] Moving screenshots to the image folder on [05f3785c3444f1bf]
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.flowtests.NotificationCenterActivity.NotificationCenterActivityFunctionTest#assertReferralPopUpWillAppear
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.flowtests.NotificationCenterActivity.NotificationCenterActivityFunctionTest#assertReferralPopUpWillHide
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#addMockItem_newMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#clickOnBackButton_returnToNotificationCenter
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#clickOnBackButton_returnToNotificationCenter
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#clickOnBackButton_returnToNotificationCenter
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#clickOnBackButton_returnToNotificationCenter
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.CustomerServiceActivity.CustomerServiceNavigator#clickOnItem_referralType
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.General.GeneralNavigator#sendNotification_addSampleMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.General.GeneralNavigator#sendNotification_addSampleMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.General.GeneralNavigator#sendNotification_addSampleMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.General.GeneralNavigator#sendNotification_addSampleMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.General.GeneralNavigator#sendNotification_addSampleMessage
2015-12-18 15:58:06 [SDR.handleImages] Unable to find test for com.myapp.sendmoney.instrumentation.navigation.activity.InviteFriendsActivity.InviteFriendsNavigator#clickOnBackButton_returnToCustomerService
因此,当我看到这个问题时,我首先想到的是...自android 6.0以来更改权限处理的问题。所以我想如果我提供
WRITE_EXTERNAL_STORAGE
和
READ_EXTERNAL_STORAGE
我的应用程序的权限应该有效。所以我创建了这个简单的shell脚本来检测SDK版本,如果它等于或高于23,那么在测试开始之前授予我的包的权限。
SDK=`adb shell getprop ro.build.version.sdk | tr -d '\r'`
if (( "$SDK" >= 23 )) ; then
adb shell pm grant com.myapp.sendmoney.debug1 android.permission.WRITE_EXTERNAL_STORAGE
adb shell pm grant com.myapp.sendmoney.debug1 android.permission.READ_EXTERNAL_STORAGE
fi
./gradlew spoon
似乎我的权限已被授予,但在测试开始后,我仍然无法从设备中提取屏幕截图。
我的第二个想法是。好的,如果这不是权限问题,那么也许没有截屏要拉。测试完成后,Spoon会清除设备中的屏幕截图。我开始测试,等到其中一些完成然后在我的控制台ctrl + C中杀死进程。我打开了Android设备监视器,我可以看到我测试的屏幕截图在那里等待拉动。仍然没有发生。
所以我的第三个想法是。好的,如果那些没有权限和截图功能的设备在6.0设备上工作正常,那么也许这是一个勺子问题。我试图在网上寻找类似的主题,但没有一个与我的案例直接相关。
我找到this issue,但它没有解决我的问题。我没有使用UIAutomator
截取屏幕截图,而是Spoon的截图方法。
There is我现在正在努力解决一个问题,但是我做了建议的事情并没有帮助。
而且there在4天前得到了一些修复,但我现在仍然面临问题而且我的libs是最新的:
dependencies {
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.squareup.spoon:spoon-client:1.2.1'
androidTestCompile 'com.jraska:falcon-spoon-compat:0.3.1'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support:recyclerview-v7:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
androidTestCompile "org.mockito:mockito-core:1.10.19"
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
}
和
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
(...)
classpath 'com.squareup.spoon:spoon-runner:1.2.1'
classpath ('com.stanfy.spoon:spoon-gradle-plugin:1.0.4-SNAPSHOT') {
exclude module: "guava"
}
classpath 'com.google.guava:guava:18.0'
}
所以...也许我错过了一些东西。也许还有我忘了的另一个许可。我很感激任何建议。