java - React 本机应用程序未从 Espresso-Intent 接收图像
问题描述
我正在编写 Espresso 测试以在我的 React Native 应用程序上运行。我Espresso-Intents
用来模拟用户拍照,代码如下:
public void takePicture() {
Instrumentation.ActivityResult result = createImageCaptureActivityResultStub();
intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result);
clickText("Camera");
}
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
// Log exception
System.out.println(e.toString());
return null;
}
}
private Instrumentation.ActivityResult createImageCaptureActivityResultStub() {
// Put the drawable in a bundle.
Bundle bundle = new Bundle();
bundle.putParcelable("data", getBitmapFromURL("https://vignette.wikia.nocookie.net/the-feed-your-pets-community/images/6/69/Banana.png/revision/latest?cb=20180527162222"));
// Create the Intent that will include the bundle.
Intent resultData = new Intent();
resultData.putExtras(bundle);
// Create the ActivityResult with the Intent.
return new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
}
运行时,相机 Intent 已成功存根,但应显示照片的视图卡在其加载状态。
在调试中,我发现这getBitmapFromURL
不是问题,因为bundle
包含正确的图像。
谁能建议问题可能出在哪里,或者如何最好地进一步调试?
解决方案
推荐阅读
- c++ - 映射进程和映射文件(非平台)具有不同的团队 ID
- javascript - 组件错过了第一个更新周期
- python - 我需要使用检查元素从网站获取特定数据
- typescript - 打字稿条件参数类型不起作用
- kubernetes - 重新启动在主图表的子图表中定义的部署
- grpc-go - protoc-gen-go 和 protoc-gen-go-grpc 的区别
- xcode - 更新到 Xcode 12.2 后无法使用 BMI2 编译项目
- julia - Julia JuMP 中的绑定 2 范数
- android - Android ML Kit Translator.getClient() 未解析参考
- fortran - Lid.exe 中 0x001D6653 处未处理的异常:0xc0000094:整数除以零