|
1 | 1 | package info.touchimage.demo
|
2 | 2 |
|
| 3 | +import android.graphics.Bitmap |
3 | 4 | import androidx.test.core.graphics.writeToTestStorage
|
4 |
| -import androidx.test.espresso.Espresso |
| 5 | +import androidx.test.espresso.Espresso.onView |
5 | 6 | import androidx.test.espresso.action.ViewActions
|
| 7 | +import androidx.test.espresso.action.ViewActions.captureToBitmap |
6 | 8 | import androidx.test.espresso.assertion.ViewAssertions.matches
|
7 | 9 | import androidx.test.espresso.intent.Intents
|
8 | 10 | import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
|
9 | 11 | import androidx.test.espresso.matcher.ViewMatchers.*
|
10 |
| -import androidx.test.espresso.screenshot.captureToBitmap |
11 | 12 | import androidx.test.ext.junit.rules.activityScenarioRule
|
12 | 13 | import androidx.test.ext.junit.runners.AndroidJUnit4
|
13 | 14 | import com.moka.lib.assertions.WaitingAssertion
|
@@ -37,111 +38,99 @@ class MainSmokeTest {
|
37 | 38 |
|
38 | 39 | @Test
|
39 | 40 | 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}") }) |
43 | 43 | }
|
44 | 44 |
|
45 | 45 | @Test
|
46 | 46 | 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()) |
48 | 48 | 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}") }) |
52 | 51 | }
|
53 | 52 |
|
54 | 53 | @Test
|
55 | 54 | 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()) |
57 | 56 | 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}") }) |
61 | 59 | }
|
62 | 60 |
|
63 | 61 | @Test
|
64 | 62 | 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()) |
66 | 64 | 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}") }) |
70 | 67 | }
|
71 | 68 |
|
72 | 69 | @Test
|
73 | 70 | 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()) |
75 | 72 | 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}") }) |
79 | 75 | }
|
80 | 76 |
|
81 | 77 | @Test
|
82 | 78 | 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()) |
84 | 80 | 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}") }) |
88 | 83 | }
|
89 | 84 |
|
90 | 85 | @Test
|
91 | 86 | 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()) |
93 | 88 | 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}") }) |
97 | 91 | }
|
98 | 92 |
|
99 | 93 | @Test
|
100 | 94 | fun testChangeSize() {
|
101 |
| - Espresso.onView(withId(R.id.resize_button)).perform(ViewActions.click()) |
| 95 | + onView(withId(R.id.resize_button)).perform(ViewActions.click()) |
102 | 96 | Intents.intended(hasComponent(ChangeSizeExampleActivity::class.java.name))
|
103 | 97 | 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}") }) |
107 | 100 | }
|
108 | 101 |
|
109 | 102 | @Test
|
110 | 103 | fun testRecycler() {
|
111 |
| - Espresso.onView(withId(R.id.recycler_button)).perform(ViewActions.click()) |
| 104 | + onView(withId(R.id.recycler_button)).perform(ViewActions.click()) |
112 | 105 | 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}") }) |
116 | 108 | }
|
117 | 109 |
|
118 | 110 | @Test
|
119 | 111 | fun testAnimateZoom() {
|
120 |
| - Espresso.onView(withId(R.id.animate_button)).perform(ViewActions.click()) |
| 112 | + onView(withId(R.id.animate_button)).perform(ViewActions.click()) |
121 | 113 | 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}") }) |
125 | 116 | }
|
126 | 117 |
|
127 | 118 | @Test
|
128 | 119 | fun testGlide() {
|
129 |
| - Espresso.onView(withId(R.id.glide_button)).perform(ViewActions.click()) |
| 120 | + onView(withId(R.id.glide_button)).perform(ViewActions.click()) |
130 | 121 | Intents.intended(hasComponent(GlideExampleActivity::class.java.name))
|
131 | 122 |
|
132 | 123 | 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}") }) |
137 | 127 | }
|
138 | 128 |
|
139 | 129 | @Test
|
140 | 130 | 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()) |
142 | 132 | 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}") }) |
146 | 135 | }
|
147 | 136 | }
|
0 commit comments