Skip to content

Commit

Permalink
Merge pull request #245 from hannesa2/ModernizeScreenshotTest
Browse files Browse the repository at this point in the history
Modernize screenshot test
  • Loading branch information
hannesa2 authored Jan 2, 2025
2 parents bb8e42c + 1f69eeb commit cd46199
Show file tree
Hide file tree
Showing 29 changed files with 39 additions and 51 deletions.
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestImplementation "androidx.test.ext:junit-ktx:1.2.1"
androidTestUtil "androidx.test.services:test-services:1.5.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
}
48 changes: 21 additions & 27 deletions demo/src/androidTest/java/info/hannes/slidingup/demo/AnchorTest.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package info.hannes.slidingup.demo

import android.graphics.Bitmap
import androidx.test.espresso.assertion.ViewAssertions.matches
import com.sothree.slidinguppanel.demo.R
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
Expand Down Expand Up @@ -39,34 +40,31 @@ class AnchorTest {
fun setup() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().targetContext)
Thread.sleep(WAIT_SLIDER)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_setup")
onView(withText(R.string.action_anchor_enable)).perform(click());
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_setup") })

onView(withText(R.string.action_anchor_enable)).perform(click())
}

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

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

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

onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
Thread.sleep(WAIT_SLIDER)
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3") })
}

@Test
Expand All @@ -83,9 +81,8 @@ class AnchorTest {
Thread.sleep(WAIT_SLIDER)
// should be still EXPANDED
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.ANCHORED)))
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2") })
}

@Test
Expand All @@ -97,9 +94,8 @@ class AnchorTest {
for (i in 0..2) {
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED-$i")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED-$i") })
}

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

onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.ANCHORED))
Expand All @@ -123,9 +118,8 @@ class AnchorTest {
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
Thread.sleep(WAIT_SLIDER)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-ANCHORED-$i")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-ANCHORED-$i") })
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package info.hannes.slidingup.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.swipeDown
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isRoot
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 com.sothree.slidinguppanel.PanelState
Expand All @@ -35,25 +35,22 @@ class NoAnchorTest {

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

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

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

onView(withId(R.id.sliding_layout)).perform(setValue(PanelState.COLLAPSED))
Thread.sleep(WAIT_SLIDER)
onView(withId(R.id.sliding_layout)).check(matches(withValue(PanelState.COLLAPSED)))
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3") })
}

@Test
Expand All @@ -63,9 +60,8 @@ class NoAnchorTest {
for (i in 0..2) {
onView(withId(R.id.follow)).perform(swipeUp())
Thread.sleep(WAIT_SLIDER)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED$i")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-COLLAPSED$i") })
}

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

for (i in 0..2) {
onView(withId(R.id.follow)).perform(ViewActions.swipeUp())
onView(withId(R.id.follow)).perform(swipeUp())
onView(withId(R.id.follow)).perform(ViewActions.swipeDown())
Thread.sleep(WAIT_SLIDER)
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i")
onView(isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-EXPANDED-$i") })
}
}

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

}
Binary file modified screenshotsToCompare9/AnchorTest_testAnchorWithAnchored-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testExpand-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testExpand-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testExpand-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-ANCHORED-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-ANCHORED-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-ANCHORED-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-COLLAPSED-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-COLLAPSED-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-COLLAPSED-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-EXPANDED-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-EXPANDED-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/AnchorTest_testSwipe-EXPANDED-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testAnchorWithoutAnchored-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testExpand-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testExpand-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testExpand-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-COLLAPSED0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-COLLAPSED1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-COLLAPSED2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-EXPANDED-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-EXPANDED-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare9/NoAnchorTest_testSwipe-EXPANDED-2.png

0 comments on commit cd46199

Please sign in to comment.