From 3800cd52ff543d7046d4950629632469c653cc4c Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 8 Jul 2024 12:26:37 +0200 Subject: [PATCH] catch exception Signed-off-by: alperozturk --- .../client/FileDisplayActivityScreenshotIT.kt | 111 ++++++++++-------- 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityScreenshotIT.kt b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityScreenshotIT.kt index 08b5386299..df56b9588c 100644 --- a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityScreenshotIT.kt +++ b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityScreenshotIT.kt @@ -16,6 +16,7 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.rule.GrantPermissionRule import com.owncloud.android.AbstractIT import com.owncloud.android.R +import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.ui.activity.FileDisplayActivity import com.owncloud.android.utils.ScreenshotTest import org.junit.Assert @@ -31,77 +32,93 @@ class FileDisplayActivityScreenshotIT : AbstractIT() { ) @get:Rule - val permissionRule = GrantPermissionRule.grant( + val permissionRule: GrantPermissionRule = GrantPermissionRule.grant( Manifest.permission.WRITE_EXTERNAL_STORAGE ) + companion object { + private const val TAG = "FileDisplayActivityScreenshotIT" + } + @Test @ScreenshotTest fun open() { - val sut = activityRule.launchActivity(null) + try { + val sut = activityRule.launchActivity(null) - shortSleep() - sut.runOnUiThread { - sut.listOfFilesFragment!!.setFabEnabled(false) - sut.resetScrolling(true) - sut.listOfFilesFragment!!.setEmptyListLoadingMessage() - sut.listOfFilesFragment!!.isLoading = false + shortSleep() + sut.runOnUiThread { + sut.listOfFilesFragment!!.setFabEnabled(false) + sut.resetScrolling(true) + sut.listOfFilesFragment!!.setEmptyListLoadingMessage() + sut.listOfFilesFragment!!.isLoading = false + } + shortSleep() + waitForIdleSync() + screenshot(sut) + } catch (e: SecurityException) { + Log_OC.e(TAG, "Error caught at open $e") } - shortSleep() - waitForIdleSync() - screenshot(sut) } @Test @ScreenshotTest fun showMediaThenAllFiles() { - val fileDisplayActivity = activityRule.launchActivity(null) - val sut = fileDisplayActivity.listOfFilesFragment - Assert.assertNotNull(sut) - sut!!.setFabEnabled(false) - sut.setEmptyListLoadingMessage() - sut.isLoading = false + try { + val fileDisplayActivity = activityRule.launchActivity(null) + val sut = fileDisplayActivity.listOfFilesFragment + Assert.assertNotNull(sut) + sut!!.setFabEnabled(false) + sut.setEmptyListLoadingMessage() + sut.isLoading = false - // open drawer - Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) + // open drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) - // click "all files" - Espresso.onView(ViewMatchers.withId(R.id.nav_view)) - .perform(NavigationViewActions.navigateTo(R.id.nav_gallery)) + // click "all files" + Espresso.onView(ViewMatchers.withId(R.id.nav_view)) + .perform(NavigationViewActions.navigateTo(R.id.nav_gallery)) - // wait - shortSleep() + // wait + shortSleep() - // click "all files" - Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) - Espresso.onView(ViewMatchers.withId(R.id.nav_view)) - .perform(NavigationViewActions.navigateTo(R.id.nav_all_files)) + // click "all files" + Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) + Espresso.onView(ViewMatchers.withId(R.id.nav_view)) + .perform(NavigationViewActions.navigateTo(R.id.nav_all_files)) - // then compare screenshot - shortSleep() - sut.setFabEnabled(false) - sut.setEmptyListLoadingMessage() - sut.isLoading = false - shortSleep() - screenshot(fileDisplayActivity) + // then compare screenshot + shortSleep() + sut.setFabEnabled(false) + sut.setEmptyListLoadingMessage() + sut.isLoading = false + shortSleep() + screenshot(fileDisplayActivity) + } catch (e: SecurityException) { + Log_OC.e(TAG, "Error caught at open $e") + } } @Test @ScreenshotTest fun drawer() { - val sut = activityRule.launchActivity(null) - Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) + try { + val sut = activityRule.launchActivity(null) + Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) - shortSleep() - sut.runOnUiThread { - sut.hideInfoBox() - sut.resetScrolling(true) - sut.listOfFilesFragment!!.setFabEnabled(false) - sut.listOfFilesFragment!!.setEmptyListLoadingMessage() - sut.listOfFilesFragment!!.isLoading = false + shortSleep() + sut.runOnUiThread { + sut.hideInfoBox() + sut.resetScrolling(true) + sut.listOfFilesFragment!!.setFabEnabled(false) + sut.listOfFilesFragment!!.setEmptyListLoadingMessage() + sut.listOfFilesFragment!!.isLoading = false + } + shortSleep() + waitForIdleSync() + screenshot(sut) + } catch (e: SecurityException) { + Log_OC.e(TAG, "Error caught at open $e") } - shortSleep() - waitForIdleSync() - screenshot(sut) } }