Skip to content

Commit 26f18b9

Browse files
committed
[#70] Apply new testing rule
1 parent 8e55140 commit 26f18b9

File tree

5 files changed

+120
-88
lines changed

5 files changed

+120
-88
lines changed

.github/workflows/dropshots-screenshot-test.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,28 @@ jobs:
104104
# Check screenshot directory
105105
adb shell find /sdcard -name "*.png" -type f 2>/dev/null || echo "No PNG files found"
106106
107-
# Extract screenshots from Dropshots results directory
107+
# Extract screenshots from internal app cache directory
108108
mkdir -p screenshots/api-27
109109
110-
# Collect screenshots from internal app cache directory
111-
adb pull /data/data/com.skydoves.cloudydemo/cache/dropshots/ ./screenshots/api-27/ 2>/dev/null || echo "No internal dropshots directory"
112-
adb pull /sdcard/dropshots/ ./screenshots/api-27/ 2>/dev/null || echo "No dropshots directory"
113-
adb pull /storage/emulated/0/dropshots/ ./screenshots/api-27/ 2>/dev/null || echo "No emulated dropshots directory"
110+
# Collect screenshots from internal cache directory (our custom location)
111+
adb pull /data/data/com.skydoves.cloudydemo/cache/screenshots/ ./screenshots/api-27/ 2>/dev/null || echo "No internal screenshots directory"
112+
113+
# List what we found
114+
echo "Screenshots found in api-27:"
115+
ls -la ./screenshots/api-27/ || echo "No files found"
114116
115-
# Also check app build outputs
116-
find ./app/build/outputs -name "*.png" -type f -exec cp {} ./screenshots/api-27/ \; 2>/dev/null || echo "No build output screenshots"
117-
118-
# Clean up filenames and add API level
117+
# Add API level suffix to filenames if needed
119118
cd ./screenshots/api-27
120119
for file in *.png 2>/dev/null; do
121120
if [[ -f "$file" && "$file" != *"api27"* ]]; then
122121
base_name="${file%.png}"
123122
mv "$file" "${base_name}_api27.png" 2>/dev/null || true
124123
fi
125124
done
125+
cd - > /dev/null
126126
127-
echo "Screenshots in api-27:"
128-
ls -la || echo "No files found"
127+
echo "Final screenshots in api-27:"
128+
ls -la ./screenshots/api-27/ || echo "No files found"
129129
130130
- name: Upload screenshots artifact
131131
if: always()
@@ -223,28 +223,28 @@ jobs:
223223
# Check screenshot directory
224224
adb shell find /sdcard -name "*.png" -type f 2>/dev/null || echo "No PNG files found"
225225
226-
# Extract screenshots from Dropshots results directory
226+
# Extract screenshots from internal app cache directory
227227
mkdir -p screenshots/api-${{ matrix.api-level }}
228228
229-
# Collect screenshots from internal app cache directory
230-
adb pull /data/data/com.skydoves.cloudydemo/cache/dropshots/ ./screenshots/api-${{ matrix.api-level }}/ 2>/dev/null || echo "No internal dropshots directory"
231-
adb pull /sdcard/dropshots/ ./screenshots/api-${{ matrix.api-level }}/ 2>/dev/null || echo "No dropshots directory"
232-
adb pull /storage/emulated/0/dropshots/ ./screenshots/api-${{ matrix.api-level }}/ 2>/dev/null || echo "No emulated dropshots directory"
233-
234-
# Also check app build outputs
235-
find ./app/build/outputs -name "*.png" -type f -exec cp {} ./screenshots/api-${{ matrix.api-level }}/ \; 2>/dev/null || echo "No build output screenshots"
229+
# Collect screenshots from internal cache directory (our custom location)
230+
adb pull /data/data/com.skydoves.cloudydemo/cache/screenshots/ ./screenshots/api-${{ matrix.api-level }}/ 2>/dev/null || echo "No internal screenshots directory"
231+
232+
# List what we found
233+
echo "Screenshots found in api-${{ matrix.api-level }}:"
234+
ls -la ./screenshots/api-${{ matrix.api-level }}/ || echo "No files found"
236235
237-
# Clean up filenames and add API level
236+
# Add API level suffix to filenames if needed
238237
cd ./screenshots/api-${{ matrix.api-level }}
239238
for file in *.png 2>/dev/null; do
240239
if [[ -f "$file" && "$file" != *"api${{ matrix.api-level }}"* ]]; then
241240
base_name="${file%.png}"
242241
mv "$file" "${base_name}_api${{ matrix.api-level }}.png" 2>/dev/null || true
243242
fi
244243
done
244+
cd - > /dev/null
245245
246-
echo "Screenshots in api-${{ matrix.api-level }}:"
247-
ls -la || echo "No files found"
246+
echo "Final screenshots in api-${{ matrix.api-level }}:"
247+
ls -la ./screenshots/api-${{ matrix.api-level }}/ || echo "No files found"
248248
249249
- name: Upload screenshots artifact
250250
if: always()

app/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ plugins {
2525
id(libs.plugins.android.application.get().pluginId)
2626
id(libs.plugins.kotlin.android.get().pluginId)
2727
id(libs.plugins.compose.compiler.get().pluginId)
28-
id(libs.plugins.dropshots.get().pluginId)
2928
}
3029

3130
android {
@@ -102,7 +101,6 @@ dependencies {
102101
testImplementation(libs.androidx.compose.ui.test.junit4)
103102

104103
// Android Instrumentation Test dependencies (Device-based for Native libraries)
105-
androidTestImplementation(libs.dropshots)
106104
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
107105
androidTestImplementation(libs.androidx.ui.test.manifest)
108106
androidTestImplementation(libs.androidx.junit)

app/src/androidTest/kotlin/com/skydoves/cloudydemo/DropshostsTestRule.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/src/androidTest/kotlin/com/skydoves/cloudydemo/MainTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith
2828
class MainTest {
2929

3030
@get:Rule
31-
val dropshots = DropshostsTestRule()
31+
val screenshots = ScreenshotTestRule()
3232

3333
@Test
3434
fun testCloudyMainScreenApi27() {
@@ -77,7 +77,7 @@ class MainTest {
7777

7878
// Capture screenshot with error handling
7979
try {
80-
dropshots.assertSnapshot(
80+
screenshots.takeScreenshot(
8181
view = activity.findViewById(android.R.id.content),
8282
name = "cloudy_main_screen_$apiSuffix"
8383
)
@@ -87,7 +87,7 @@ class MainTest {
8787
// Try one more time after reduced wait
8888
Thread.sleep(1000)
8989
try {
90-
dropshots.assertSnapshot(
90+
screenshots.takeScreenshot(
9191
view = activity.findViewById(android.R.id.content),
9292
name = "cloudy_main_screen_$apiSuffix"
9393
)
@@ -117,7 +117,7 @@ class MainTest {
117117
Thread.sleep(400) // Optimized single wait
118118

119119
try {
120-
dropshots.assertSnapshot(
120+
screenshots.takeScreenshot(
121121
view = activity.findViewById(android.R.id.content),
122122
name = "cloudy_blur_initial_api${Build.VERSION.SDK_INT}"
123123
)
@@ -131,7 +131,7 @@ class MainTest {
131131
Thread.sleep(1000) // Animation duration
132132

133133
try {
134-
dropshots.assertSnapshot(
134+
screenshots.takeScreenshot(
135135
view = activity.findViewById(android.R.id.content),
136136
name = "cloudy_blur_complete_api${Build.VERSION.SDK_INT}"
137137
)
@@ -160,7 +160,7 @@ class MainTest {
160160
Thread.sleep(400) // Initial state
161161

162162
try {
163-
dropshots.assertSnapshot(
163+
screenshots.takeScreenshot(
164164
view = activity.findViewById(android.R.id.content),
165165
name = "cloudy_animation_start_api${Build.VERSION.SDK_INT}"
166166
)
@@ -174,7 +174,7 @@ class MainTest {
174174
Thread.sleep(1000) // Full animation duration
175175

176176
try {
177-
dropshots.assertSnapshot(
177+
screenshots.takeScreenshot(
178178
view = activity.findViewById(android.R.id.content),
179179
name = "cloudy_animation_end_api${Build.VERSION.SDK_INT}"
180180
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Designed and developed by 2022 skydoves (Jaewoong Eum)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.skydoves.cloudydemo
17+
18+
import android.content.Context
19+
import android.graphics.Bitmap
20+
import android.graphics.Canvas
21+
import android.view.View
22+
import androidx.test.platform.app.InstrumentationRegistry
23+
import org.junit.rules.TestRule
24+
import org.junit.runner.Description
25+
import org.junit.runners.model.Statement
26+
import java.io.File
27+
import java.io.FileOutputStream
28+
29+
/**
30+
* Custom screenshot test rule that doesn't require any permissions.
31+
* Uses internal app storage to save screenshots for CI collection.
32+
*/
33+
class ScreenshotTestRule : TestRule {
34+
35+
private val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
36+
private val screenshotDir: File
37+
38+
init {
39+
// Create screenshots directory in internal cache (no permissions needed)
40+
screenshotDir = File(context.cacheDir, "screenshots")
41+
if (!screenshotDir.exists()) {
42+
screenshotDir.mkdirs()
43+
}
44+
println("Screenshot directory created at: ${screenshotDir.absolutePath}")
45+
}
46+
47+
override fun apply(base: Statement, description: Description): Statement {
48+
return object : Statement() {
49+
override fun evaluate() {
50+
try {
51+
base.evaluate()
52+
} finally {
53+
// Cleanup if needed
54+
}
55+
}
56+
}
57+
}
58+
59+
fun takeScreenshot(view: View, name: String) {
60+
try {
61+
// Create bitmap from view
62+
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
63+
val canvas = Canvas(bitmap)
64+
view.draw(canvas)
65+
66+
// Save to internal cache directory
67+
val file = File(screenshotDir, "$name.png")
68+
FileOutputStream(file).use { out ->
69+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
70+
}
71+
72+
println("Screenshot saved: ${file.absolutePath}")
73+
println("Screenshot size: ${file.length()} bytes")
74+
75+
// Also try to save to external accessible location for CI collection
76+
try {
77+
val externalFile = File("/data/data/${context.packageName}/cache/screenshots", "$name.png")
78+
externalFile.parentFile?.mkdirs()
79+
FileOutputStream(externalFile).use { out ->
80+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
81+
}
82+
println("External screenshot saved: ${externalFile.absolutePath}")
83+
} catch (e: Exception) {
84+
println("External save failed (expected): ${e.message}")
85+
}
86+
} catch (e: Exception) {
87+
println("Screenshot capture failed: ${e.message}")
88+
throw AssertionError("Failed to capture screenshot: ${e.message}")
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)