-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement automatic screenshot generation
- Loading branch information
1 parent
f6feb2c
commit 8664660
Showing
8 changed files
with
272 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
on: | ||
push: | ||
branches: | ||
- '*' | ||
|
||
name: Generate Screenshots | ||
|
||
jobs: | ||
|
||
screenshot: | ||
name: Generate screenshots | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
api-level: [ 34 ] | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: AVD cache | ||
uses: actions/cache@v3 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/avd/* | ||
~/.android/adb* | ||
key: avd-${{ matrix.api-level }} | ||
|
||
- name: create AVD and generate snapshot for caching | ||
if: steps.avd-cache.outputs.cache-hit != 'true' | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
target: playstore | ||
arch: x86_64 | ||
profile: pixel_4 | ||
force-avd-creation: false | ||
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
disable-animations: false | ||
script: echo "Generated AVD snapshot for caching." | ||
|
||
- name: Set up Java environment | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'zulu' | ||
cache: 'gradle' | ||
|
||
- name: Build app | ||
run: ./gradlew assembleGoogleNormalDebug assembleGoogleNormalAndroidTest | ||
env: | ||
GOINGELECTRIC_API_KEY: ${{ secrets.GOINGELECTRIC_API_KEY }} | ||
OPENCHARGEMAP_API_KEY: ${{ secrets.OPENCHARGEMAP_API_KEY }} | ||
CHARGEPRICE_API_KEY: ${{ secrets.CHARGEPRICE_API_KEY }} | ||
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }} | ||
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }} | ||
FRONYX_API_KEY: ${{ secrets.FRONYX_API_KEY }} | ||
ACRA_CRASHREPORT_CREDENTIALS: ${{ secrets.ACRA_CRASHREPORT_CREDENTIALS }} | ||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | ||
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }} | ||
KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }} | ||
|
||
- name: Start System UI demo mode | ||
run: | | ||
- name: Run emulator and generate screenshots | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
target: playstore | ||
arch: x86_64 | ||
profile: pixel_4 | ||
force-avd-creation: false | ||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
disable-animations: false | ||
script: | | ||
adb shell settings put global hidden_api_policy 1 | ||
# Start demo mode | ||
adb shell settings put global sysui_demo_allowed 1 | ||
# Display time 12:00 | ||
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200 | ||
# Display full mobile data without type | ||
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e level 4 -e datatype false | ||
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4 -e fully true | ||
# Hide notifications | ||
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false | ||
# Show full battery but not in charging state | ||
adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false -e level 100 | ||
fastlane screengrab --app_apk_path app/build/outputs/apk/googleNormal/debug/app-google-normal-debug.apk --test_apk_path app/build/outputs/apk/androidTest/googleNormal/debug/app-google-normal-debug-androidTest.apk --tests_package_name=net.vonforst.evmap.debug.test --app_package_name net.vonforst.evmap.debug -p net.vonforst.evmap.screenshot --use_timestamp_suffix false --clear_previous_screenshots true -q en-US,de-DE | ||
adb shell am broadcast -a com.android.systemui.demo -e command exit | ||
- name: Upload screenshots as artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: screenshots | ||
path: fastlane/metadata/android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/src/androidTest/java/net/vonforst/evmap/screenshot/ScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package net.vonforst.evmap.screenshot | ||
|
||
import android.Manifest.permission.ACCESS_FINE_LOCATION | ||
import android.content.Intent | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.IdlingRegistry | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.contrib.DrawerActions | ||
import androidx.test.espresso.contrib.NavigationViewActions | ||
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 | ||
import androidx.test.rule.GrantPermissionRule | ||
import androidx.test.rule.GrantPermissionRule.grant | ||
import kotlinx.coroutines.runBlocking | ||
import net.vonforst.evmap.EXTRA_CHARGER_ID | ||
import net.vonforst.evmap.EXTRA_LAT | ||
import net.vonforst.evmap.EXTRA_LON | ||
import net.vonforst.evmap.EspressoIdlingResource | ||
import net.vonforst.evmap.MapsActivity | ||
import net.vonforst.evmap.storage.PreferenceDataSource | ||
import org.junit.BeforeClass | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import tools.fastlane.screengrab.Screengrab | ||
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy | ||
import tools.fastlane.screengrab.locale.LocaleTestRule | ||
import net.vonforst.evmap.R | ||
import net.vonforst.evmap.api.goingelectric.GEReferenceData | ||
import net.vonforst.evmap.api.goingelectric.GoingElectricApiWrapper | ||
import net.vonforst.evmap.model.Favorite | ||
import net.vonforst.evmap.storage.AppDatabase | ||
|
||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ScreenshotTest { | ||
companion object { | ||
@JvmStatic | ||
@BeforeClass | ||
fun beforeAll() { | ||
Screengrab.setDefaultScreenshotStrategy(UiAutomatorScreenshotStrategy()) | ||
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource) | ||
|
||
val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
val prefs = PreferenceDataSource(context) | ||
prefs.dataSourceSet = true | ||
prefs.welcomeDialogShown = true | ||
prefs.privacyAccepted = true | ||
prefs.opensourceDonationsDialogShown = true | ||
prefs.chargepriceMyVehicles = setOf("b58bc94d-d929-ad71-d95b-08b877bf76ba") | ||
|
||
// insert favorites | ||
val db = AppDatabase.getInstance(context) | ||
val api = GoingElectricApiWrapper( | ||
context.getString(R.string.goingelectric_key), | ||
context = context | ||
) | ||
val ids = listOf(70774L, 40315L, 49219L) | ||
runBlocking { | ||
val refData = api.getReferenceData().data as GEReferenceData | ||
ids.forEachIndexed { i, id -> | ||
val detail = api.getChargepointDetail(refData, id).data!! | ||
db.chargeLocationsDao().insert(detail) | ||
db.favoritesDao().insert( | ||
Favorite( | ||
i.toLong(), | ||
chargerId = id, | ||
chargerDataSource = "goingelectric" | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@get:Rule | ||
val localeTestRule = LocaleTestRule() | ||
|
||
@get:Rule | ||
val activityRule: ActivityScenarioRule<MapsActivity> = ActivityScenarioRule( | ||
Intent( | ||
InstrumentationRegistry.getInstrumentation().targetContext, | ||
MapsActivity::class.java | ||
).apply { | ||
putExtra(EXTRA_CHARGER_ID, 62489L) | ||
putExtra(EXTRA_LAT, 53.099512) | ||
putExtra(EXTRA_LON, 9.981884) | ||
}) | ||
|
||
@get:Rule | ||
val permissionRule: GrantPermissionRule = grant(ACCESS_FINE_LOCATION) | ||
|
||
@Test | ||
fun testTakeScreenshot() { | ||
Thread.sleep(3000L) | ||
Screengrab.screenshot("01_map") | ||
|
||
onView(withId(R.id.topPart)).perform(click()) | ||
Screengrab.screenshot("02_detail") | ||
|
||
onView(withId(R.id.btnChargeprice)).perform(click()) | ||
Screengrab.screenshot("03_prices") | ||
|
||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.favs)) | ||
|
||
Thread.sleep(3000L) | ||
Screengrab.screenshot("04_favorites") | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...johan/evmap/storage/SavedRegionDaoTest.kt → ...forst/evmap/storage/SavedRegionDaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters