Skip to content

Commit

Permalink
Bump Espresso screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Nov 18, 2024
1 parent e40a367 commit e3357bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 73 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ dependencies {
implementation "androidx.viewpager2:viewpager2:1.1.0"
implementation 'com.github.bumptech.glide:glide:4.16.0'

androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation "androidx.test:rules:1.5.0" // GrantPermissionRule
androidTestImplementation 'com.github.AppDevNext:Moka:1.6'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1'
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'
}
89 changes: 39 additions & 50 deletions app/src/androidTest/java/info/touchimage/demo/MainSmokeTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package info.touchimage.demo

import android.graphics.Bitmap
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso
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.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.moka.lib.assertions.WaitingAssertion
Expand Down Expand Up @@ -37,111 +38,99 @@ class MainSmokeTest {

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

@Test
fun testSingleTouch() {
Espresso.onView(withId(R.id.single_touchimageview_button)).perform(ViewActions.click())
onView(withId(R.id.single_touchimageview_button)).perform(ViewActions.click())
Intents.intended(hasComponent(SingleTouchImageViewActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testViewPager() {
Espresso.onView(withId(R.id.viewpager_example_button)).perform(ViewActions.click())
onView(withId(R.id.viewpager_example_button)).perform(ViewActions.click())
Intents.intended(hasComponent(ViewPagerExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testView2Pager() {
Espresso.onView(withId(R.id.viewpager2_example_button)).perform(ViewActions.click())
onView(withId(R.id.viewpager2_example_button)).perform(ViewActions.click())
Intents.intended(hasComponent(ViewPager2ExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testMirroring() {
Espresso.onView(withId(R.id.mirror_touchimageview_button)).perform(ViewActions.click())
onView(withId(R.id.mirror_touchimageview_button)).perform(ViewActions.click())
Intents.intended(hasComponent(MirroringExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testSwitchImage() {
Espresso.onView(withId(R.id.switch_image_button)).perform(ViewActions.click())
onView(withId(R.id.switch_image_button)).perform(ViewActions.click())
Intents.intended(hasComponent(SwitchImageExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testSwitchScale() {
Espresso.onView(withId(R.id.switch_scaletype_button)).perform(ViewActions.click())
onView(withId(R.id.switch_scaletype_button)).perform(ViewActions.click())
Intents.intended(hasComponent(SwitchScaleTypeExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testChangeSize() {
Espresso.onView(withId(R.id.resize_button)).perform(ViewActions.click())
onView(withId(R.id.resize_button)).perform(ViewActions.click())
Intents.intended(hasComponent(ChangeSizeExampleActivity::class.java.name))
Thread.sleep(500)
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testRecycler() {
Espresso.onView(withId(R.id.recycler_button)).perform(ViewActions.click())
onView(withId(R.id.recycler_button)).perform(ViewActions.click())
Intents.intended(hasComponent(RecyclerExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testAnimateZoom() {
Espresso.onView(withId(R.id.animate_button)).perform(ViewActions.click())
onView(withId(R.id.animate_button)).perform(ViewActions.click())
Intents.intended(hasComponent(AnimateZoomActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun testGlide() {
Espresso.onView(withId(R.id.glide_button)).perform(ViewActions.click())
onView(withId(R.id.glide_button)).perform(ViewActions.click())
Intents.intended(hasComponent(GlideExampleActivity::class.java.name))

WaitingAssertion.checkAssertion(R.id.textLoaded, isDisplayed(), 1500)
Espresso.onView(withId(R.id.textLoaded)).check( matches(withText(containsString(" ms"))))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(withId(R.id.textLoaded)).check( matches(withText(containsString(" ms"))))
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}

@Test
fun makeScreenshotOfShapedImage() {
Espresso.onView(withId(R.id.shaped_image_button)).perform(ViewActions.click())
onView(withId(R.id.shaped_image_button)).perform(ViewActions.click())
Intents.intended(hasComponent(ShapedExampleActivity::class.java.name))
Espresso.onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
}
}
17 changes: 8 additions & 9 deletions app/src/androidTest/java/info/touchimage/demo/TouchTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package info.touchimage.demo

import android.graphics.Bitmap
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import info.touchimage.demo.utils.MultiTouchDownEvent
Expand All @@ -27,28 +28,26 @@ class TouchTest {
@Test
fun testSingleTouch() {
onView(withId(R.id.imageSingle)).perform(TouchAction(4f, 8f))
onView(withId(R.id.imageSingle)).captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch1")
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch1") })
onView(withId(R.id.imageSingle)).perform(TouchAction(40f, 80f))
Thread.sleep(300)
onView(withId(R.id.imageSingle)).captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch2")
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch2") })
}

@Test
@Ignore("It is flaky")
fun testMultiTouch() {
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-before")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-before") })
val touchList: Array<Pair<Float, Float>> = listOf(
Pair(4f, 8f),
Pair(40f, 80f),
Pair(30f, 70f)
).toTypedArray()
onView(withId(R.id.imageSingle)).perform(MultiTouchDownEvent(touchList))
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-after")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-after") })
}
}
15 changes: 6 additions & 9 deletions app/src/androidTest/java/info/touchimage/demo/ZoomTest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package info.touchimage.demo

import android.graphics.Bitmap
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.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
Expand All @@ -26,23 +27,19 @@ class ZoomTest {
fun zoom() {
Thread.sleep(WAIT)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1-init")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1-init") })
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
Thread.sleep(WAIT)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2-reset")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2-reset") })
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
Thread.sleep(WAIT)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3-zoom")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3-zoom") })
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
Thread.sleep(WAIT)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-4-end")
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-4-end") })
}

companion object {
Expand Down

0 comments on commit e3357bd

Please sign in to comment.