1
1
package info.hannes.slidingup.demo
2
2
3
+ import android.graphics.Bitmap
3
4
import androidx.test.espresso.assertion.ViewAssertions.matches
4
5
import com.sothree.slidinguppanel.demo.R
5
6
import androidx.test.core.graphics.writeToTestStorage
6
7
import androidx.test.espresso.Espresso.onView
7
8
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
8
9
import androidx.test.espresso.action.ViewActions
10
+ import androidx.test.espresso.action.ViewActions.captureToBitmap
9
11
import androidx.test.espresso.action.ViewActions.click
10
- import androidx.test.espresso.matcher.ViewMatchers
12
+ import androidx.test.espresso.matcher.ViewMatchers.isRoot
11
13
import androidx.test.espresso.matcher.ViewMatchers.withId
12
14
import androidx.test.espresso.matcher.ViewMatchers.withText
13
- import androidx.test.espresso.screenshot.captureToBitmap
14
15
import androidx.test.ext.junit.rules.activityScenarioRule
15
16
import androidx.test.ext.junit.runners.AndroidJUnit4
16
17
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
@@ -39,34 +40,31 @@ class AnchorTest {
39
40
fun setup () {
40
41
openActionBarOverflowOrOptionsMenu(getInstrumentation().targetContext)
41
42
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())
46
47
}
47
48
48
49
@Test
49
50
fun testExpand () {
50
51
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" ) })
54
54
onView(withId(R .id.sliding_layout)).check(matches(withValue(PanelState .ANCHORED )))
55
55
56
56
onView(withId(R .id.sliding_layout)).perform(setValue(PanelState .EXPANDED ))
57
57
58
58
Thread .sleep(WAIT_SLIDER )
59
59
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" ) })
63
62
64
63
onView(withId(R .id.sliding_layout)).perform(setValue(PanelState .COLLAPSED ))
65
64
Thread .sleep(WAIT_SLIDER )
66
65
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" ) })
70
68
}
71
69
72
70
@Test
@@ -83,9 +81,8 @@ class AnchorTest {
83
81
Thread .sleep(WAIT_SLIDER )
84
82
// should be still EXPANDED
85
83
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" ) })
89
86
}
90
87
91
88
@Test
@@ -97,9 +94,8 @@ class AnchorTest {
97
94
for (i in 0 .. 2 ) {
98
95
onView(withId(R .id.follow)).perform(ViewActions .swipeUp())
99
96
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 " ) })
103
99
}
104
100
105
101
onView(withId(R .id.sliding_layout)).perform(setValue(PanelState .ANCHORED ))
@@ -111,9 +107,8 @@ class AnchorTest {
111
107
onView(withId(R .id.follow)).perform(ViewActions .swipeUp())
112
108
onView(withId(R .id.follow)).perform(ViewActions .swipeDown())
113
109
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 " ) })
117
112
}
118
113
119
114
onView(withId(R .id.sliding_layout)).perform(setValue(PanelState .ANCHORED ))
@@ -123,9 +118,8 @@ class AnchorTest {
123
118
onView(withId(R .id.follow)).perform(ViewActions .swipeUp())
124
119
onView(withId(R .id.follow)).perform(ViewActions .swipeDown())
125
120
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 " ) })
129
123
}
130
124
}
131
125
}
0 commit comments