|
| 1 | +package com.orgzly.android.espresso |
| 2 | + |
| 3 | +import androidx.test.core.app.ActivityScenario |
| 4 | +import androidx.test.espresso.Espresso.onView |
| 5 | +import androidx.test.espresso.action.ViewActions.click |
| 6 | +import androidx.test.espresso.assertion.ViewAssertions.matches |
| 7 | +import androidx.test.espresso.contrib.DrawerActions.open |
| 8 | +import androidx.test.espresso.matcher.ViewMatchers.* |
| 9 | +import androidx.test.platform.app.InstrumentationRegistry |
| 10 | +import androidx.test.uiautomator.UiDevice |
| 11 | +import com.orgzly.R |
| 12 | +import com.orgzly.android.OrgzlyTest |
| 13 | +import com.orgzly.android.espresso.EspressoUtils.* |
| 14 | +import com.orgzly.android.prefs.AppPreferences |
| 15 | +import com.orgzly.android.ui.main.MainActivity |
| 16 | +import com.orgzly.android.ui.settings.SettingsActivity |
| 17 | +import org.hamcrest.CoreMatchers.allOf |
| 18 | +import org.junit.Before |
| 19 | +import org.junit.BeforeClass |
| 20 | +import org.junit.Ignore |
| 21 | +import org.junit.Test |
| 22 | +import java.io.File |
| 23 | + |
| 24 | +@Ignore("Not a test") |
| 25 | +class ScreenshotsTakingNotATest : OrgzlyTest() { |
| 26 | + |
| 27 | + companion object { |
| 28 | + private const val SCREENSHOTS_DIRECTORY = "/sdcard/Download/screenshots" |
| 29 | + |
| 30 | + @BeforeClass |
| 31 | + @JvmStatic |
| 32 | + fun beforeClass() { |
| 33 | + File(SCREENSHOTS_DIRECTORY).run { |
| 34 | + if (exists()) { |
| 35 | + if (!deleteRecursively()) { |
| 36 | + throw Exception("Failed to delete $SCREENSHOTS_DIRECTORY") |
| 37 | + } |
| 38 | + } |
| 39 | + if (!mkdirs()) { |
| 40 | + throw Exception("Failed to create $SCREENSHOTS_DIRECTORY") |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @Before |
| 47 | + @Throws(Exception::class) |
| 48 | + override fun setUp() { |
| 49 | + super.setUp() |
| 50 | + |
| 51 | + dataRepository.importGettingStartedBook() |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + fun main() { |
| 56 | + ActivityScenario.launch(MainActivity::class.java) |
| 57 | + onView(withId(R.id.main_content)).check(matches(isDisplayed())) |
| 58 | + |
| 59 | + takeScreenshot("books.png") |
| 60 | + |
| 61 | + onView(withId(R.id.drawer_layout)).perform(open()) |
| 62 | + |
| 63 | + takeScreenshot("navigation-drawer.png") |
| 64 | + |
| 65 | + onView(allOf(isDescendantOfA(withId(R.id.drawer_navigation_view)), withText(R.string.getting_started_notebook_name))) |
| 66 | + .perform(click()) |
| 67 | + |
| 68 | + // Open quick-menu |
| 69 | + // Not working |
| 70 | + // onNoteInBook(4).perform(swipeRight()) |
| 71 | + |
| 72 | + takeScreenshot("book.png") |
| 73 | + |
| 74 | + onNoteInBook(11).perform(click()) |
| 75 | + |
| 76 | + takeScreenshot("note.png") |
| 77 | + |
| 78 | + onView(withId(R.id.drawer_layout)).perform(open()) |
| 79 | + onView(withText(R.string.searches)).perform(click()) |
| 80 | + |
| 81 | + takeScreenshot("saved-searches.png") |
| 82 | + |
| 83 | + onView(withId(R.id.drawer_layout)).perform(open()) |
| 84 | + |
| 85 | + onView(allOf(isDescendantOfA(withId(R.id.drawer_navigation_view)), withText(R.string.agenda))) |
| 86 | + .perform(click()) |
| 87 | + |
| 88 | + takeScreenshot("agenda.png") |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + fun mainDark() { |
| 93 | + AppPreferences.colorScheme(context, context.getString(R.string.pref_value_color_scheme_dark)) |
| 94 | + ActivityScenario.launch(MainActivity::class.java) |
| 95 | + onView(withId(R.id.main_content)).check(matches(isDisplayed())) |
| 96 | + |
| 97 | + onBook(0).perform(click()) |
| 98 | + onView(withId(R.id.drawer_layout)).perform(open()) |
| 99 | + |
| 100 | + takeScreenshot("navigation-drawer-dark.png") |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + fun settings() { |
| 105 | + ActivityScenario.launch(SettingsActivity::class.java) |
| 106 | + onView(withId(R.id.main_content)).check(matches(isDisplayed())) |
| 107 | + |
| 108 | + clickSetting("", R.string.sync) |
| 109 | + clickSetting("", R.string.repositories) |
| 110 | + |
| 111 | + takeScreenshot("repositories.png") |
| 112 | + } |
| 113 | + |
| 114 | + private fun takeScreenshot(name: String) { |
| 115 | + val screenshotFile = File(SCREENSHOTS_DIRECTORY, name) |
| 116 | + |
| 117 | + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).run { |
| 118 | + if (!takeScreenshot(screenshotFile, 1.0f, 100)) { |
| 119 | + throw Exception("Failed to create screenshot $name") |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments