Skip to content

Commit

Permalink
Aligned android element screenshot to the same functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon Haiut committed May 25, 2021
1 parent a443b88 commit e05793c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ class ScreenshotResult(private val bitmap: Bitmap) {

class ViewScreenshot() {
fun takeOf(view: View): ScreenshotResult {
val visibleRect = Rect()
if (!view.getLocalVisibleRect(visibleRect)) {
throw IllegalStateException("Cannot take screenshot of a view that's out of screen's bounds")
}

val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
view.draw(Canvas(bitmap))

val clippedBitmap = Bitmap.createBitmap(bitmap, visibleRect.left, visibleRect.top, visibleRect.width(), visibleRect.height())
return ScreenshotResult(clippedBitmap)
return ScreenshotResult(bitmap)
}
}
7 changes: 0 additions & 7 deletions detox/test/e2e/26.element-screenshots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ describe('Element screenshots', () => {
expectBitmapsToBeEqual(bitmapPath, screenshotAssetPath);
});

it(':android: should fail to take a screenshot of an off-screen element', async () => {
await expectToThrow(
() => element(by.id('offscreenElement')).takeScreenshot(),
`Cannot take screenshot of a view that's out of screen's bounds`,
);
});

function expectBitmapsToBeEqual(bitmapPath, expectedBitmapPath) {
const bitmapBuffer = fs.readFileSync(bitmapPath);
const expectedBitmapBuffer = fs.readFileSync(expectedBitmapPath);
Expand Down

0 comments on commit e05793c

Please sign in to comment.