screenshot-tests-for-android icon indicating copy to clipboard operation
screenshot-tests-for-android copied to clipboard

Screenshot of BottomSheetDialog

Open tobiasKaminsky opened this issue 5 years ago • 2 comments

Expected behaviour

create screenshot of bottomsheet dialog

Actual behaviour

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.facebook.testing.screenshot.internal.ScreenshotImpl.runCallableOnUiThread(ScreenshotImpl.java:335)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:157)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.record(ScreenshotImpl.java:261)
at com.facebook.testing.screenshot.internal.RecordBuilderImpl.record(RecordBuilderImpl.java:155) 

Steps to reproduce

This is a condensed code:

MyBottomSheetDialog dialog = new MyBottomSheetDialog();

ViewHelpers.setupView(dialog.getWindow().getDecorView())
            .setExactHeightPx(100)
            .setExactWidthPx(100)
            .layout();

Screenshot.snap(dialog.getWindow().getDecorView()).record();

I also tried to launch the dialog via activity and then take a snapshot. But this fails, as it only captures the acivity, but not the overlaying dialog.

A third try was: Launching BottomSheetDialog and then: Screenshot.snap(sut.findViewById(R.id.bottomSheetMain)).record();

but this results in:

java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getMeasuredHeight()' on a null object reference

A test repo can be found here: Here you go: https://github.com/tobiasKaminsky/KarumiTest/blob/bottomSheet/app/src/androidTest/java/me/kaminsky/karumitest/BottomSheetTest.kt

Repo: [email protected]:tobiasKaminsky/KarumiTest.git Branch: bottomSheet

tobiasKaminsky avatar Mar 03 '20 09:03 tobiasKaminsky

You need to create the dialog, show it (on an Activity), wait for idle then snap the dialog.getWindow().getDecorView().

xiphirx avatar Mar 04 '20 19:03 xiphirx

Switching to BottomSheetDialogFragment and then using this works:

val sut: MainActivity = activityRule.launchActivity(null)
val dialog = MyBottomSheetDialog()
dialog.show(sut.supportFragmentManager, "bottomDialog")

InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Screenshot.snap(dialog.dialog?.window?.decorView).record()

But I failed to do this via a Dialog.

tobiasKaminsky avatar Mar 05 '20 07:03 tobiasKaminsky