Skip to content

Commit

Permalink
Creates EmulatorConfigRule to configure the emulator for full screen …
Browse files Browse the repository at this point in the history
…screenshots. (#62)

* Creates EmulatorConfigRule to configure the emulator for full screen screenshots.

* Updates target sdk versions

* 🤖 Updates screenshots

* updates AGP and dependencies.

* Fixes up some versioning things.

* Format update to kick workflow.

* Updates gradle wrapper validation action.

* Fixes gradle wrapper validation name.

* Updates jdk to 17

* 🤖 Updates screenshots

* Updates api dump

* Updates lint and test targetSdk

* Updates dependencies.

* Updates min sdk version

* 🤖 Updates screenshots

---------

Co-authored-by: rharter <[email protected]>
  • Loading branch information
rharter and rharter authored Oct 23, 2024
1 parent 8b7d70e commit 2b640c6
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 134 deletions.
13 changes: 2 additions & 11 deletions .github/scripts/emu_setup.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#!/bin/bash

adb wait-for-devices

echo "Cleaning up old emulator data"
adb uninstall com.dropbox.dropshots.test || true
adb shell rm -rf /storage/emulated/0/Download/screenshots || true

adb wait-for-devices
adb shell settings put global sysui_demo_allowed 1
adb shell am broadcast -a com.android.systemui.demo -e command enter
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1234
adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false
adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false
adb shell cmd overlay enable com.android.internal.systemui.navbar.gestural
103 changes: 36 additions & 67 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
uses: gradle/actions/wrapper-validation@v4

- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/**.gradle.kts', '**/gradle/wrapper/gradle-wrapper.properties', '**/libs.versions.toml') }}
restore-keys: |
${{ runner.os }}-gradle
- name: Install JDK 11
uses: actions/setup-java@v3
- name: Install JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build
run: ./gradlew assemble --stacktrace
Expand All @@ -39,25 +33,19 @@ jobs:
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
uses: gradle/actions/wrapper-validation@v4

- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/**.gradle.kts', '**/gradle/wrapper/gradle-wrapper.properties', '**/libs.versions.toml') }}
restore-keys: |
${{ runner.os }}-gradle
- name: Install JDK 11
uses: actions/setup-java@v3
- name: Install JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Run Tests
run: ./gradlew check --no-daemon --stacktrace
Expand All @@ -68,7 +56,7 @@ jobs:

- name: (Fail-only) Upload the build report
if: failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: unit-test-report
path: unit-test-build-reports.zip
Expand Down Expand Up @@ -107,25 +95,19 @@ jobs:
sudo udevadm trigger --name-match=kvm
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v2

- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/**.gradle.kts', '**/gradle/wrapper/gradle-wrapper.properties', '**/libs.versions.toml') }}
restore-keys: |
${{ runner.os }}-gradle
uses: gradle/actions/wrapper-validation@v4

- name: Install JDK 11
- name: Install JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

# Retrieve the cached emulator snapshot.
- name: AVD cache
Expand Down Expand Up @@ -209,7 +191,7 @@ jobs:

- name: Upload the build report
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: instrumentation-test-report
path: instrumentation-test-build-reports.zip
Expand All @@ -220,37 +202,24 @@ jobs:
needs: [unitTests]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/**.gradle.kts', '**/gradle/wrapper/gradle-wrapper.properties', '**/libs.versions.toml') }}
restore-keys: |
${{ runner.os }}-gradle
- name: Install JDK 11
uses: actions/setup-java@v3
- name: Gradle Wrapper Validation
uses: gradle/actions/wrapper-validation@v4

- name: Install JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Upload Snapshot
run: ./gradlew clean publish -Pdropshots.releaseMode=true --no-daemon --no-parallel --no-configuration-cache --stacktrace
run: ./gradlew publish -Pdropshots.releaseMode=true --no-daemon --no-parallel --no-configuration-cache --stacktrace
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}

- name: Retrieve Version
run: echo "VERSION_NAME=$(./gradlew -q :printVersionName)" >> $GITHUB_ENV

- name: Publish release (main only)
run: ./gradlew closeAndReleaseRepository --no-daemon --no-parallel
if: success() && !endsWith(env.VERSION_NAME, '-SNAPSHOT')
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
6 changes: 0 additions & 6 deletions dropshots-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ tasks.withType<KotlinCompile>().configureEach {
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(11)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
}

android {
namespace = "com.dropbox.dropshots.test.configuration-cache-compatible"
compileSdk = 32
namespace = "com.dropbox.dropshots.test.configuration_cache_compatible"
compileSdk = 34

defaultConfig {
minSdk = 24
targetSdk = 32
targetSdk = 34
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
}

android {
namespace = "com.dropbox.dropshots.test.configuration-cache-compatible"
compileSdk = 32
namespace = "com.dropbox.dropshots.test.configuration_cache_compatible"
compileSdk = 34

defaultConfig {
minSdk = 24
targetSdk = 32
targetSdk = 34
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
}

android {
namespace = "com.dropbox.dropshots.test.application-project"
compileSdk = 32
namespace = "com.dropbox.dropshots.test.application_project"
compileSdk = 34

defaultConfig {
minSdk = 24
targetSdk = 32
targetSdk = 34
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
7 changes: 0 additions & 7 deletions dropshots/api/dropshots.api
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
public final class com/dropbox/dropshots/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public fun <init> ()V
}

public final class com/dropbox/dropshots/Dropshots : org/junit/rules/TestRule {
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function1;ZLcom/dropbox/differ/ImageComparator;Lkotlin/jvm/functions/Function1;)V
Expand Down
8 changes: 5 additions & 3 deletions dropshots/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ plugins {

android {
namespace = "com.dropbox.dropshots"
compileSdk = 32
compileSdk = 34
testOptions.targetSdk = 34
lint.targetSdk = 34

defaultConfig {
minSdk = 19
targetSdk = 32
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -55,6 +56,7 @@ dependencies {
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.uiautomator)
}

mavenPublishing {
Expand Down
Binary file modified dropshots/src/androidTest/assets/MatchesActivityScreenshot.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 dropshots/src/androidTest/assets/MatchesFullScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class DropshotsTest {
private val fakeValidator = FakeResultValidator()
private val isRecordingScreenshots = isRecordingScreenshots()

@get:Rule
val emulatorConfigRule = EmulatorConfigRule()

@get:Rule
val activityScenarioRule = ActivityScenarioRule(TestActivity::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.dropbox.dropshots

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class EmulatorConfigRule : TestRule {
override fun apply(base: Statement, description: Description): Statement =
EmulatorConfigStatement(base)

private class EmulatorConfigStatement(
private val base: Statement,
) : Statement() {
override fun evaluate() {
enableDemoMode()
base.evaluate()
disableDemoMode()
}

private fun enableDemoMode() {
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.apply {
executeShellCommand("cmd overlay enable com.android.internal.systemui.navbar.gestural")
executeShellCommand("settings put global sysui_demo_allowed 1")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command enter")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1234")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command battery -e plugged false")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command battery -e level 100")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command notifications -e visible false")
}
}

private fun disableDemoMode() {
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.executeShellCommand("am broadcast -a com.android.systemui.demo -e command exit")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.dropbox.dropshots

class TestActivity : androidx.fragment.app.FragmentActivity()
public class TestActivity : androidx.fragment.app.FragmentActivity()
6 changes: 3 additions & 3 deletions dropshots/src/main/java/com/dropbox/dropshots/Dropshots.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class Dropshots(
view: View,
name: String = snapshotName,
filePath: String? = null,
) = assertSnapshot(Screenshot.capture(view).bitmap, name, filePath)
): Unit = assertSnapshot(Screenshot.capture(view).bitmap, name, filePath)

/**
* Compares a screenshot of the activity to a reference screenshot from the test application's assets.
Expand All @@ -91,7 +91,7 @@ public class Dropshots(
activity: Activity,
name: String = snapshotName,
filePath: String? = null,
) = assertSnapshot(Screenshot.capture(activity).bitmap, name, filePath)
): Unit = assertSnapshot(Screenshot.capture(activity).bitmap, name, filePath)

/**
* Compares a screenshot of the visible screen content to a reference screenshot from the test application's assets.
Expand All @@ -104,7 +104,7 @@ public class Dropshots(
public fun assertSnapshot(
name: String = snapshotName,
filePath: String? = null,
) = assertSnapshot(Screenshot.capture().bitmap, name, filePath)
): Unit = assertSnapshot(Screenshot.capture().bitmap, name, filePath)

@Suppress("LongMethod")
public fun assertSnapshot(
Expand Down
Loading

0 comments on commit 2b640c6

Please sign in to comment.