留言
qq:492497451
差点看成《移动测试大圣归来》
spoon 中有这样一段代码,可以参考
/** Download all screenshots from a single device to the local machine. */
private void pullScreenshotsFromDevice(IDevice device) throws Exception {
// Screenshot path on private internal storage, for KitKat and below.
FileEntry internalDir = getScreenshotDirOnInternalStorage();
logDebug(debug, "Internal path is " + internalDir.getFullPath());
// Screenshot path on public external storage, for Lollipop and above.
FileEntry externalDir = getScreenshotDirOnExternalStorage(device);
logDebug(debug, "External path is " + externalDir.getFullPath());
// Sync device screenshots to the local filesystem.
// TODO only pull from one location, based on android version of device
logDebug(debug, "Pulling screenshots from external dir on [%s]", serial);
String localDirName = work.getAbsolutePath();
adbPull(device, externalDir, localDirName);
logDebug(debug, "Pulling screenshots from internal dir on [%s]", serial);
adbPull(device, internalDir, localDirName);
logDebug(debug, "Done pulling screenshots from [%s]", serial);
}
private void adbPull(IDevice device, FileEntry remoteDirName, String localDirName) {
try {
device.getSyncService()
.pull(new FileEntry[] {remoteDirName}, localDirName,
SyncService.getNullProgressMonitor());
} catch (Exception e) {
logDebug(debug, e.getMessage(), e);
}
}
private FileEntry getScreenshotDirOnInternalStorage() {
String appPackage = instrumentationInfo.getApplicationPackage();
String internalPath = "/data/data/" + appPackage + "/" + SCREENSHOT_DIR;
return obtainDirectoryFileEntry(internalPath);
}
private static FileEntry getScreenshotDirOnExternalStorage(IDevice device) throws Exception {
String externalPath = getExternalStoragePath(device) + "/" + SCREENSHOT_DIR;
return obtainDirectoryFileEntry(externalPath);
}
private static String getExternalStoragePath(IDevice device) throws Exception {
CollectingOutputReceiver pathNameOutputReceiver = new CollectingOutputReceiver();
device.executeShellCommand("echo $EXTERNAL_STORAGE", pathNameOutputReceiver);
return pathNameOutputReceiver.getOutput().trim();
}
#5 楼 @sanlengjingvv shell 脚本运行在 Android 上,robotium 也是运行在 Android 上的。
我同意 yangchengtest 的建议,写个 shell 脚本来做传文件的事,然后再 case 中调用就好。
是不是输入过程中光标跳了
其实只要生育能力正常就行。
#17 楼 @yuweixx spoon 源码中对 5.0 及以上的系统是做了处理的,但还是有问题~~
rivate static File obtainScreenshotDirectory(Context context, String testClassName,
String testMethodName) throws IllegalAccessException {
File screenshotsDir;
if (Build.VERSION.SDK_INT >= 21) {
// Use external storage.
screenshotsDir = new File(getExternalStorageDirectory(), "app_" + SPOON_SCREENSHOTS);
} else {
// Use internal storage.
screenshotsDir = context.getDir(SPOON_SCREENSHOTS, MODE_WORLD_READABLE);
}
Nexus 7-Android 5.1.1 截图报错怎么破,是跟 Android5.1.1 系统有关吗:
Caused by: java.lang.IllegalAccessException: Unable to create output dir: /storage/emulated/0/app_spoon-screenshots
Android 4.4.4 的设备无此问题。
mark 先顶后看
点击 “启动” 出现异常