Skip to content

Commit

Permalink
Merge pull request #252 from AppDevNext/BumpEspresso
Browse files Browse the repository at this point in the history
Bump Espresso screenshot tests
  • Loading branch information
hannesa2 authored Nov 18, 2024
2 parents b334cc0 + 4cb5162 commit 82809fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
8 changes: 5 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.multidex:multidex:2.0.1'

androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestImplementation "androidx.test.espresso:espresso-core:${androidxTestEspresso}"
androidTestImplementation "androidx.test.ext:junit-ktx:1.2.1"
androidTestImplementation "com.github.AppDevNext.Logcat:LogcatCoreLib:3.3.1"
androidTestUtil "androidx.test.services:test-services:1.5.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
// androidTestImplementation 'androidx.test.espresso:espresso-intents:3.6.1'

androidTestImplementation project(':moka')
}
24 changes: 12 additions & 12 deletions sample/src/androidTest/java/com/sample/app/ADTTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.sample.app

import android.graphics.Bitmap
import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
Expand Down Expand Up @@ -37,9 +39,9 @@ class ADTTest {
@Test
@Throws(IOException::class)
fun saveActivityBitmap() {
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })

}

/**
Expand All @@ -49,8 +51,7 @@ class ADTTest {
@Throws(IOException::class)
fun saveViewBitmap() {
onView(ViewMatchers.withText("Hello Espresso!"))
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

/**
Expand All @@ -66,17 +67,16 @@ class ADTTest {

@Test
fun changeTextSameActivity() {
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-Start")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-Start") })

// Type text and then press the button.
onView(ViewMatchers.withId(R.id.editTextUserInput)).perform(ViewActions.typeText(STRING_TO_BE_TYPED), ViewActions.closeSoftKeyboard())
onView(ViewMatchers.withId(R.id.changeTextBt)).perform(ViewActions.click())
// Check that the text was changed.
onView(ViewMatchers.withId(R.id.textToBeChanged)).check(matches(ViewMatchers.withText(STRING_TO_BE_TYPED)))
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-End")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-End") })
}

companion object {
Expand Down

0 comments on commit 82809fd

Please sign in to comment.