ScreenshotsIT.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.owncloud.android;
  2. import android.Manifest;
  3. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  4. import com.owncloud.android.operations.CreateFolderOperation;
  5. import com.owncloud.android.operations.common.SyncOperation;
  6. import com.owncloud.android.ui.activity.FileDisplayActivity;
  7. import com.owncloud.android.ui.activity.SettingsActivity;
  8. import org.junit.Assert;
  9. import org.junit.BeforeClass;
  10. import org.junit.ClassRule;
  11. import org.junit.Rule;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import org.junit.runners.JUnit4;
  15. import androidx.test.core.app.ActivityScenario;
  16. import androidx.test.espresso.action.ViewActions;
  17. import androidx.test.espresso.contrib.DrawerActions;
  18. import androidx.test.espresso.contrib.RecyclerViewActions;
  19. import androidx.test.espresso.matcher.PreferenceMatchers;
  20. import androidx.test.filters.LargeTest;
  21. import androidx.test.rule.GrantPermissionRule;
  22. import tools.fastlane.screengrab.Screengrab;
  23. import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
  24. import tools.fastlane.screengrab.locale.LocaleTestRule;
  25. import static androidx.test.espresso.Espresso.onData;
  26. import static androidx.test.espresso.Espresso.onView;
  27. import static androidx.test.espresso.action.ViewActions.click;
  28. import static androidx.test.espresso.action.ViewActions.swipeUp;
  29. import static androidx.test.espresso.matcher.ViewMatchers.withId;
  30. import static androidx.test.espresso.matcher.ViewMatchers.withText;
  31. import static org.hamcrest.core.AnyOf.anyOf;
  32. import static org.junit.Assert.assertTrue;
  33. @LargeTest
  34. @RunWith(JUnit4.class)
  35. public class ScreenshotsIT extends AbstractIT {
  36. @ClassRule
  37. public static final LocaleTestRule localeTestRule = new LocaleTestRule();
  38. @Rule
  39. public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
  40. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  41. @BeforeClass
  42. public static void beforeScreenshot() {
  43. Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
  44. }
  45. @Test
  46. public void gridViewScreenshot() {
  47. ActivityScenario.launch(FileDisplayActivity.class);
  48. onView(anyOf(withText(R.string.action_switch_grid_view), withId(R.id.switch_grid_view_button))).perform(click());
  49. shortSleep();
  50. Screengrab.screenshot("01_gridView");
  51. onView(anyOf(withText(R.string.action_switch_list_view), withId(R.id.switch_grid_view_button))).perform(click());
  52. Assert.assertTrue(true); // if we reach this, everything is ok
  53. }
  54. @Test
  55. public void listViewScreenshot() {
  56. String path = "/Camera/";
  57. // folder does not exist yet
  58. if (getStorageManager().getFileByPath(path) == null) {
  59. SyncOperation syncOp = new CreateFolderOperation(path, account, targetContext);
  60. RemoteOperationResult result = syncOp.execute(client, getStorageManager());
  61. assertTrue(result.isSuccess());
  62. }
  63. ActivityScenario.launch(FileDisplayActivity.class);
  64. // go into work folder
  65. onView(withId(R.id.list_root)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
  66. Screengrab.screenshot("02_listView");
  67. Assert.assertTrue(true); // if we reach this, everything is ok
  68. }
  69. @Test
  70. public void drawerScreenshot() {
  71. ActivityScenario.launch(FileDisplayActivity.class);
  72. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  73. Screengrab.screenshot("03_drawer");
  74. onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());
  75. Assert.assertTrue(true); // if we reach this, everything is ok
  76. }
  77. @Test
  78. public void multipleAccountsScreenshot() {
  79. ActivityScenario.launch(FileDisplayActivity.class);
  80. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  81. onView(withId(R.id.drawer_active_user)).perform(click());
  82. Screengrab.screenshot("04_accounts");
  83. onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());
  84. Assert.assertTrue(true); // if we reach this, everything is ok
  85. }
  86. @Test
  87. public void autoUploadScreenshot() {
  88. ActivityScenario.launch(FileDisplayActivity.class);
  89. onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
  90. onView(withId(R.id.nav_view)).perform(swipeUp());
  91. onView(anyOf(withText(R.string.drawer_synced_folders), withId(R.id.nav_synced_folders))).perform(click());
  92. Screengrab.screenshot("05_autoUpload");
  93. Assert.assertTrue(true); // if we reach this, everything is ok
  94. }
  95. @Test
  96. public void davdroidScreenshot() {
  97. ActivityScenario.launch(SettingsActivity.class);
  98. onData(PreferenceMatchers.withTitle(R.string.prefs_category_more)).perform(ViewActions.scrollTo());
  99. shortSleep();
  100. Screengrab.screenshot("06_davdroid");
  101. Assert.assertTrue(true); // if we reach this, everything is ok
  102. }
  103. }