简介:
刚开始porting 1.0的case到2.0上的时候,发现2.0的log现在输出到了android log里面,必须使用logcat才能抓取出来
这样给开发人员,调试case带来很多麻烦。
代码里面System.out.println()输出log的方法应该可以用,只是最后也输出到的android log里面,tag为System.out
同时保存截图时候,无法保存到sdcard下
1.截图问题原因及解决方法
public void takeScreenshot(String name) {
Log.d(TAG, "takeScreenshot");
String dir = String.format("%s/%s", Environment.getExternalStorageDirectory().getPath(), "screen");
Log.d(TAG,dir);
File theDir = new File(dir);
if (!theDir.exists()) {
theDir.mkdirs();
}
device.takeScreenshot(new File(String.format("%s/%s", dir, name)));
}
logcat抓到log是没有权限创建文件夹(androidManifest上已经添加了读写SDCARD的权限)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
原因:在androidM以后对于权限问题要求很严格,但是androidM/N,为了兼容以前的apk,所以当SDK API <23时候,权限问题要求就
小很多
解决方法:targetSdkVersion22
defaultConfig {
applicationId "com.example.zhenyang.helloui"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
2. 输出log到控制台
public void log(String info){
Bundle bundle = new Bundle();
bundle.clear();
bundle.putString("System.out"," "+info);
instrumentation.sendStatus(0,bundle);
}
效果如下: