Skip to content

Commit

Permalink
Move all screenshots to one tests and only run this test via screengr…
Browse files Browse the repository at this point in the history
…ab (#797)

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Mar 23, 2018
1 parent ff6a22a commit 55a5050
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion fastlane/Screengrabfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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')
app_apk_path('mobile/build/outputs/apk/fullStable/debug/mobile-full-stable-debug.apk')

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'])
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -120,21 +108,21 @@ public void openHABMainActivityTest() throws InterruptedException {
}
}

private interface ChildViewCallback {
public interface ChildViewCallback {
View findChild(View parent);
}

private static Matcher<View> atPositionOnView(final int position,
public static Matcher<View> atPositionOnView(final int position,
final Matcher<View> itemMatcher, @IdRes final int targetViewId) {
return atPositionOnView(position, itemMatcher, parent -> parent.findViewById(targetViewId));
}

private static Matcher<View> atPositionOnView(final int position,
public static Matcher<View> atPositionOnView(final int position,
final Matcher<View> itemMatcher, final String tag) {
return atPositionOnView(position, itemMatcher, parent -> parent.findViewWithTag(tag));
}

private static Matcher<View> atPositionOnView(final int position,
public static Matcher<View> atPositionOnView(final int position,
final Matcher<View> itemMatcher, final ChildViewCallback childCb) {
return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
@Override
Expand All @@ -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<View> getConstraints() {
Expand Down
36 changes: 14 additions & 22 deletions mobile/src/androidTest/java/org/openhab/habdroid/ui/NfcTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -28,43 +27,36 @@
@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()));

recyclerView.perform(actionOnItemAtPosition(1, longClick()));

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()));
}
Expand Down
12 changes: 6 additions & 6 deletions travis/prepare-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 55a5050

Please sign in to comment.