Allow to run different colors on dark/light mode

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-07-28 22:14:14 +02:00
parent 0a062ea937
commit c9c0ae9e46
No known key found for this signature in database
GPG Key ID: 0E00D4D47D0C5AF7
18 changed files with 194 additions and 99 deletions

View File

@ -192,7 +192,7 @@ steps:
- ./gradlew assembleGplayDebug
- scripts/wait_for_emulator.sh
- ./gradlew installGplayDebugAndroidTest
- ./gradlew gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest && scripts/deleteOutdatedComments.sh "stable" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN
- scripts/runAllScreenshotCombinations "stable" false
- name: notify
image: drillster/drone-email
settings:
@ -247,7 +247,7 @@ steps:
- scripts/wait_for_emulator.sh
- ./gradlew installGplayDebugAndroidTest
- sed -i s"#5#1#" ./src/androidTest/java/com/nextcloud/client/RetryTestRule.kt
- ./gradlew gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest && scripts/deleteOutdatedComments.sh "master" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "master" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN
- scripts/runAllScreenshotCombinations "master" false
- name: notify
image: drillster/drone-email
settings:

View File

@ -3,11 +3,17 @@
if [ $# -lt 2 ]; then
echo "1: record: true/false
2: class name
3: method name"
3: method name
4: darkMode / \"all\" to run all screenshot combinations
5: color"
exit
fi
sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
cd src/androidTest/java
class=$(find | grep $2 | grep -E "java$|kt$" | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##'| sed s'#\.kt##')
@ -37,8 +43,27 @@ else
fi
fi
./gradlew gplayDebugExecuteScreenshotTests $record \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
-Pandroid.testInstrumentationRunnerArguments.class=$class$method
if [ -e $4 ] ; then
darkMode=""
else
darkMode="-Pandroid.testInstrumentationRunnerArguments.DARKMODE=$4"
fi
if [ -e $5 ] ; then
color=""
else
color="-Pandroid.testInstrumentationRunnerArguments.COLOR=$5"
fi
if [[ $4 = "all" ]]; then
scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
else
./gradlew gplayDebugExecuteScreenshotTests $record \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
-Pandroid.testInstrumentationRunnerArguments.class=$class$method \
$darkMode \
$color
fi
sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g src/main/res/values/setup.xml

View File

@ -0,0 +1,43 @@
#!/bin/bash
## $1 noCI/stable/master: wether to run deleteOutdatedComments.sh or uploadReport.sh
## $2 true/false: record or verify screenshots
## $3 classMethod: piped from androidScreenshotTest
if [[ $2 = "true" ]]; then
record="-Precord"
else
record=""
fi
classMethod=$3
while read line
do
darkMode=$(echo "$line" | cut -d" " -f1)
color=$(echo "$line" | cut -d" " -f2)
echo "Run $color on $darkMode mode"
if [[ $1 = "noCI" ]]; then
./gradlew --console plain gplayDebugExecuteScreenshotTests \
$record \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
-Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \
-Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" \
$classMethod </dev/null > /dev/null
if [[ $? -ne 0 ]]; then
exit
fi
else
./gradlew gplayDebugExecuteScreenshotTests \
$record \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
-Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \
-Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" \
&& scripts/deleteOutdatedComments.sh "$1-$darkMode-$color" "Screenshot" "$DRONE_PULL_REQUEST" \
"$GIT_USERNAME" "$GIT_TOKEN" \
|| scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$DRONE_BUILD_NUMBER" \
"$1-$darkMode-$color" "Screenshot" "$DRONE_PULL_REQUEST" "$GIT_USERNAME" "$GIT_TOKEN"
fi
done < scripts/screenshotCombinations

View File

@ -0,0 +1 @@
light blue

View File

@ -25,7 +25,6 @@ package com.nextcloud.client;
import android.Manifest;
import android.view.View;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
import com.owncloud.android.ui.activities.ActivitiesActivity;
@ -60,16 +59,13 @@ public class ActivitiesActivityIT extends AbstractIT {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
sut.runOnUiThread(new Runnable() {
@Override
public void run() {
sut.emptyContentContainer.setVisibility(View.VISIBLE);
sut.recyclerView.setVisibility(View.INVISIBLE);
}
sut.runOnUiThread(() -> {
sut.emptyContentContainer.setVisibility(View.VISIBLE);
sut.recyclerView.setVisibility(View.INVISIBLE);
});
waitForIdleSync();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
}

View File

@ -25,7 +25,6 @@ package com.nextcloud.client;
import android.Manifest;
import android.app.Activity;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractOnServerIT;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
@ -126,7 +125,7 @@ public class FileDisplayActivityIT extends AbstractOnServerIT {
shortSleep();
shortSleep();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
@Test

View File

@ -24,7 +24,6 @@ package com.nextcloud.client;
import android.Manifest;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@ -57,7 +56,7 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
sut.getListOfFilesFragment().setFabEnabled(false);
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
@Test
@ -70,6 +69,6 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
sut.getListOfFilesFragment().setFabEnabled(false);
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
}

View File

@ -25,7 +25,6 @@ package com.nextcloud.client;
import android.Manifest;
import android.app.Activity;
import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.onboarding.FirstRunActivity;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.utils.ScreenshotTest;
@ -51,7 +50,7 @@ public class FirstRunActivityIT extends AbstractIT {
public void open() {
Activity sut = activityRule.launchActivity(null);
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
}

View File

@ -1,52 +0,0 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client;
import android.Manifest;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.NotificationsActivity;
import com.owncloud.android.utils.ScreenshotTest;
import org.junit.Rule;
import org.junit.Test;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.rule.GrantPermissionRule;
public class NotificationsActivityIT extends AbstractIT {
@Rule public IntentsTestRule<NotificationsActivity> activityRule = new IntentsTestRule<>(NotificationsActivity.class,
true,
false);
@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
}
}

View File

@ -25,7 +25,6 @@ package com.nextcloud.client;
import android.Manifest;
import android.app.Activity;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.SettingsActivity;
import com.owncloud.android.utils.ScreenshotTest;
@ -49,8 +48,8 @@ public class SettingsActivityIT extends AbstractIT {
@Test
@ScreenshotTest
public void open() {
Activity test = activityRule.launchActivity(null);
Activity sut = activityRule.launchActivity(null);
Screenshot.snapActivity(test).record();
screenshot(sut);
}
}

View File

@ -25,7 +25,6 @@ package com.nextcloud.client;
import android.Manifest;
import android.content.Intent;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.MediaFolderType;
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
@ -87,6 +86,6 @@ public class SyncedFoldersActivityIT extends AbstractIT {
getInstrumentation().waitForIdleSync();
shortSleep();
Screenshot.snap(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView()).record();
screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView());
}
}

View File

@ -7,8 +7,12 @@ import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import com.facebook.testing.screenshot.Screenshot;
import com.facebook.testing.screenshot.internal.TestNameDetector;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.account.UserAccountManagerImpl;
@ -16,6 +20,8 @@ import com.nextcloud.client.device.BatteryStatus;
import com.nextcloud.client.device.PowerManagementService;
import com.nextcloud.client.network.Connectivity;
import com.nextcloud.client.network.ConnectivityService;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.nextcloud.client.preferences.DarkMode;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
@ -26,6 +32,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.FileStorageUtils;
@ -65,6 +72,8 @@ public abstract class AbstractIT {
protected static Account account;
protected static User user;
protected static Context targetContext;
protected static String DARK_MODE = "";
protected static String COLOR = "";
protected Activity currentActivity;
@ -107,6 +116,63 @@ public abstract class AbstractIT {
} catch (AccountUtils.AccountNotFoundException e) {
e.printStackTrace();
}
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
// color
String colorParameter = arguments.getString("COLOR");
if (!TextUtils.isEmpty(colorParameter)) {
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
targetContext.getContentResolver());
String colorHex = null;
COLOR = colorParameter;
switch (colorParameter) {
case "red":
colorHex = "#7c0000";
break;
case "green":
colorHex = "#00ff00";
break;
case "white":
colorHex = "#ffffff";
break;
case "black":
colorHex = "#000000";
break;
default:
break;
}
if (colorHex != null) {
OCCapability capability = fileDataStorageManager.getCapability(account.name);
capability.setServerColor(colorHex);
fileDataStorageManager.saveCapabilities(capability);
}
}
// dark / light
String darkModeParameter = arguments.getString("DARKMODE");
if (darkModeParameter != null) {
if (darkModeParameter.equalsIgnoreCase("dark")) {
DARK_MODE = "dark";
AppPreferencesImpl.fromContext(targetContext).setDarkThemeMode(DarkMode.DARK);
MainApp.setAppTheme(DarkMode.DARK);
} else {
DARK_MODE = "light";
}
}
if (DARK_MODE.equalsIgnoreCase("light") && COLOR.equalsIgnoreCase("blue")) {
// use already existing names
DARK_MODE = "";
COLOR = "";
}
}
protected FileDataStorageManager getStorageManager() {
@ -151,7 +217,7 @@ public abstract class AbstractIT {
waitForIdleSync();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
protected Activity getCurrentActivity() {
@ -249,4 +315,26 @@ public abstract class AbstractIT {
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
assertTrue(result.getLogMessage(), result.isSuccess());
}
protected void screenshot(View view) {
Screenshot.snap(view).setName(createName()).record();
}
protected void screenshot(Activity sut) {
Screenshot.snapActivity(sut).setName(createName()).record();
}
private String createName() {
String name = TestNameDetector.getTestClass() + "_" + TestNameDetector.getTestName();
if (!DARK_MODE.isEmpty()) {
name = name + "_" + DARK_MODE;
}
if (!COLOR.isEmpty()) {
name = name + "_" + COLOR;
}
return name;
}
}

View File

@ -24,7 +24,6 @@ package com.owncloud.android.ui.activity;
import android.content.Intent;
import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.account.UserAccountManagerImpl;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
@ -38,6 +37,8 @@ import com.owncloud.android.utils.ScreenshotTest;
import org.junit.Rule;
import org.junit.Test;
import java.util.Objects;
import androidx.fragment.app.DialogFragment;
import androidx.test.espresso.intent.rule.IntentsTestRule;
@ -87,7 +88,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
shortSleep();
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
}
// @Test
@ -141,7 +142,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
// getInstrumentation().waitForIdleSync();
// shortSleep();
//
// Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
// screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
// }
@Test
@ -222,7 +223,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
onView(withId(R.id.existing_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
onView(withText("OK")).perform(click());
@ -267,7 +268,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
onView(withId(R.id.new_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
onView(withText("OK")).perform(click());
@ -313,7 +314,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
onView(withId(R.id.new_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
onView(withText("OK")).perform(click());

View File

@ -24,7 +24,6 @@ package com.owncloud.android.ui.activity;
import android.app.Activity;
import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.account.User;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.utils.ScreenshotTest;
@ -47,7 +46,7 @@ public class ManageAccountsActivityIT extends AbstractIT {
shortSleep();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
@Test
@ -61,6 +60,6 @@ public class ManageAccountsActivityIT extends AbstractIT {
shortSleep();
shortSleep();
Screenshot.snapActivity(getCurrentActivity()).record();
screenshot(getCurrentActivity());
}
}

View File

@ -53,7 +53,7 @@ class NotificationsActivityIT : AbstractIT() {
shortSleep()
Screenshot.snapActivity(sut).record()
screenshot(sut)
}
@Test
@ -114,7 +114,7 @@ class NotificationsActivityIT : AbstractIT() {
shortSleep()
Screenshot.snapActivity(sut).record()
screenshot(sut)
}
@Test
@ -126,6 +126,6 @@ class NotificationsActivityIT : AbstractIT() {
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
Screenshot.snapActivity(sut).record()
screenshot(sut)
}
}

View File

@ -28,7 +28,6 @@ import android.accounts.AccountManager;
import android.content.Intent;
import android.os.Looper;
import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.account.RegisteredUser;
import com.nextcloud.client.account.Server;
import com.nextcloud.ui.ChooseAccountDialogFragment;
@ -162,6 +161,6 @@ public class DialogFragmentIT extends AbstractIT {
getInstrumentation().waitForIdleSync();
shortSleep();
Screenshot.snap(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
}
}

View File

@ -24,7 +24,6 @@ package com.owncloud.android.ui.dialog;
import android.Manifest;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@ -32,6 +31,8 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
import org.junit.Rule;
import org.junit.Test;
import java.util.Objects;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.rule.GrantPermissionRule;
@ -58,7 +59,7 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
getInstrumentation().waitForIdleSync();
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
}
@Test
@ -72,6 +73,6 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
getInstrumentation().waitForIdleSync();
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
}
}

View File

@ -24,7 +24,6 @@ package com.owncloud.android.ui.preview;
import android.Manifest;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@ -64,7 +63,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
shortSleep();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
@Test
@ -82,6 +81,6 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
shortSleep();
Screenshot.snapActivity(sut).record();
screenshot(sut);
}
}