From af7e440a5d03145303b555cf3b270e0ff6f7d73e Mon Sep 17 00:00:00 2001 From: Arsenii Kharlanow Date: Sun, 15 Sep 2024 17:10:27 +0200 Subject: [PATCH] ISSUE-638: Added try/catch to InternalScreenshotMaker --- .../screenshots/screenshotmaker/InternalScreenshotMaker.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/screenshots/screenshotmaker/InternalScreenshotMaker.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/screenshots/screenshotmaker/InternalScreenshotMaker.kt index f6c4b9abc..64d664bdc 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/screenshots/screenshotmaker/InternalScreenshotMaker.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/screenshots/screenshotmaker/InternalScreenshotMaker.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.graphics.Bitmap import android.graphics.Canvas import android.os.Looper +import android.util.Log import android.view.View import com.kaspersky.kaspresso.device.activities.Activities import com.kaspersky.kaspresso.params.ScreenshotParams @@ -82,7 +83,7 @@ class InternalScreenshotMaker( private fun drawBitmap(view: View): Bitmap { view.layout(0, 0, view.measuredWidth, view.measuredHeight) val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) - val bitmapHolder = Canvas(bitmap!!) + val bitmapHolder = Canvas(bitmap) view.draw(bitmapHolder) return bitmap } @@ -97,6 +98,8 @@ class InternalScreenshotMaker( activity.runOnUiThread { try { activity.drawToBitmap(bitmap) + } catch (e: Exception) { + Log.e("InternalScreenshotMaker", "Unable to get screenshot ${file.absolutePath}") } finally { latch.countDown() }