Skip to content

Commit c8e0482

Browse files
authored
Merge pull request #625 from MikeOrtiz/BumpEspresso
Bump Espresso screenshot tests
2 parents 0d7f0ae + 900b411 commit c8e0482

22 files changed

+59
-74
lines changed

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ dependencies {
4343
implementation "androidx.viewpager2:viewpager2:1.1.0"
4444
implementation 'com.github.bumptech.glide:glide:4.16.0'
4545

46-
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
47-
androidTestUtil "androidx.test.services:test-services:1.4.2"
48-
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
49-
androidTestImplementation "androidx.test:rules:1.5.0" // GrantPermissionRule
50-
androidTestImplementation 'com.github.AppDevNext:Moka:1.6'
51-
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1'
46+
androidTestImplementation 'com.github.AppDevNext:Moka:1.7'
47+
androidTestImplementation "androidx.test.ext:junit-ktx:1.2.1"
48+
androidTestImplementation "com.github.AppDevNext.Logcat:LogcatCoreLib:3.3.1"
49+
androidTestUtil "androidx.test.services:test-services:1.5.0"
50+
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
51+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.6.1'
5252
}
Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package info.touchimage.demo
22

3+
import android.graphics.Bitmap
34
import androidx.test.core.graphics.writeToTestStorage
4-
import androidx.test.espresso.Espresso
5+
import androidx.test.espresso.Espresso.onView
56
import androidx.test.espresso.action.ViewActions
7+
import androidx.test.espresso.action.ViewActions.captureToBitmap
68
import androidx.test.espresso.assertion.ViewAssertions.matches
79
import androidx.test.espresso.intent.Intents
810
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
911
import androidx.test.espresso.matcher.ViewMatchers.*
10-
import androidx.test.espresso.screenshot.captureToBitmap
1112
import androidx.test.ext.junit.rules.activityScenarioRule
1213
import androidx.test.ext.junit.runners.AndroidJUnit4
1314
import com.moka.lib.assertions.WaitingAssertion
@@ -37,111 +38,99 @@ class MainSmokeTest {
3738

3839
@Test
3940
fun smokeTestSimplyStart() {
40-
Espresso.onView(isRoot())
41-
.captureToBitmap()
42-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
41+
onView(isRoot())
42+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
4343
}
4444

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

5453
@Test
5554
fun testViewPager() {
56-
Espresso.onView(withId(R.id.viewpager_example_button)).perform(ViewActions.click())
55+
onView(withId(R.id.viewpager_example_button)).perform(ViewActions.click())
5756
Intents.intended(hasComponent(ViewPagerExampleActivity::class.java.name))
58-
Espresso.onView(isRoot())
59-
.captureToBitmap()
60-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
57+
onView(isRoot())
58+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
6159
}
6260

6361
@Test
6462
fun testView2Pager() {
65-
Espresso.onView(withId(R.id.viewpager2_example_button)).perform(ViewActions.click())
63+
onView(withId(R.id.viewpager2_example_button)).perform(ViewActions.click())
6664
Intents.intended(hasComponent(ViewPager2ExampleActivity::class.java.name))
67-
Espresso.onView(isRoot())
68-
.captureToBitmap()
69-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
65+
onView(isRoot())
66+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
7067
}
7168

7269
@Test
7370
fun testMirroring() {
74-
Espresso.onView(withId(R.id.mirror_touchimageview_button)).perform(ViewActions.click())
71+
onView(withId(R.id.mirror_touchimageview_button)).perform(ViewActions.click())
7572
Intents.intended(hasComponent(MirroringExampleActivity::class.java.name))
76-
Espresso.onView(isRoot())
77-
.captureToBitmap()
78-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
73+
onView(isRoot())
74+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
7975
}
8076

8177
@Test
8278
fun testSwitchImage() {
83-
Espresso.onView(withId(R.id.switch_image_button)).perform(ViewActions.click())
79+
onView(withId(R.id.switch_image_button)).perform(ViewActions.click())
8480
Intents.intended(hasComponent(SwitchImageExampleActivity::class.java.name))
85-
Espresso.onView(isRoot())
86-
.captureToBitmap()
87-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
81+
onView(isRoot())
82+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
8883
}
8984

9085
@Test
9186
fun testSwitchScale() {
92-
Espresso.onView(withId(R.id.switch_scaletype_button)).perform(ViewActions.click())
87+
onView(withId(R.id.switch_scaletype_button)).perform(ViewActions.click())
9388
Intents.intended(hasComponent(SwitchScaleTypeExampleActivity::class.java.name))
94-
Espresso.onView(isRoot())
95-
.captureToBitmap()
96-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
89+
onView(isRoot())
90+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
9791
}
9892

9993
@Test
10094
fun testChangeSize() {
101-
Espresso.onView(withId(R.id.resize_button)).perform(ViewActions.click())
95+
onView(withId(R.id.resize_button)).perform(ViewActions.click())
10296
Intents.intended(hasComponent(ChangeSizeExampleActivity::class.java.name))
10397
Thread.sleep(500)
104-
Espresso.onView(isRoot())
105-
.captureToBitmap()
106-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
98+
onView(isRoot())
99+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
107100
}
108101

109102
@Test
110103
fun testRecycler() {
111-
Espresso.onView(withId(R.id.recycler_button)).perform(ViewActions.click())
104+
onView(withId(R.id.recycler_button)).perform(ViewActions.click())
112105
Intents.intended(hasComponent(RecyclerExampleActivity::class.java.name))
113-
Espresso.onView(isRoot())
114-
.captureToBitmap()
115-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
106+
onView(isRoot())
107+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
116108
}
117109

118110
@Test
119111
fun testAnimateZoom() {
120-
Espresso.onView(withId(R.id.animate_button)).perform(ViewActions.click())
112+
onView(withId(R.id.animate_button)).perform(ViewActions.click())
121113
Intents.intended(hasComponent(AnimateZoomActivity::class.java.name))
122-
Espresso.onView(isRoot())
123-
.captureToBitmap()
124-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
114+
onView(isRoot())
115+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
125116
}
126117

127118
@Test
128119
fun testGlide() {
129-
Espresso.onView(withId(R.id.glide_button)).perform(ViewActions.click())
120+
onView(withId(R.id.glide_button)).perform(ViewActions.click())
130121
Intents.intended(hasComponent(GlideExampleActivity::class.java.name))
131122

132123
WaitingAssertion.checkAssertion(R.id.textLoaded, isDisplayed(), 1500)
133-
Espresso.onView(withId(R.id.textLoaded)).check( matches(withText(containsString(" ms"))))
134-
Espresso.onView(isRoot())
135-
.captureToBitmap()
136-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
124+
onView(withId(R.id.textLoaded)).check( matches(withText(containsString(" ms"))))
125+
onView(isRoot())
126+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
137127
}
138128

139129
@Test
140130
fun makeScreenshotOfShapedImage() {
141-
Espresso.onView(withId(R.id.shaped_image_button)).perform(ViewActions.click())
131+
onView(withId(R.id.shaped_image_button)).perform(ViewActions.click())
142132
Intents.intended(hasComponent(ShapedExampleActivity::class.java.name))
143-
Espresso.onView(isRoot())
144-
.captureToBitmap()
145-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
133+
onView(isRoot())
134+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })
146135
}
147136
}

app/src/androidTest/java/info/touchimage/demo/TouchTest.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package info.touchimage.demo
22

3+
import android.graphics.Bitmap
34
import androidx.test.core.graphics.writeToTestStorage
45
import androidx.test.espresso.Espresso.onView
6+
import androidx.test.espresso.action.ViewActions.captureToBitmap
57
import androidx.test.espresso.matcher.ViewMatchers
68
import androidx.test.espresso.matcher.ViewMatchers.withId
7-
import androidx.test.espresso.screenshot.captureToBitmap
89
import androidx.test.ext.junit.rules.activityScenarioRule
910
import androidx.test.ext.junit.runners.AndroidJUnit4
1011
import info.touchimage.demo.utils.MultiTouchDownEvent
@@ -27,28 +28,26 @@ class TouchTest {
2728
@Test
2829
fun testSingleTouch() {
2930
onView(withId(R.id.imageSingle)).perform(TouchAction(4f, 8f))
30-
onView(withId(R.id.imageSingle)).captureToBitmap()
31-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch1")
31+
onView(ViewMatchers.isRoot())
32+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch1") })
3233
onView(withId(R.id.imageSingle)).perform(TouchAction(40f, 80f))
3334
Thread.sleep(300)
34-
onView(withId(R.id.imageSingle)).captureToBitmap()
35-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch2")
35+
onView(ViewMatchers.isRoot())
36+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-touch2") })
3637
}
3738

3839
@Test
3940
@Ignore("It is flaky")
4041
fun testMultiTouch() {
4142
onView(ViewMatchers.isRoot())
42-
.captureToBitmap()
43-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-before")
43+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-before") })
4444
val touchList: Array<Pair<Float, Float>> = listOf(
4545
Pair(4f, 8f),
4646
Pair(40f, 80f),
4747
Pair(30f, 70f)
4848
).toTypedArray()
4949
onView(withId(R.id.imageSingle)).perform(MultiTouchDownEvent(touchList))
5050
onView(ViewMatchers.isRoot())
51-
.captureToBitmap()
52-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-after")
51+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-after") })
5352
}
5453
}

app/src/androidTest/java/info/touchimage/demo/ZoomTest.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package info.touchimage.demo
22

3+
import android.graphics.Bitmap
34
import androidx.test.core.graphics.writeToTestStorage
45
import androidx.test.espresso.Espresso.onView
56
import androidx.test.espresso.action.ViewActions
7+
import androidx.test.espresso.action.ViewActions.captureToBitmap
68
import androidx.test.espresso.matcher.ViewMatchers
79
import androidx.test.espresso.matcher.ViewMatchers.withId
8-
import androidx.test.espresso.screenshot.captureToBitmap
910
import androidx.test.ext.junit.rules.activityScenarioRule
1011
import androidx.test.ext.junit.runners.AndroidJUnit4
1112
import org.junit.Rule
@@ -26,23 +27,19 @@ class ZoomTest {
2627
fun zoom() {
2728
Thread.sleep(WAIT)
2829
onView(ViewMatchers.isRoot())
29-
.captureToBitmap()
30-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1-init")
30+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1-init") })
3131
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
3232
Thread.sleep(WAIT)
3333
onView(ViewMatchers.isRoot())
34-
.captureToBitmap()
35-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2-reset")
34+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2-reset") })
3635
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
3736
Thread.sleep(WAIT)
3837
onView(ViewMatchers.isRoot())
39-
.captureToBitmap()
40-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3-zoom")
38+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3-zoom") })
4139
onView(withId(R.id.current_zoom)).perform(ViewActions.click())
4240
Thread.sleep(WAIT)
4341
onView(ViewMatchers.isRoot())
44-
.captureToBitmap()
45-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-4-end")
42+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-4-end") })
4643
}
4744

4845
companion object {
-910 Bytes
Loading
1.37 KB
Loading
-12.2 KB
Loading
774 Bytes
Loading
46 Bytes
Loading
74 Bytes
Loading

0 commit comments

Comments
 (0)