Skip to content

Commit

Permalink
refactored screenshot generation for tablet to not depend on abandonn…
Browse files Browse the repository at this point in the history
…ed Gradle plugin
  • Loading branch information
mtotschnig committed Jun 23, 2023
1 parent 9a9303f commit 5b616a8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Screengrabfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ use_adb_root(true)
clear_previous_screenshots(false)

use_timestamp_suffix(false)

launch_arguments(["scenario 2"])
10 changes: 0 additions & 10 deletions myExpenses/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.novoda.gradle.command.Files

buildscript {
repositories {
// mavenLocal()
Expand All @@ -8,7 +6,6 @@ buildscript {
}
dependencies {
// classpath 'com.jakewharton.hugo:hugo-plugin:1.2.2-SNAPSHOT'
classpath 'com.novoda:gradle-android-command-plugin:2.0.1'
}
}

Expand Down Expand Up @@ -339,13 +336,6 @@ static def getDate() {
}

//apply plugin: 'com.jakewharton.hugo'
apply plugin: 'com.novoda.android-command'

tasks.register('copyFileForFixture', Files) {
script {
push "tests/script/screenshot.jpg", "/sdcard/Android/data/org.totschnig.myexpenses.fortest/files/screenshot.jpg"
}
}

//For Drive
//apply plugin: 'com.google.gms.google-services'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
package org.totschnig.myexpenses.test.screenshots

import android.Manifest
import android.content.Intent
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.*
import androidx.core.os.LocaleListCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.*
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onIdle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.contrib.DrawerActions
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.instanceOf
import org.junit.After
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import org.junit.*
import org.totschnig.myexpenses.BuildConfig
import org.totschnig.myexpenses.R
import org.totschnig.myexpenses.activity.TestMyExpenses
import org.totschnig.myexpenses.preference.PrefKey
import org.totschnig.myexpenses.testutils.BaseMyExpensesTest
import org.totschnig.myexpenses.testutils.MockLicenceHandler
Expand All @@ -41,6 +37,7 @@ import tools.fastlane.screengrab.cleanstatusbar.CleanStatusBar
import tools.fastlane.screengrab.locale.LocaleTestRule
import tools.fastlane.screengrab.locale.LocaleUtil


/**
* This test is meant to be run with FastLane Screengrab, but also works on its own.
*/
Expand All @@ -57,8 +54,9 @@ class TestMain : BaseMyExpensesTest() {

@Test
fun mkScreenShots() {
loadFixture(BuildConfig.TEST_SCENARIO == 2)
scenario()
val scenario = InstrumentationRegistry.getArguments().getString("scenario", "1")
loadFixture(scenario == "2")
scenario(scenario)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList())
}

Expand All @@ -70,10 +68,9 @@ class TestMain : BaseMyExpensesTest() {
}
}

private fun scenario() {
Thread.sleep(500)
when (BuildConfig.TEST_SCENARIO) {
1 -> {
private fun scenario(scenario: String) {
when (scenario) {
"1" -> {
drawerAction(DrawerActions.open())
takeScreenshot("summarize")
drawerAction(DrawerActions.close())
Expand Down Expand Up @@ -133,21 +130,17 @@ class TestMain : BaseMyExpensesTest() {
Thread.sleep(5000)
takeScreenshot("sync")
}
2 -> {
"2" -> {
//tablet screenshots
takeScreenshot("main")
clickMenuItem(R.id.DISTRIBUTION_COMMAND)
takeScreenshot("distribution")
pressBack()
onView(
org.totschnig.myexpenses.testutils.Matchers.first(
withText(
containsString(testContext.getString(org.totschnig.myexpenses.test.R.string.testData_transaction1SubCat))
)
)
).perform(click())
onView(withId(android.R.id.button1))
.perform(click())
listNode.onChildren()
.filter(hasText(testContext.getString(org.totschnig.myexpenses.test.R.string.testData_transaction1SubCat), substring = true))
.onFirst()
.performClick()
composeTestRule.onNodeWithText(getString(R.string.menu_edit)).performClick()
pressBack() //close keyboard
onView(withId(R.id.PictureContainer))
.perform(click())
Expand All @@ -167,8 +160,7 @@ class TestMain : BaseMyExpensesTest() {
prefHandler.putLong(PrefKey.CURRENT_ACCOUNT, app.fixture.account1.id)
prefHandler.putInt(PrefKey.CURRENT_VERSION, versionNumber)
prefHandler.putInt(PrefKey.FIRST_INSTALL_VERSION, versionNumber)
val startIntent = Intent(app, TestMyExpenses::class.java)
testScenario = ActivityScenario.launch(startIntent)
launch()
}

private fun takeScreenshot(fileName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ class Fixture(inst: Instrumentation) {
.date(offset - 300000)
if (withPicture) {
builder.pictureUri(
Uri.fromFile(
File(
appContext.getExternalFilesDir(null),
"screenshot.jpg"
)
)
Uri.parse("file:///android_asset/screenshot.jpg")
)
}
builder.persist()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ abstract class TransactionDelegate<T : ITransaction>(
@Inject
lateinit var homeCurrencyProvider: HomeCurrencyProvider

@Inject
lateinit var picasso: Picasso

val homeCurrency by lazy {
homeCurrencyProvider.homeCurrencyUnit
}
Expand Down Expand Up @@ -1019,7 +1022,7 @@ abstract class TransactionDelegate<T : ITransaction>(
private fun configurePicture() {
if (pictureUri != null) {
viewBinding.PictureContainer.root.visibility = View.VISIBLE
Picasso.get().load(pictureUri).fit().into(viewBinding.PictureContainer.picture)
picasso.load(pictureUri).fit().into(viewBinding.PictureContainer.picture)
viewBinding.AttachImage.visibility = View.GONE
} else {
viewBinding.AttachImage.visibility = View.VISIBLE
Expand Down
Binary file removed tests/script/screenshot.jpg
Binary file not shown.

0 comments on commit 5b616a8

Please sign in to comment.