diff --git a/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java b/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java index 0b32f30889..10863285f8 100644 --- a/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java +++ b/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.java @@ -71,10 +71,10 @@ public class FileDisplayActivityIT extends AbstractIT { Manifest.permission.WRITE_EXTERNAL_STORAGE); @Test - public void open() throws InterruptedException { + public void open() { Activity sut = activityRule.launchActivity(null); - Thread.sleep(3000); + shortSleep(); Screenshot.snapActivity(sut).record(); } @@ -162,7 +162,7 @@ public class FileDisplayActivityIT extends AbstractIT { } @Test - public void allFiles() throws InterruptedException { + public void allFiles() { // ActivityScenario sut = ActivityScenario.launch(FileDisplayActivity.class); FileDisplayActivity sut = activityRule.launchActivity(null); @@ -184,7 +184,7 @@ public class FileDisplayActivityIT extends AbstractIT { .perform(NavigationViewActions.navigateTo(R.id.nav_all_files)); // then should be in root again - Thread.sleep(2000); + shortSleep(); assertEquals(getStorageManager().getFileByPath("/"), sut.getCurrentDir()); } } diff --git a/src/androidTest/java/com/owncloud/android/AbstractIT.java b/src/androidTest/java/com/owncloud/android/AbstractIT.java index 75fea91b5e..cc2a550691 100644 --- a/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -192,7 +192,7 @@ public abstract class AbstractIT { protected void openDrawer(IntentsTestRule activityRule) throws InterruptedException { Activity sut = activityRule.launchActivity(null); - Thread.sleep(3000); + shortSleep(); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); @@ -214,4 +214,20 @@ public abstract class AbstractIT { return currentActivity; } + + protected void shortSleep() { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected void longSleep() { + try { + Thread.sleep(20000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } diff --git a/src/androidTest/java/com/owncloud/android/ScreenshotsIT.java b/src/androidTest/java/com/owncloud/android/ScreenshotsIT.java index 53d61c032a..c4f8cf4713 100644 --- a/src/androidTest/java/com/owncloud/android/ScreenshotsIT.java +++ b/src/androidTest/java/com/owncloud/android/ScreenshotsIT.java @@ -60,7 +60,7 @@ public class ScreenshotsIT extends AbstractIT { openOverflowMenu(); onView(anyOf(withText(R.string.action_switch_grid_view), withId(R.id.action_switch_view))).perform(click()); - Thread.sleep(1000); + shortSleep(); Screengrab.screenshot("01_gridView"); @@ -70,12 +70,12 @@ public class ScreenshotsIT extends AbstractIT { Assert.assertTrue(true); // if we reach this, everything is ok } - private void openOverflowMenu() throws InterruptedException { + private void openOverflowMenu() { try { Espresso.openContextualActionModeOverflowMenu(); } catch (NoActivityResumedException e) { ActivityScenario.launch(FileDisplayActivity.class); - Thread.sleep(1000); + shortSleep(); Espresso.openContextualActionModeOverflowMenu(); } } @@ -143,12 +143,12 @@ public class ScreenshotsIT extends AbstractIT { } @Test - public void davdroidScreenshot() throws InterruptedException { + public void davdroidScreenshot() { ActivityScenario.launch(SettingsActivity.class); onData(PreferenceMatchers.withTitle(R.string.prefs_category_more)).perform(ViewActions.scrollTo()); - Thread.sleep(1000); + shortSleep(); Screengrab.screenshot("06_davdroid"); diff --git a/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt b/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt index 724390f37c..8a38892a16 100644 --- a/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt +++ b/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt @@ -42,9 +42,6 @@ import org.junit.Test import java.io.File class FileUploaderIT : AbstractIT() { - val SHORT_WAIT: Long = 5000 - val LONG_WAIT: Long = 20000 - var uploadsStorageManager: UploadsStorageManager? = null val connectivityServiceMock: ConnectivityService = object : ConnectivityService { @@ -149,7 +146,7 @@ class FileUploaderIT : AbstractIT() { false, FileUploader.NameCollisionPolicy.DEFAULT) - Thread.sleep(LONG_WAIT) + longSleep() val result = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result.isSuccess) @@ -166,7 +163,7 @@ class FileUploaderIT : AbstractIT() { FileUploader.LOCAL_BEHAVIOUR_COPY, FileUploader.NameCollisionPolicy.OVERWRITE) - Thread.sleep(SHORT_WAIT) + shortSleep() val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result2.isSuccess) @@ -256,7 +253,7 @@ class FileUploaderIT : AbstractIT() { false, FileUploader.NameCollisionPolicy.DEFAULT) - Thread.sleep(LONG_WAIT) + longSleep() val result = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result.isSuccess) @@ -273,7 +270,7 @@ class FileUploaderIT : AbstractIT() { FileUploader.LOCAL_BEHAVIOUR_COPY, FileUploader.NameCollisionPolicy.RENAME) - Thread.sleep(SHORT_WAIT) + shortSleep() val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result2.isSuccess) @@ -356,7 +353,7 @@ class FileUploaderIT : AbstractIT() { false, FileUploader.NameCollisionPolicy.DEFAULT) - Thread.sleep(LONG_WAIT) + longSleep() val result = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result.isSuccess) @@ -373,7 +370,7 @@ class FileUploaderIT : AbstractIT() { FileUploader.LOCAL_BEHAVIOUR_COPY, FileUploader.NameCollisionPolicy.CANCEL) - Thread.sleep(SHORT_WAIT) + shortSleep() val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client) assertTrue(result2.isSuccess) diff --git a/src/androidTest/java/com/owncloud/android/ui/activity/ConflictsResolveActivityIT.java b/src/androidTest/java/com/owncloud/android/ui/activity/ConflictsResolveActivityIT.java index bfe237f031..8dc32f8faf 100644 --- a/src/androidTest/java/com/owncloud/android/ui/activity/ConflictsResolveActivityIT.java +++ b/src/androidTest/java/com/owncloud/android/ui/activity/ConflictsResolveActivityIT.java @@ -59,7 +59,7 @@ public class ConflictsResolveActivityIT extends AbstractIT { private boolean returnCode; @Test - public void screenshotTextFiles() throws InterruptedException { + public void screenshotTextFiles() { OCFile newFile = new OCFile("/newFile.txt"); newFile.setFileLength(56000); newFile.setModificationTimestamp(1522019340); @@ -88,13 +88,13 @@ public class ConflictsResolveActivityIT extends AbstractIT { getInstrumentation().waitForIdleSync(); - Thread.sleep(2000); + shortSleep(); Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record(); } @Test - public void screenshotImages() throws InterruptedException, IOException { + public void screenshotImages() throws IOException { FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); @@ -141,13 +141,13 @@ public class ConflictsResolveActivityIT extends AbstractIT { dialog.listener = listener; getInstrumentation().waitForIdleSync(); - Thread.sleep(2000); + shortSleep(); Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record(); } @Test - public void cancel() throws InterruptedException { + public void cancel() { returnCode = false; OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt", @@ -179,7 +179,7 @@ public class ConflictsResolveActivityIT extends AbstractIT { }; getInstrumentation().waitForIdleSync(); - Thread.sleep(2000); + shortSleep(); onView(withText("Cancel")).perform(click()); diff --git a/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java b/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java index e0de88c845..58aa429de8 100644 --- a/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java +++ b/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java @@ -40,22 +40,22 @@ public class ManageAccountsActivityIT extends AbstractIT { false); @Test - public void open() throws InterruptedException { + public void open() { Activity sut = activityRule.launchActivity(null); - Thread.sleep(2000); + shortSleep(); Screenshot.snapActivity(sut).record(); } @Test - public void userInfoDetail() throws InterruptedException { + public void userInfoDetail() { ManageAccountsActivity sut = activityRule.launchActivity(null); User user = sut.accountManager.getUser(); sut.onClick(user); - Thread.sleep(2000); + shortSleep(); Screenshot.snapActivity(getCurrentActivity()).record(); } diff --git a/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentIT.kt b/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentIT.kt index c572f449e0..2e4750ff9f 100644 --- a/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentIT.kt +++ b/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentIT.kt @@ -55,6 +55,11 @@ import org.junit.Rule import org.junit.Test class OCFileListFragmentIT : AbstractIT() { + companion object { + val SECOND_IN_MILLIS = 1000L + val RESULT_PER_PAGE = 50 + } + @get:Rule val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, false) @@ -112,7 +117,7 @@ class OCFileListFragmentIT : AbstractIT() { assertTrue(newUpload.execute(client, storageManager).isSuccess) assertTrue(RefreshFolderOperation(storageManager.getFileByPath("/test/"), - System.currentTimeMillis() / 1000, + System.currentTimeMillis() / SECOND_IN_MILLIS, false, true, storageManager, @@ -122,7 +127,7 @@ class OCFileListFragmentIT : AbstractIT() { val sut = ActivityScenario.launch(FileDisplayActivity::class.java) sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) } - Thread.sleep(2000) + shortSleep() sut.onActivity { activity -> Screenshot.snapActivity(activity).setName("richworkspaces_light").record() @@ -138,7 +143,7 @@ class OCFileListFragmentIT : AbstractIT() { sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) } - Thread.sleep(2000) + shortSleep() sut.onActivity { activity -> Screenshot.snapActivity(activity).setName("richworkspaces_dark").record() @@ -170,7 +175,7 @@ class OCFileListFragmentIT : AbstractIT() { val sut: FileDisplayActivity = activityRule.launchActivity(null) sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true) - Thread.sleep(2000) + shortSleep() InstrumentationRegistry.getInstrumentation().waitForIdleSync() Screenshot.snapActivity(sut).record() } @@ -192,7 +197,7 @@ class OCFileListFragmentIT : AbstractIT() { val sut: FileDisplayActivity = activityRule.launchActivity(null) sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true) - Thread.sleep(2000) + shortSleep() InstrumentationRegistry.getInstrumentation().waitForIdleSync() Screenshot.snapActivity(sut).record() } @@ -204,7 +209,7 @@ class OCFileListFragmentIT : AbstractIT() { // share folder to circle // get circleId - val searchResult = GetShareesRemoteOperation("publicCircle", 1, 50).execute(client) + val searchResult = GetShareesRemoteOperation("publicCircle", 1, RESULT_PER_PAGE).execute(client) assertTrue(searchResult.logMessage, searchResult.isSuccess) val resultJson: JSONObject = searchResult.data[0] as JSONObject @@ -221,7 +226,7 @@ class OCFileListFragmentIT : AbstractIT() { val sut: FileDisplayActivity = activityRule.launchActivity(null) sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true) - Thread.sleep(2000) + shortSleep() InstrumentationRegistry.getInstrumentation().waitForIdleSync() Screenshot.snapActivity(sut).record() } @@ -243,7 +248,7 @@ class OCFileListFragmentIT : AbstractIT() { val sut: FileDisplayActivity = activityRule.launchActivity(null) sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true) - Thread.sleep(2000) + shortSleep() InstrumentationRegistry.getInstrumentation().waitForIdleSync() Screenshot.snapActivity(sut).record() } diff --git a/src/androidTest/java/com/owncloud/android/ui/preview/PreviewTextFileFragmentTest.java b/src/androidTest/java/com/owncloud/android/ui/preview/PreviewTextFileFragmentTest.java index ad7f04bce4..0c64a98941 100644 --- a/src/androidTest/java/com/owncloud/android/ui/preview/PreviewTextFileFragmentTest.java +++ b/src/androidTest/java/com/owncloud/android/ui/preview/PreviewTextFileFragmentTest.java @@ -53,7 +53,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT { public void displaySimpleTextFile() throws InterruptedException { FileDisplayActivity sut = activityRule.launchActivity(null); - Thread.sleep(3000); + shortSleep(); File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); OCFile test = new OCFile("/text.md"); @@ -61,7 +61,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT { test.setStoragePath(file.getAbsolutePath()); sut.startTextPreview(test, false); - Thread.sleep(3000); + shortSleep(); Screenshot.snapActivity(sut).record(); } @@ -70,7 +70,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT { public void displayJavaSnippetFile() throws IOException, InterruptedException { FileDisplayActivity sut = activityRule.launchActivity(null); - Thread.sleep(3000); + shortSleep(); File file = getFile("java.md"); OCFile test = new OCFile("/java.md"); @@ -78,7 +78,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT { test.setStoragePath(file.getAbsolutePath()); sut.startTextPreview(test, false); - Thread.sleep(3000); + shortSleep(); Screenshot.snapActivity(sut).record(); }