From 55a5050564c4ca5563614bf2f61ebfc7b52b8445 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Fri, 23 Mar 2018 17:01:43 +0100 Subject: [PATCH] Move all screenshots to one tests and only run this test via screengrab (#797) Signed-off-by: mueller-ma --- .travis.yml | 2 +- fastlane/Screengrabfile | 4 +- .../habdroid/screengrab/ScreengrabTest.java | 93 +++++++++++++++++++ .../openhab/habdroid/ui/BasicWidgetTest.java | 22 +---- .../java/org/openhab/habdroid/ui/NfcTest.java | 36 +++---- travis/prepare-deploy.sh | 12 +-- 6 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 mobile/src/androidTest/java/org/openhab/habdroid/screengrab/ScreengrabTest.java diff --git a/.travis.yml b/.travis.yml index 9377429812..e530af809a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,9 +28,9 @@ android: install: - sed -i 's/org.gradle.daemon=false/org.gradle.daemon=true/' ~/.gradle/gradle.properties +- echo "mapsApiKey=AIzaSyA2t2893e9wccs9EnlnauJRgtqFNYQSp-o" >> ~/.gradle/gradle.properties - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2" -- echo "mapsApiKey=AIzaSyA2t2893e9wccs9EnlnauJRgtqFNYQSp-o" >> ~/.gradle/gradle.properties - ./gradlew --version - sdkmanager --list || true diff --git a/fastlane/Screengrabfile b/fastlane/Screengrabfile index b4d1f16d81..395d20663e 100644 --- a/fastlane/Screengrabfile +++ b/fastlane/Screengrabfile @@ -1,4 +1,4 @@ -locales ['en-US'] +locales ['af-ZA', 'ar-SA', 'bg-BG', 'ca-ES', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-US', 'es-ES', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'nl-NL', 'no-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-SP', 'sv-SE', 'tl-PH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN'] clear_previous_screenshots false app_package_name('org.openhab.habdroid') @@ -6,3 +6,5 @@ app_apk_path('mobile/build/outputs/apk/fullStable/debug/mobile-full-stable-debug tests_package_name('org.openhab.habdroid.test') tests_apk_path('mobile/build/outputs/apk/androidTest/fullStable/debug/mobile-full-stable-debug-androidTest.apk') + +use_tests_in_packages(['org.openhab.habdroid.screengrab']) diff --git a/mobile/src/androidTest/java/org/openhab/habdroid/screengrab/ScreengrabTest.java b/mobile/src/androidTest/java/org/openhab/habdroid/screengrab/ScreengrabTest.java new file mode 100644 index 0000000000..b053eb2f66 --- /dev/null +++ b/mobile/src/androidTest/java/org/openhab/habdroid/screengrab/ScreengrabTest.java @@ -0,0 +1,93 @@ +package org.openhab.habdroid.screengrab; + +import android.support.annotation.IdRes; +import android.support.test.espresso.DataInteraction; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.ViewInteraction; +import android.support.test.espresso.contrib.RecyclerViewActions; +import android.support.test.espresso.matcher.BoundedMatcher; +import android.support.test.runner.AndroidJUnit4; +import android.support.v7.widget.RecyclerView; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.View; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openhab.habdroid.BuildConfig; +import org.openhab.habdroid.R; +import org.openhab.habdroid.TestWithoutIntro; +import org.openhab.habdroid.ui.BasicWidgetTest; + +import tools.fastlane.screengrab.locale.LocaleTestRule; + +import static android.support.test.espresso.Espresso.onData; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.Espresso.pressBack; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.longClick; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withClassName; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.is; +import static org.openhab.habdroid.ui.BasicWidgetTest.atPositionOnView; +import static org.openhab.habdroid.ui.BasicWidgetTest.onChildView; +import static tools.fastlane.screengrab.Screengrab.*; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class ScreengrabTest extends TestWithoutIntro { + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Test + public void test() { + ViewInteraction recyclerView = onView(withId(R.id.recyclerview)); + + screenshot("menu"); + + // open widget overview + recyclerView.perform(RecyclerViewActions.actionOnItemAtPosition(10, click())); + + screenshot("widget_overview"); + + // open nfc selection + recyclerView.perform(actionOnItemAtPosition(1, longClick())); + + screenshot("nfc_selection"); + + // close nfc selection + pressBack(); + + // check whether selection widget appears and click on it + recyclerView + .perform(RecyclerViewActions.scrollToPosition(4)) + .check(matches(atPositionOnView(4, withText("Scene Selection"), R.id.widgetlabel))) + .check(matches(atPositionOnView(4, isDisplayed(), R.id.selectionspinner))) + .perform(RecyclerViewActions.actionOnItemAtPosition(4, onChildView(click(), R.id.selectionspinner))); + + screenshot("selection"); + + DataInteraction appCompatCheckedTextView = onData(anything()) + .inAdapterView(withClassName( + is("com.android.internal.app.AlertController$RecycleListView"))) + .atPosition(0); + appCompatCheckedTextView.check(matches(withText("off"))); + appCompatCheckedTextView.perform(click()); + + if (BuildConfig.FLAVOR.equals("full")) { + // check whether map view is displayed + recyclerView + .perform(RecyclerViewActions.scrollToPosition(13)) + .check(matches(atPositionOnView(13, isDisplayed(), "MapView"))); + screenshot("mapview"); + } + } +} diff --git a/mobile/src/androidTest/java/org/openhab/habdroid/ui/BasicWidgetTest.java b/mobile/src/androidTest/java/org/openhab/habdroid/ui/BasicWidgetTest.java index d64c48d8e9..e3fd1024c2 100644 --- a/mobile/src/androidTest/java/org/openhab/habdroid/ui/BasicWidgetTest.java +++ b/mobile/src/androidTest/java/org/openhab/habdroid/ui/BasicWidgetTest.java @@ -23,10 +23,6 @@ import org.openhab.habdroid.R; import org.openhab.habdroid.TestWithoutIntro; -import tools.fastlane.screengrab.Screengrab; -import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; -import tools.fastlane.screengrab.locale.LocaleTestRule; - import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; @@ -41,16 +37,10 @@ @LargeTest @RunWith(AndroidJUnit4.class) public class BasicWidgetTest extends TestWithoutIntro { - @ClassRule - public static final LocaleTestRule localeTestRule = new LocaleTestRule(); - @Test public void openHABMainActivityTest() throws InterruptedException { ViewInteraction recyclerView = onView(withId(R.id.recyclerview)); - //Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); - Screengrab.screenshot("menu"); - recyclerView .perform(RecyclerViewActions.scrollToPosition(0)) .check(matches(atPositionOnView(0, isDisplayed(), R.id.widgetlabel))) @@ -85,8 +75,6 @@ public void openHABMainActivityTest() throws InterruptedException { appCompatCheckedTextView.check(matches(withText("off"))); appCompatCheckedTextView.perform(click()); - Screengrab.screenshot("widget_overview"); - // check whether scene radio button group is present recyclerView .perform(RecyclerViewActions.scrollToPosition(5)) @@ -120,21 +108,21 @@ public void openHABMainActivityTest() throws InterruptedException { } } - private interface ChildViewCallback { + public interface ChildViewCallback { View findChild(View parent); } - private static Matcher atPositionOnView(final int position, + public static Matcher atPositionOnView(final int position, final Matcher itemMatcher, @IdRes final int targetViewId) { return atPositionOnView(position, itemMatcher, parent -> parent.findViewById(targetViewId)); } - private static Matcher atPositionOnView(final int position, + public static Matcher atPositionOnView(final int position, final Matcher itemMatcher, final String tag) { return atPositionOnView(position, itemMatcher, parent -> parent.findViewWithTag(tag)); } - private static Matcher atPositionOnView(final int position, + public static Matcher atPositionOnView(final int position, final Matcher itemMatcher, final ChildViewCallback childCb) { return new BoundedMatcher(RecyclerView.class) { @Override @@ -151,7 +139,7 @@ public boolean matchesSafely(final RecyclerView recyclerView) { }; } - private static ViewAction onChildView(final ViewAction action, @IdRes final int targetViewId) { + public static ViewAction onChildView(final ViewAction action, @IdRes final int targetViewId) { return new ViewAction() { @Override public Matcher getConstraints() { diff --git a/mobile/src/androidTest/java/org/openhab/habdroid/ui/NfcTest.java b/mobile/src/androidTest/java/org/openhab/habdroid/ui/NfcTest.java index aa02262719..84cab38b72 100644 --- a/mobile/src/androidTest/java/org/openhab/habdroid/ui/NfcTest.java +++ b/mobile/src/androidTest/java/org/openhab/habdroid/ui/NfcTest.java @@ -1,5 +1,7 @@ package org.openhab.habdroid.ui; +import android.content.Context; +import android.support.test.InstrumentationRegistry; import android.support.test.espresso.ViewInteraction; import android.support.test.espresso.contrib.RecyclerViewActions; import android.support.test.runner.AndroidJUnit4; @@ -12,9 +14,6 @@ import org.openhab.habdroid.R; import org.openhab.habdroid.TestWithoutIntro; -import tools.fastlane.screengrab.Screengrab; -import tools.fastlane.screengrab.locale.LocaleTestRule; - import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.longClick; @@ -28,15 +27,12 @@ @LargeTest @RunWith(AndroidJUnit4.class) public class NfcTest extends TestWithoutIntro { - @ClassRule - public static final LocaleTestRule localeTestRule = new LocaleTestRule(); - @Test public void nfcTest() throws InterruptedException { ViewInteraction recyclerView = onView(withId(R.id.recyclerview)); + Context context = InstrumentationRegistry.getTargetContext(); - recyclerView - .perform(RecyclerViewActions.actionOnItemAtPosition(10, click())); + recyclerView.perform(RecyclerViewActions.actionOnItemAtPosition(10, click())); recyclerView.perform(actionOnItemAtPosition(10, click())); @@ -44,27 +40,23 @@ public void nfcTest() throws InterruptedException { ViewInteraction title = onView(allOf( IsInstanceOf.instanceOf(android.widget.TextView.class), - withText("Write NFC tag action for this element"))); - title.check(matches(withText("Write NFC tag action for this element"))); + withText(context.getString(R.string.nfc_dialog_title)))); + title.check(matches(withText(context.getString(R.string.nfc_dialog_title)))); - ViewInteraction onButton = onView(withText("On")); - onButton.check(matches(withText("On"))); + ViewInteraction onButton = onView(withText(context.getString(R.string.nfc_action_on))); + onButton.check(matches(withText(context.getString(R.string.nfc_action_on)))); - ViewInteraction offButton = onView(withText("Off")); - offButton.check(matches(withText("Off"))); + ViewInteraction offButton = onView(withText(context.getString(R.string.nfc_action_off))); + offButton.check(matches(withText(context.getString(R.string.nfc_action_off)))); - ViewInteraction toggleButton = onView(withText("Toggle")); - toggleButton.check(matches(withText("Toggle"))); + ViewInteraction toggleButton = onView(withText(context.getString(R.string.nfc_action_toggle))); + toggleButton.check(matches(withText(context.getString(R.string.nfc_action_toggle)))); - ViewInteraction sitemapButton = onView(withText("Navigate to Sitemap page")); - sitemapButton.check(matches(withText("Navigate to Sitemap page"))); - - Screengrab.screenshot("nfc_select"); + ViewInteraction sitemapButton = onView(withText(context.getString(R.string.nfc_action_to_sitemap_page))); + sitemapButton.check(matches(withText(context.getString(R.string.nfc_action_to_sitemap_page)))); onButton.perform(click()); - Screengrab.screenshot("nfc_activity"); - ViewInteraction imageView = onView(withId(R.id.nfc_watermark)); imageView.check(matches(isDisplayed())); } diff --git a/travis/prepare-deploy.sh b/travis/prepare-deploy.sh index 6b063864b4..fdf69e7ff1 100644 --- a/travis/prepare-deploy.sh +++ b/travis/prepare-deploy.sh @@ -19,12 +19,12 @@ mkdir $HOME/apks_to_deploy cp mobile/build/outputs/apk/full${releaseFlavorCaptital}/release/mobile-full-${releaseFlavor}-release-unsigned.apk $HOME/apks_to_deploy cp mobile/build/outputs/apk/foss${releaseFlavorCaptital}/release/mobile-foss-${releaseFlavor}-release-unsigned.apk $HOME/apks_to_deploy cd $HOME/apks_to_deploy -jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $HOME/keystore -storepass $storepass mobile-full-${releaseFlavor}-release-unsigned.apk sign -jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $HOME/keystore -storepass $storepass mobile-foss-${releaseFlavor}-release-unsigned.apk sign -jarsigner -verify mobile-full-${releaseFlavor}-release-unsigned.apk -jarsigner -verify mobile-foss-${releaseFlavor}-release-unsigned.apk -${ANDROID_HOME}/build-tools/25.0.2/zipalign -v 4 mobile-full-${releaseFlavor}-release-unsigned.apk openhab-android.apk -${ANDROID_HOME}/build-tools/25.0.2/zipalign -v 4 mobile-foss-${releaseFlavor}-release-unsigned.apk openhab-android-foss.apk +jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $HOME/keystore -storepass $storepass mobile-full-${releaseFlavor}-release-unsigned.apk sign > /dev/null +jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $HOME/keystore -storepass $storepass mobile-foss-${releaseFlavor}-release-unsigned.apk sign > /dev/null +jarsigner -verify mobile-full-${releaseFlavor}-release-unsigned.apk > /dev/null +jarsigner -verify mobile-foss-${releaseFlavor}-release-unsigned.apk > /dev/null +${ANDROID_HOME}/build-tools/25.0.2/zipalign -v 4 mobile-full-${releaseFlavor}-release-unsigned.apk openhab-android.apk > /dev/null +${ANDROID_HOME}/build-tools/25.0.2/zipalign -v 4 mobile-foss-${releaseFlavor}-release-unsigned.apk openhab-android-foss.apk > /dev/null echo "Configure git" git config --local user.name "openhab-bot"