Skip to content

Commit cd46199

Browse files
authored
Merge pull request #245 from hannesa2/ModernizeScreenshotTest
Modernize screenshot test
2 parents bb8e42c + 1f69eeb commit cd46199

29 files changed

+39
-51
lines changed

demo/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3636

3737
testImplementation "junit:junit:4.13.2"
38-
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
38+
androidTestImplementation "androidx.test.ext:junit-ktx:1.2.1"
3939
androidTestUtil "androidx.test.services:test-services:1.5.0"
40-
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
40+
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
4141
}

demo/src/androidTest/java/info/hannes/slidingup/demo/AnchorTest.kt

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package info.hannes.slidingup.demo
22

3+
import android.graphics.Bitmap
34
import androidx.test.espresso.assertion.ViewAssertions.matches
45
import com.sothree.slidinguppanel.demo.R
56
import androidx.test.core.graphics.writeToTestStorage
67
import androidx.test.espresso.Espresso.onView
78
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
89
import androidx.test.espresso.action.ViewActions
10+
import androidx.test.espresso.action.ViewActions.captureToBitmap
911
import androidx.test.espresso.action.ViewActions.click
10-
import androidx.test.espresso.matcher.ViewMatchers
12+
import androidx.test.espresso.matcher.ViewMatchers.isRoot
1113
import androidx.test.espresso.matcher.ViewMatchers.withId
1214
import androidx.test.espresso.matcher.ViewMatchers.withText
13-
import androidx.test.espresso.screenshot.captureToBitmap
1415
import androidx.test.ext.junit.rules.activityScenarioRule
1516
import androidx.test.ext.junit.runners.AndroidJUnit4
1617
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
@@ -39,34 +40,31 @@ class AnchorTest {
3940
fun setup() {
4041
openActionBarOverflowOrOptionsMenu(getInstrumentation().targetContext)
4142
Thread.sleep(WAIT_SLIDER)
42-
onView(ViewMatchers.isRoot())
43-
.captureToBitmap()
44-
.writeToTestStorage("${javaClass.simpleName}_setup")
45-
onView(withText(R.string.action_anchor_enable)).perform(click());
43+
onView(isRoot())
44+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_setup") })
45+
46+
onView(withText(R.string.action_anchor_enable)).perform(click())
4647
}
4748

4849
@Test
4950
fun testExpand() {
5051
Thread.sleep(WAIT_SLIDER)
51-
onView(ViewMatchers.isRoot())
52-
.captureToBitmap()
53-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1")
52+
onView(isRoot())
53+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1") })
5454
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.ANCHORED)))
5555

5656
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED))
5757

5858
Thread.sleep(WAIT_SLIDER)
5959
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
60-
onView(ViewMatchers.isRoot())
61-
.captureToBitmap()
62-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
60+
onView(isRoot())
61+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") })
6362

6463
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
6564
Thread.sleep(WAIT_SLIDER)
6665
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
67-
onView(ViewMatchers.isRoot())
68-
.captureToBitmap()
69-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
66+
onView(isRoot())
67+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3") })
7068
}
7169

7270
@Test
@@ -83,9 +81,8 @@ class AnchorTest {
8381
Thread.sleep(WAIT_SLIDER)
8482
// should be still EXPANDED
8583
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.ANCHORED)))
86-
onView(ViewMatchers.isRoot())
87-
.captureToBitmap()
88-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
84+
onView(isRoot())
85+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") })
8986
}
9087

9188
@Test
@@ -97,9 +94,8 @@ class AnchorTest {
9794
for (i in 0..2) {
9895
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
9996
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
100-
onView(ViewMatchers.isRoot())
101-
.captureToBitmap()
102-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED-$i")
97+
onView(isRoot())
98+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED-$i") })
10399
}
104100

105101
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.ANCHORED))
@@ -111,9 +107,8 @@ class AnchorTest {
111107
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
112108
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
113109
Thread.sleep(WAIT_SLIDER)
114-
onView(ViewMatchers.isRoot())
115-
.captureToBitmap()
116-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i")
110+
onView(isRoot())
111+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i") })
117112
}
118113

119114
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.ANCHORED))
@@ -123,9 +118,8 @@ class AnchorTest {
123118
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
124119
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
125120
Thread.sleep(WAIT_SLIDER)
126-
onView(ViewMatchers.isRoot())
127-
.captureToBitmap()
128-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-ANCHORED-$i")
121+
onView(isRoot())
122+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-ANCHORED-$i") })
129123
}
130124
}
131125
}

demo/src/androidTest/java/info/hannes/slidingup/demo/NoAnchorTest.kt

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package info.hannes.slidingup.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
6-
import androidx.test.espresso.action.ViewActions.swipeDown
7+
import androidx.test.espresso.action.ViewActions.captureToBitmap
78
import androidx.test.espresso.action.ViewActions.swipeUp
89
import androidx.test.espresso.assertion.ViewAssertions.matches
9-
import androidx.test.espresso.matcher.ViewMatchers
10+
import androidx.test.espresso.matcher.ViewMatchers.isRoot
1011
import androidx.test.espresso.matcher.ViewMatchers.withId
11-
import androidx.test.espresso.screenshot.captureToBitmap
1212
import androidx.test.ext.junit.rules.activityScenarioRule
1313
import androidx.test.ext.junit.runners.AndroidJUnit4
1414
import com.sothree.slidinguppanel.PanelState
@@ -35,25 +35,22 @@ class NoAnchorTest {
3535

3636
@Test
3737
fun testExpand() {
38-
onView(ViewMatchers.isRoot())
39-
.captureToBitmap()
40-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1")
38+
onView(isRoot())
39+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1") })
4140
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
4241

4342
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.EXPANDED))
4443

4544
Thread.sleep(WAIT_SLIDER)
4645
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
47-
onView(ViewMatchers.isRoot())
48-
.captureToBitmap()
49-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
46+
onView(isRoot())
47+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") })
5048

5149
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
5250
Thread.sleep(WAIT_SLIDER)
5351
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
54-
onView(ViewMatchers.isRoot())
55-
.captureToBitmap()
56-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
52+
onView(isRoot())
53+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3") })
5754
}
5855

5956
@Test
@@ -63,9 +60,8 @@ class NoAnchorTest {
6360
for (i in 0..2) {
6461
onView(withId(R.id.follow)).perform(swipeUp())
6562
Thread.sleep(WAIT_SLIDER)
66-
onView(ViewMatchers.isRoot())
67-
.captureToBitmap()
68-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED$i")
63+
onView(isRoot())
64+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED$i") })
6965
}
7066

7167
onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
@@ -74,12 +70,11 @@ class NoAnchorTest {
7470
Thread.sleep(WAIT_SLIDER)
7571

7672
for (i in 0..2) {
77-
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
73+
onView(withId(R.id.follow)).perform(swipeUp())
7874
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
7975
Thread.sleep(WAIT_SLIDER)
80-
onView(ViewMatchers.isRoot())
81-
.captureToBitmap()
82-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i")
76+
onView(isRoot())
77+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i") })
8378
}
8479
}
8580

@@ -98,9 +93,8 @@ class NoAnchorTest {
9893
// should be still EXPANDED
9994
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.EXPANDED)))
10095
Thread.sleep(WAIT_SLIDER)
101-
onView(ViewMatchers.isRoot())
102-
.captureToBitmap()
103-
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
96+
onView(isRoot())
97+
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") })
10498
}
10599

106100
}
Loading
Loading
98 Bytes
Loading
86 Bytes
Loading
189 Bytes
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
190 Bytes
Loading
Loading
189 Bytes
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)