androidandroid-espressoandroid-testingandroidx-test

In which package are androidx.test.core.app.DeviceCapture.takeScreenshot or androidx.test.espresso.screenshot.captureToBitmap located


I'm trying to update my screenshot routine used in the instrumentation tests of multiple projects using the new suggested method. Which is, of course, more complicated then the pervious version.

There are two options open and I'm currently trying out both.

     val screenshot1 = androidx.test.core.app.DeviceCapture.takeScreenshot()
     val screenshot2 = androidx.test.espresso.screenshot.captureToBitmap ()

However but both give me an not found error.

According to Documentation androidx.test.core.app.DeviceCapture should be part of androidx.test:core and androidx.test.espresso.screenshot part of androidx.test.espresso:espresso-core.

I include both packages yet, as mentioned, both statements still give me a not found error:

   implementation (
      [group: 'androidx.test', name: 'core', version: Androidx_Test_Version],
      [group: 'androidx.test', name: 'core-ktx', version: Androidx_Test_Version],
      [group: 'androidx.test', name: 'rules', version: Androidx_Test_Version],
      [group: 'androidx.test', name: 'runner', version: Androidx_Test_Runner_Version],
      [group: 'androidx.test.espresso', name: 'espresso-core', version: Espresso_Version],
      [group: 'androidx.test.espresso', name: 'espresso-device', version: '1.0.1'],
      [group: 'androidx.test.ext', name: 'junit', version: Androidx_Test_Ext_Version],
      [group: 'androidx.test.uiautomator', name: 'uiautomator', version: UI_Automator_Version],
      [group: 'junit', name: "junit", version: JUnit_Version],
      [group: 'net.sourceforge.uiq3', name: 'Calculator-Library', version: Version_Maven],
      [group: 'org.exparity', name: 'hamcrest-date', version: Hamcrest_Date_Version],
      [group: 'org.hamcrest', name: 'hamcrest-core', version: Hamcrest_Version],
      [group: 'org.hamcrest', name: 'hamcrest-library', version: Hamcrest_Version],
      [group: 'org.jetbrains.kotlin', name: "kotlin-reflect", version: Kotlin_Plugin_Version],
      [group: 'org.jetbrains.kotlin', name: "kotlin-stdlib", version: Kotlin_Plugin_Version]
   ) // implementation

The variables are all set to the newest version and the project-structure suggestions are empty.

So, what am I missing here?

Update 1

According to documentation it should have been added for Version 1.6.0

Version 1.6.0


Solution

  • It seems that you absolutely have import the methods as they are package level methods declared outside of any class and the DeviceCapture class mentioned in the documentation exist only for Java compatibility.

    The following will at least compile:

    import androidx.test.core.app.takeScreenshot
    import androidx.test.core.graphics.writeToTestStorage
    
    val screenshot = takeScreenshot()
    screenshot.writeToTestStorage (name)
    

    Sadly the Screenshots are not downloaded as promised by the documentation. But that is a different problem.