Skip to content

Commit

Permalink
Exclude shot for normal builds
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Feb 22, 2024
1 parent 3780d83 commit 002f61a
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/screenShotTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:
contents: read
pull-requests: write

concurrency:
concurrency:
group: screenshot-test-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

Expand Down Expand Up @@ -73,6 +73,8 @@ jobs:
run: scripts/deleteOldComments.sh "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}}

- name: Run screenshot tests
env:
SHOT_TEST: "true"
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2.30.1
with:
api-level: ${{ matrix.api-level }}
Expand Down
27 changes: 19 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.github.spotbugs.snom.SpotBugsTask
import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort
import com.github.spotbugs.snom.SpotBugsTask
import org.gradle.internal.jvm.Jvm

buildscript {
Expand Down Expand Up @@ -32,7 +32,12 @@ apply plugin: 'pmd'
apply from: "$rootProject.projectDir/jacoco.gradle"
apply plugin: 'com.github.spotbugs'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'shot'

// needed to make renovate run without shot, as shot requires Android SDK
// https://github.com/pedrovgs/Shot/issues/300
if (shotTest) {
apply plugin: 'shot'
}
apply plugin: 'com.google.devtools.ksp'


Expand Down Expand Up @@ -99,7 +104,11 @@ android {
}

// arguments to be passed to functional tests
testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
if (shotTest) {
testInstrumentationRunner "com.karumi.shot.ShotTestRunner"
} else {
testInstrumentationRunner "com.nextcloud.client.TestRunner"
}
testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
Expand Down Expand Up @@ -431,11 +440,13 @@ detekt {
config.setFrom("detekt.yml")
}

shot {
showOnlyFailingTestsInReports = ciBuild
// CI environment renders some shadows slightly different from local VMs
// Add a 0.5% tolerance to account for that
tolerance = ciBuild ? 0.5 : 0
if (shotTest) {
shot {
showOnlyFailingTestsInReports = ciBuild
// CI environment renders some shadows slightly different from local VMs
// Add a 0.5% tolerance to account for that
tolerance = ciBuild ? 0.5 : 0
}
}

jacoco {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FileDisplayActivityIT : AbstractOnServerIT() {
.perform(NavigationViewActions.navigateTo(R.id.nav_shared))
shortSleep()
shortSleep()
screenshot(sut)
// screenshot(sut) // todo run without real server
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import android.app.Application
import android.app.Instrumentation
import android.content.Context
import android.os.Build
import androidx.test.runner.AndroidJUnitRunner
import com.github.tmurakami.dexopener.DexOpener
import com.karumi.shot.ShotTestRunner
import com.nextcloud.test.TestMainApp

class ScreenshotTestRunner : ShotTestRunner() {
class TestRunner : AndroidJUnitRunner() {
@Throws(ClassNotFoundException::class, IllegalAccessException::class, InstantiationException::class)
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.utils.ScreenshotTest;

import org.junit.Rule;
import org.junit.Test;
Expand All @@ -41,6 +42,7 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
false);

@Test
@ScreenshotTest
public void showNotEnoughSpaceDialogForFolder() {
FileDisplayActivity test = activityRule.launchActivity(null);
OCFile ocFile = new OCFile("/Document/");
Expand All @@ -56,6 +58,7 @@ public void showNotEnoughSpaceDialogForFolder() {
}

@Test
@ScreenshotTest
public void showNotEnoughSpaceDialogForFile() {
FileDisplayActivity test = activityRule.launchActivity(null);
OCFile ocFile = new OCFile("/Video.mp4");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ScreenshotTest;

import org.junit.Rule;
import org.junit.Test;
Expand All @@ -41,7 +42,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
false);

@Test
// @ScreenshotTest // todo run without real server
@ScreenshotTest
public void displaySimpleTextFile() throws IOException {
FileDisplayActivity sut = activityRule.launchActivity(null);

Expand All @@ -59,7 +60,7 @@ public void displaySimpleTextFile() throws IOException {
}

@Test
// @ScreenshotTest // todo run without real server
@ScreenshotTest
public void displayJavaSnippetFile() throws IOException {
FileDisplayActivity sut = activityRule.launchActivity(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TrashbinActivityIT : AbstractIT() {
}

@Test
@ScreenshotTest
fun normalUser() {
val sut: TrashbinActivity = activityRule.launchActivity(null)

Expand All @@ -124,6 +125,7 @@ class TrashbinActivityIT : AbstractIT() {
}

@Test
@ScreenshotTest
fun differentUser() {
val temp = Account("differentUser@https://nextcloud.localhost", MainApp.getAccountType(targetContext))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,19 @@ private void setThumbnail(TrashbinFile file, ImageView thumbnailView) {
thumbnailView.setImageBitmap(thumbnail);
}
} else {
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
file.getFileName(),
context,
viewThemeUtils));

// generate new thumbnail
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
try {
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
storageManager,
user,
asyncTasks);
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
storageManager,
user,
asyncTasks);

final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ buildscript {
roomVersion = "2.6.1"

ciBuild = System.getenv("CI") == "true"
shotTest = System.getenv("SHOT_TEST") == "true"
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/androidScreenshotTest
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fi
if [[ $4 = "all" ]]; then
scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
else
./gradlew --offline gplayDebugExecuteScreenshotTests $record \
SHOT_TEST=true ./gradlew --offline gplayDebugExecuteScreenshotTests $record \
-Dorg.gradle.jvmargs="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.nio.channels=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED" \
-Pscreenshot=true \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
Expand Down

0 comments on commit 002f61a

Please sign in to comment.