Search code examples
androidandroid-testing

Issue setting up the gradle plugin for Facebook screenshot-tests-for-android


I need to implement screenshot testing for android.

I've followed the steps on https://facebook.github.io/screenshot-tests-for-android/#gradle-setup and have the following in my gradle file

buildscript {
    // ...
    dependencies {
      // ...
      classpath 'com.facebook.testing.screenshot:plugin:0.9.0'
    }
  }

  apply plugin: 'com.facebook.testing.screenshot'

However, I get an error

A problem occurred evaluating root project 'app-android'. Failed to apply plugin [id 'com.facebook.testing.screenshot'] Configuration with name 'androidTestImplementation' not found.

I have the following in my build.gradle

androidTestImplementation 'androidx.test:core:1.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.multidex:multidex-instrumentation:2.0.0'

I can't find any evidence that I need anything else.

I've also seen on https://github.com/facebook/screenshot-tests-for-android that

You need python-2.7 for the gradle plugin to work, and we also recommending installing the python-pillow library which is required for recording and verifying screenshots.

And I've installed that and see that I have version 2.7.16 I've also installed pillow as reccommended (v6.0.0)


Solution

  • you may need to move this line:

    apply plugin: "com.facebook.testing.screenshot"
    

    into the module level build.gradle. it has to be below this one line:

    apply plugin: "com.android.application"
    

    because that's where the androidTestImplementation comes from.