Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up our JDK environment
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17.0.10'
java-version: '17.0.14'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
uses: gradle/actions/setup-gradle@v3
with:
arguments: testDebugUnitTest
run: ./gradlew testDebugUnitTest
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.enableJetifier=false
android.injected.androidTest.leaveApksInstalledAfterRun=true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows us to collect screenshots off devices after instrumented tests (androidTest) finish


GROUP=com.wealthfront
VERSION_NAME=2.1.2-SNAPSHOT
Expand Down
2 changes: 1 addition & 1 deletion gradle/android-module.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
android {
compileSdkVersion 34
compileSdkVersion 35

defaultConfig {
minSdkVersion 26
Expand Down
14 changes: 8 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
[versions]
recyclerview = "1.3.2"
recyclerview = "1.4.0"
appcompat = "1.7.0"
androidx-activity-ktx = "1.9.1"
screenshotty = "1.0.4"
robolectric = "4.13"
robolectric = "4.14.1"
test-core = "1.6.1"
test-rules = "1.6.1"
test-ext = "1.2.1"
junit = "4.13.2"
truth = "1.0"
truth = "1.4.0"
espresso = "3.6.1"
agp = "8.5.1"
kotlin = "2.0.0"
compose-bom = "2023.09.02"
agp = "8.9.0"
kotlin = "2.0.21"
compose-bom = "2025.03.00"

[libraries]
recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerview" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "androidx-activity-ktx" }
screenshotty = { group = "eu.bolt", name = "screenshotty", version.ref = "screenshotty" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 10 11:07:40 PST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions screencaptor-sample-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ plugins {
alias(libs.plugins.compose.compiler)
}

apply(from = "../gradle/android-module.gradle")

android {
namespace = "com.wealthfront.screencaptor.sample.test"
compileSdk = 34

testOptions {
animationsDisabled = true
}

defaultConfig {
minSdk = 26
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ScreenshotComposeTest {
screenshotDirectory = screenShotDirectory
)

compareScreenshots("compose", TestRes.raw.compose_pixel7_api33)
compareScreenshots("compose", TestRes.raw.compose_pixel7_api35)
}

@Test
Expand All @@ -81,7 +81,7 @@ class ScreenshotComposeTest {
screenshotDirectory = screenShotDirectory
)

compareScreenshots("compose_dialogs", TestRes.raw.compose_dialogs_pixel7_api33)
compareScreenshots("compose_dialogs", TestRes.raw.compose_dialogs_pixel7_api35)
}


Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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.
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.
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.
3 changes: 2 additions & 1 deletion screencaptor-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ android {

dependencies {
implementation(project(":screencaptor"))
implementation(libs.recyclerview)
implementation(libs.appcompat)
implementation(libs.recyclerview)
implementation(libs.androidx.activity.ktx)
testImplementation(project(":internal-test-support"))

implementation(platform(libs.compose.bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wealthfront.screencaptor.sample
import android.app.AlertDialog
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -12,6 +13,8 @@ class SampleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

setContentView(R.layout.screenshot_test)
findViewById<Button>(R.id.showDialog).setOnClickListener {
AlertDialog.Builder(this)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified screencaptor-sample/src/main/res/raw/dialog.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 @@ -81,7 +81,7 @@ class ScreenshotComposeRobolectricTest {
)


compareScreenshots("compose", R.raw.compose_unknown_robolectric)
compareScreenshots("compose", R.raw.compose_robolectric_robolectric_34)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.wealthfront.screencaptor.sample

import android.Manifest.permission.READ_EXTERNAL_STORAGE
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.graphics.BitmapFactory.decodeByteArray
import android.graphics.BitmapFactory.decodeFile
import android.os.Environment
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
Expand All @@ -10,6 +13,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.GrantPermissionRule
import com.wealthfront.screencaptor.ScreenCaptor
import org.junit.After
import org.junit.Assert.assertTrue
Expand All @@ -18,22 +22,26 @@ import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.annotation.GraphicsMode
import java.io.File
import com.wealthfront.screencaptor.sample.R as AppRes

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class ScreenshotTest {

@Rule
@JvmField
val folder = TemporaryFolder()
private val screenShotDirectory: String =
"${getInstrumentation().targetContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!.absolutePath}/screenshots"

@get:Rule
var activityTestRule: ActivityScenarioRule<SampleActivity> = ActivityScenarioRule(SampleActivity::class.java)
var activityTestRule: ActivityScenarioRule<SampleActivity> =
ActivityScenarioRule(SampleActivity::class.java)

@get:Rule
var permissionsRule = GrantPermissionRule.grant(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)

@After
fun cleanUpScreenshots() {
folder.root.deleteRecursively()
File(screenShotDirectory).deleteRecursively()
}

@Test
Expand All @@ -46,10 +54,10 @@ class ScreenshotTest {
ScreenCaptor.takeScreenshot(
activityScenario = activityScenario,
screenshotName = "screenshot_dialog",
screenshotDirectory = folder.root.path
screenshotDirectory = screenShotDirectory,
)

val screenshot = folder.root.listFiles()!!.find { it.name.contains("screenshot_dialog") }!!
val screenshot = File(screenShotDirectory).listFiles()!!.find { it.name.contains("screenshot_dialog") }!!
val actual = decodeFile(screenshot.path)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sdk=26
sdk=34
qualifiers=w405dp-h720dp-xxhdpi
77 changes: 38 additions & 39 deletions screencaptor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.compose.compiler)
}

apply(from = "../gradle/gradle-mvn-push.gradle")
apply(from = "../gradle/android-module.gradle")

android {
namespace = "com.wealthfront.screencaptor"
resourcePrefix = "screencaptor"
namespace = "com.wealthfront.screencaptor"
resourcePrefix = "screencaptor"

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
compose = true
}
buildFeatures {
compose = true
}

publishing {
singleVariant("release") {
withSourcesJar()
}
publishing {
singleVariant("release") {
withSourcesJar()
}
}
}

dependencies {
implementation(libs.recyclerview)
implementation(libs.screenshotty)
implementation(libs.espresso.core)
implementation(libs.espresso.contrib)
implementation(libs.appcompat)

testImplementation(libs.robolectric)
testImplementation(libs.androidx.test)
testImplementation(libs.androidx.test.ktx)
testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.androidx.test.rules)
testImplementation(libs.androidx.test.junit)
testImplementation(libs.compose.junit4)

implementation(platform(libs.compose.bom))
implementation(libs.compose.foundation)
implementation(libs.compose.ui)
implementation(libs.compose.tooling)
implementation(libs.compose.tooling.preview)
implementation(libs.compose.material)
implementation(libs.compose.material3)
implementation(libs.compose.manifest)
implementation(libs.compose.junit4)
implementation(libs.recyclerview)
implementation(libs.screenshotty)
implementation(libs.espresso.core)
implementation(libs.espresso.contrib)

testImplementation(libs.robolectric)
testImplementation(libs.androidx.test)
testImplementation(libs.androidx.test.ktx)
testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.androidx.test.rules)
testImplementation(libs.androidx.test.junit)
testImplementation(libs.compose.junit4)

implementation(platform(libs.compose.bom))
implementation(libs.compose.foundation)
implementation(libs.compose.ui)
implementation(libs.compose.tooling)
implementation(libs.compose.tooling.preview)
implementation(libs.compose.material)
implementation(libs.compose.material3)
implementation(libs.compose.manifest)
implementation(libs.compose.junit4)
}
3 changes: 2 additions & 1 deletion screencaptor/src/test/resources/robolectric.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sdk=26
sdk=34
qualifiers=w405dp-h720dp-xxhdpi
Loading