首页 > 解决方案 > 为 Facebook screenshot-tests-for-android 设置 gradle 插件的问题

问题描述

我需要为android实现屏幕截图测试。

我已按照https://facebook.github.io/screenshot-tests-for-android/#gradle-setup上的步骤操作,并在我的 gradle 文件中包含以下内容

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

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

但是,我收到一个错误

评估根项目“app-android”时出现问题。无法应用插件 [id 'com.facebook.testing.screenshot'] 未找到名称为 'androidTestImplementation' 的配置。

我的 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'

我找不到任何证据表明我需要其他任何东西。

我还在https://github.com/facebook/screenshot-tests-for-android上看到了

您需要 python-2.7 才能使 gradle 插件工作,我们还建议安装记录和验证屏幕截图所需的 python-pillow 库。

我已经安装了它,看到我有版本 2.7.16 我还安装了推荐的枕头(v6.0.0)

标签: androidandroid-testing

解决方案


您可能需要移动此行:

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

进入模块级别build.gradle。它必须低于这一行:

apply plugin: "com.android.application"

因为那是它的androidTestImplementation来源。


推荐阅读