From 4508f6cc1cf1964327bbb8e2e148d5f86eb4a36d Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Tue, 11 Apr 2023 18:34:48 +0200 Subject: [PATCH] draft: android screenshots --- android/app/build.gradle | 16 +++ .../src/androidTest/java/ScreenshotTest.java | 105 ++++++++++++++++++ android/app/src/debug/AndroidManifest.xml | 12 ++ android/gradle.properties | 2 +- fastlane/Fastfile | 18 +++ fastlane/README.md | 8 ++ 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 android/app/src/androidTest/java/ScreenshotTest.java diff --git a/android/app/build.gradle b/android/app/build.gradle index 3a23a4d..894f016 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -141,6 +141,7 @@ android { versionCode 15 versionName "2.0.3" buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" if (isNewArchitectureEnabled()) { // We configure the CMake build only if you decide to opt-in for the New Architecture. @@ -281,6 +282,21 @@ dependencies { exclude group:'com.facebook.flipper' } + // fastlane screengrab, falcon is a dependency of screengrab + androidTestImplementation 'com.jraska:falcon:2.2.0' + androidTestImplementation "tools.fastlane:screengrab:2.1.0" + // Espresso dependencies + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + // Hamcrest library + androidTestImplementation 'org.hamcrest:hamcrest-library:1.3' + + // Core library + androidTestImplementation 'androidx.test:core:1.4.0' + + // AndroidJUnitRunner and JUnit Rules + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + if (enableHermes) { //noinspection GradleDynamicVersion implementation("com.facebook.react:hermes-engine:+") { // From node_modules diff --git a/android/app/src/androidTest/java/ScreenshotTest.java b/android/app/src/androidTest/java/ScreenshotTest.java new file mode 100644 index 0000000..4717054 --- /dev/null +++ b/android/app/src/androidTest/java/ScreenshotTest.java @@ -0,0 +1,105 @@ +package nl.moeilijkedingen.jellyfinaudioplayer; + +import androidx.test.rule.ActivityTestRule; + +import nl.moeilijkedingen.jellyfinaudioplayer.R; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import java.util.Arrays; + +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.cleanstatusbar.BluetoothState; +import tools.fastlane.screengrab.cleanstatusbar.CleanStatusBar; +import tools.fastlane.screengrab.cleanstatusbar.MobileDataType; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +import androidx.test.espresso.NoMatchingViewException; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.typeText; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import static org.hamcrest.core.AllOf.allOf; + +@RunWith(JUnit4.class) +public class ScreenshotTest { + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(MainActivity.class); + + @BeforeClass + public static void beforeAll() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + CleanStatusBar.enableWithDefaults(); + } + + @AfterClass + public static void afterAll() { + CleanStatusBar.disable(); + } + + /* + Custom wait function. In order to make sure each button press yields a + desirable screen, we use the wait function to delay further actions until + the current one has achieved its purpose. + + `duration` indicates the amount of milli-seconds to wait. The value of + `duration` is acquired by emperical trial-and-error. + */ + public void wait(int duration) { + try { + Thread.sleep(duration); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void inputText(Integer id, String text) { + try { + onView(allOf(withId(id))).perform(typeText(text)); + } catch (NoMatchingViewException e) { + e.printStackTrace(); + } + } + + @Test + public void testTakeScreenshot() { + System.out.println("AVAILABLE IDS:" + Arrays.toString(R.id.class.getFields())); + // wait(10000); + + // Screengrab.screenshot("04RecentAlbums"); + // onView(allOf(withId(R.id.all_albums))).perform(click()); + // wait(5000); + // Screengrab.screenshot("05AlbumsScreen"); + + // onView(allOf(withId(R.id.search_tab))).perform(click()); + // wait(5000); + // onView(allOf(withId(R.id.search_input_container))).perform(click()); + // wait(5000); + // onView(allOf(withId(R.id.search_input_textinput))).perform(typeText("bicep")); + // wait(5000); + + // onView(allOf(withId(R.id.search_result_a644f8d23821601d2feb86ddae5e64f4))).perform(click()); + // wait(5000); + // Screengrab.screenshot("02AlbumScreen"); + + // onView(allOf(withId(R.id.play_album))).perform(click()); + // wait(5000); + // onView(allOf(withId(R.id.open_player_modal))).perform(click()); + // wait(5000); + // Screengrab.screenshot("01PlayModal"); + } +} \ No newline at end of file diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 528ac4b..028c3bf 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -3,6 +3,18 @@ xmlns:tools="http://schemas.android.com/tools"> + + + + + + + + + + + +