Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Update screenshot test scripts
Browse files Browse the repository at this point in the history
Disable Pocket related tests
Convert SettingTest (screenshot) to Java for Fastlane compatibility
  • Loading branch information
No Jun Park committed Apr 24, 2019
1 parent d2de3fb commit 549bed4
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 89 deletions.
6 changes: 4 additions & 2 deletions Screengrabfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use_tests_in_packages ['org.mozilla.tv.firefox.ui.screenshots']
app_package_name 'org.mozilla.tv.firefox.debug'

app_apk_path 'app/build/outputs/apk/debug/app-debug.apk'
tests_apk_path 'app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk'
app_apk_path 'app/build/outputs/apk/system/debug/app-system-debug.apk'
tests_apk_path 'app/build/outputs/apk/androidTest/system/debug/app-system-debug-androidTest.apk'

# Supported locales
locales ['en-US', 'de', 'zh-cn', 'fr', 'it', 'ja', 'pt-BR', 'es-ES']
Expand All @@ -25,3 +25,5 @@ exit_on_test_failure false

skip_open_summary false
reinstall_app true

test_instrumentation_runner 'org.mozilla.tv.firefox.FirefoxTestRunner'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

package org.mozilla.tv.firefox.ui.screenshots

import org.junit.Ignore
import org.junit.ClassRule
import org.junit.Rule
import org.junit.After
import org.junit.Test
import android.app.Application
import android.view.View
import androidx.test.platform.app.InstrumentationRegistry
Expand All @@ -16,10 +21,6 @@ import androidx.test.rule.ActivityTestRule
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import org.mozilla.tv.firefox.MainActivity
import org.mozilla.tv.firefox.R
import org.mozilla.tv.firefox.TestDependencyFactory
Expand All @@ -30,6 +31,8 @@ import org.mozilla.tv.firefox.utils.ServiceLocator
import tools.fastlane.screengrab.Screengrab
import tools.fastlane.screengrab.locale.LocaleTestRule

// Since pocket is currently EN-US only, this should be ignored
@Ignore
class PocketErrorTest : ScreenshotTest() {

companion object : TestDependencyFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mozilla.tv.firefox.MainActivity;
Expand All @@ -32,7 +33,8 @@
import static org.mozilla.tv.firefox.onboarding.OnboardingActivity.ONBOARD_SHOWN_PREF;
import static org.mozilla.tv.firefox.pocket.PocketOnboardingActivity.POCKET_ONBOARDING_SHOWN_PREF;


// Since pocket is currently EN-US only, this should be ignored
@Ignore
public class PocketOnboardTest extends ScreenshotTest {

private Intent intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.junit.After;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mozilla.tv.firefox.MainActivity;
Expand All @@ -26,7 +27,8 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;


// Since pocket is currently EN-US only, this should be ignored
@Ignore
public class PocketRecommendationTest extends ScreenshotTest {

private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ String getString(@StringRes int resourceId) {
String getString(@StringRes int resourceId, Object... formatArgs) {
return targetContext.getString(resourceId, formatArgs).trim();
}

public void takeScreenshotsAfterWait(String filename, int waitingTime) throws InterruptedException {

Thread.sleep(waitingTime);
Screengrab.screenshot(filename);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.tv.firefox.ui.screenshots;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.UiDevice;

import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.mozilla.tv.firefox.MainActivity;
import org.mozilla.tv.firefox.R;
import org.mozilla.tv.firefox.helpers.MainActivityTestRule;

import tools.fastlane.screengrab.Screengrab;
import tools.fastlane.screengrab.locale.LocaleTestRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;


public class SettingsTest extends ScreenshotTest {

private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new MainActivityTestRule();

@After
public void tearDown() {
mActivityTestRule.getActivity().finishAndRemoveTask();
}

@Test
public void showSettingsViews() throws InterruptedException {
onView(withId(R.id.navUrlInput)).check(matches(isDisplayed()));

// current settings list view
onView(withId(R.id.container_web_render)).check(matches(isDisplayed()));

// This will need to change if the button layout changes. However, such layout
// changes are infrequent, and updating this will be easy.
device.pressDPadDown();
device.pressDPadDown();
device.pressDPadDown();
device.pressDPadDown();

onView(withId(R.id.settings_tile_telemetry)).check(matches(isDisplayed()));

// capture a screenshot of the default settings list
Screengrab.screenshot("settings");

onView(withId(R.id.settings_tile_telemetry)).perform(click());
takeScreenshotsAfterWait("send-usage-data", 5000);
mDevice.pressBack();

onView(withId(R.id.settings_tile_cleardata)).perform(click());
takeScreenshotsAfterWait("clear-all-data", 5000);
mDevice.pressBack();
onView(withId(R.id.settings_tile_about)).perform(click());
takeScreenshotsAfterWait("about-screen", 5000);
mDevice.pressBack();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.tv.firefox.ui.screenshots;

import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.Until;

import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.mozilla.tv.firefox.MainActivity;
import org.mozilla.tv.firefox.R;
import org.mozilla.tv.firefox.helpers.MainActivityTestRule;

import tools.fastlane.screengrab.locale.LocaleTestRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;

public class TooltipCaptureTest extends ScreenshotTest {

@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new MainActivityTestRule();

@After
public void tearDown() {
mActivityTestRule.getActivity().finishAndRemoveTask();
}

@Test
public void showToolTips() throws InterruptedException {

onView(allOf(withId(R.id.navUrlInput), hasFocus())).check(matches(isDisplayed()));
onView(withId(R.id.tileContainer)).check(matches(isDisplayed()));

// open two sites to enable back and front button
onView(withId(R.id.tileContainer)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
device.wait(Until.findObject(By.res(Integer.toString(R.id.progressAnimation))), 2000);
device.pressMenu();
onView(withId(R.id.tileContainer)).perform(RecyclerViewActions.actionOnItemAtPosition(2, click()));
device.wait(Until.findObject(By.res(Integer.toString(R.id.progressAnimation))), 2000);

device.pressMenu();
device.pressDPadUp();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-backbutton", 500);

onView(withId(R.id.navButtonBack)).perform(click());
device.wait(Until.findObject(By.res(Integer.toString(R.id.progressAnimation))), 2000);
device.pressMenu();
device.pressDPadUp();
device.pressDPadRight(); // In fastlane, back button is still enabled - this might be fastlane issue

// forward button
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-forwardbutton", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-reload", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-pintohs", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-turbomode", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-requestdesktop", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-exit", 500);
device.pressDPadRight();
onView(withId(R.id.tooltip)).inRoot(isPlatformPopup()).check(matches(isDisplayed()));
takeScreenshotsAfterWait("tooltip-settings", 500);
device.pressDPadLeft();
device.pressDPadLeft();
device.pressDPadCenter();
takeScreenshotsAfterWait("desktoprequested", 500);
}
}
22 changes: 5 additions & 17 deletions download-build-run-locale-screenshots.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

REPO="https://github.com/mozilla-mobile/firefox-tv.git"
CLONE_DIR="$HOME/Desktop/firefox-tv"
SCREENSHOTS_DIR="$CLONE_DIR/fastlane"
CONFIG="$CLONE_DIR/Screengrabfile"
SCREENSHOTS_DIR="fastlane"
CONFIG="Screengrabfile"

# optional – location used to upload screenshots
DROPBOX_DIR="$HOME/Dropbox"
Expand All @@ -38,26 +38,14 @@ adb -s $ANDROID_SERIAL shell settings put global window_animation_scale 0
adb -s $ANDROID_SERIAL shell settings put global transition_animation_scale 0
adb -s $ANDROID_SERIAL shell settings put global animatior_duration_scale 0

# clone repository
if [ -d "$CLONE_DIR" ]; then
cd "$CLONE_DIR"
git pull origin master
else
git clone "$REPO" "$CLONE_DIR"
cd "$CLONE_DIR"
fi

# build debug app
./gradlew clean app:assembleDebug
./gradlew clean app:assembleSystemDebug

# build test app
./gradlew app:assembleAndroidTest
./gradlew app:assembleSystemDebugAndroidTest

# uninstall existing apps
./gradlew uninstallDebug uninstallDebugAndroidTest

# install apps
./gradlew installDebug installDebugAndroidTest
./gradlew uninstallSystemDebug uninstallSystemDebugAndroidTest

# inject target device into Screengrabfile
echo "specific_device '$ANDROID_SERIAL'" >> $CONFIG
Expand Down

0 comments on commit 549bed4

Please sign in to comment.