Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE recording screenshots #70

Closed
slacklab opened this issue Oct 24, 2019 · 13 comments
Closed

NPE recording screenshots #70

slacklab opened this issue Oct 24, 2019 · 13 comments

Comments

@slacklab
Copy link

slacklab commented Oct 24, 2019

I want to run yours plugin
I do:
./gradlew executeScreenshotTests -Precord

But get some errors:

⬇️  Pulling screenshots from your connected devices!

> Task :presentation:executeScreenshotTests FAILED
💾  Saving screenshots.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':presentation:executeScreenshotTests'.
> java.io.FileNotFoundException: /Users/ivan/AndroidStudioProjects/android-client/presentation/screenshots/screenshots-default/com.kg.project.presentation.RegressSuite_test_dump.json (No such file or directory)

But I found this Json at zip archive screenshot_bundle.zip

What I should do to avoid this error?

Thanks in advance

Version of the library

com.karumi:shot:3.0.2

@tonilopezmr
Copy link

Can you share more information about your build.gradle with your configuration?
Or share a complete example to reproduce the error?

Thanks!!

@slacklab
Copy link
Author

slacklab commented Oct 25, 2019

@tonilopezmr
in build.gradle(Project)

classpath 'com.karumi:shot:3.0.2'

in app/build.gradle(Module)

 // Standard Android View Plugins (TextView, etc)
    implementation "com.facebook.testing.screenshot:layout-hierarchy-common:0.11.0"

    // Litho Component Plugins
    implementation "com.facebook.testing.screenshot:layout-hierarchy-litho:0.11.0"

shot {
    appId = 'com.kg.project'
    instrumentationTestTask = 'connectedDevDebugAndroidTest'
}

// setup for facebook screenshot plugin
screenshots {
    referenceDir = "$projectDir/build/outputs/screenshots"
    multipleDevices true
}

Can you give me some advice?

@tonilopezmr
Copy link

Thanks! @slacklab, during next month we will take a look at this issue to solve it, in the meantime, if you have more informatión to share or you found the solution and want to make a PR with the fix is more than welcome.

@pedrovgs
Copy link
Owner

@slacklab could you please ensure you are not adding this dependency to your build.gradle file? com.facebook.testing.screenshot:core The error you reported is generated because any part of your code is importing that dependency with a version greater than 0.8.0 which is the last version we support right now. Could you check your dependencies and let me know if this facebook dependency is declared?

If the dependency is not declared, could you please run ./gradlew app:dependencies and paste the output of the command in a comment?

@pedrovgs
Copy link
Owner

Please, try also to remove these dependencies you declared in your manifest if my previous comment didn't fix the issue.

    // Standard Android View Plugins (TextView, etc)
    implementation "com.facebook.testing.screenshot:layout-hierarchy-common:0.11.0"

    // Litho Component Plugins
    implementation "com.facebook.testing.screenshot:layout-hierarchy-litho:0.11.0"

@ivan399
Copy link

ivan399 commented Oct 28, 2019

@pedrovgs

Hello !

If you remove this dependence - the test will fail with such an error.

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)
at com.myapp.present.Suite.test(Suite.kt:417)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:134)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:134)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1955)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.facebook.testing.screenshot.WindowAttachment.invokeUnchecked(WindowAttachment.java:103)
at com.facebook.testing.screenshot.WindowAttachment.invoke(WindowAttachment.java:94)
at com.facebook.testing.screenshot.WindowAttachment.dispatchAttach(WindowAttachment.java:83)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:173)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.access$000(ScreenshotImpl.java:47)
at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:161)
at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:158)
at com.facebook.testing.screenshot.internal.ScreenshotImpl$3.run(ScreenshotImpl.java:317)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6394)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1000)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:890)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.testing.screenshot.WindowAttachment.invokeUnchecked(WindowAttachment.java:101)
... 14 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewRootImpl.addWindowCallbacks(android.view.WindowCallbacks)' on a null object reference
at com.android.internal.policy.DecorView.onAttachedToWindow(DecorView.java:1566)
... 16 more

./gradlew app:dependencies

What lines are interested in this command? In the output did not find Facebook dependencies

@pedrovgs
Copy link
Owner

@ivan399 I'm afraid looking at the trace I don't understand where the NPE comes from. Could you please upload a zip file or create a GitHub repository with a reproducing the error?

@ivan399
Copy link

ivan399 commented Oct 29, 2019

@pedrovgs

I don’t have the right to publicly upload a project or part of it :(

But I found a similar problem: facebook/screenshot-tests-for-android#68

@pedrovgs
Copy link
Owner

@ivan399 I don't mean uploading the code of the app you are working on right now. I mean uploading any sample project you could create reproducing the error.

@pedrovgs pedrovgs changed the title Cannot run any compare snapshots NPE recording screenshots Nov 8, 2019
@emilioscy
Copy link

Here is a test project that produces this specific error.
https://github.com/emilioscy/MFSNapshotTest

@Serchinastico
Copy link
Contributor

Hi @emilioscy, I'm seeing your project has both, Shot and Facebook's Screenshot library included. This will override the dependency Shot is using internally and will produce strange behaviors. I recommend not mixing both and stick to one of them.

@emilioscy
Copy link

Hello @Serchinastico, i removed Facebook's library and works as expected. Perhaps this is what was causing the issue for @slacklab.

@Serchinastico
Copy link
Contributor

I'm closing the issue. There is already a small section on the README describing problems if you load your own facebook dependency and how the current version of Shot is only compatible with FB's 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants