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

Bump Espresso screenshot tests #252

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading