- screenshot library setup

- pull screenshot after tests
 - update to fastfile to produce bundles instead of .apks

Took 4 hours 17 minutes
This commit is contained in:
2023-06-26 22:40:30 +01:00
parent 18106330c9
commit 2daf11e4d7
11 changed files with 91 additions and 58 deletions

View File

@@ -36,18 +36,18 @@ android {
}
}
// signingConfigs {
// release {
// storePassword relStorePassword
// keyPassword relKeyPassword
// keyAlias relKeyAlias
// storeFile file(relStoreFile)
// }
// }
signingConfigs {
release {
storePassword relStorePassword
keyPassword relKeyPassword
keyAlias relKeyAlias
storeFile file(relStoreFile)
}
}
buildTypes {
release {
// signingConfig signingConfigs.release
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
@@ -162,6 +162,6 @@ dependencies {
def retrofit_version = "2.9.0"
androidTestImplementation "com.squareup.retrofit2:retrofit:$retrofit_version"
androidTestImplementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
/ * Spoon screenshot library */
androidTestImplementation 'com.squareup.spoon:spoon-client:1.1.1'
/ * screenshot library */
androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
}

View File

@@ -11,10 +11,12 @@
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/buttonContainer"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_driver_license" />
app:layout_constraintVertical_bias="0.0"
tools:layout="@layout/fragment_private_hire_license" />
<LinearLayout
android:id="@+id/buttonContainer"

View File

@@ -1,7 +1,6 @@
package h_mal.appttude.com.driver
import android.Manifest
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.R
import android.app.Activity
import android.content.Context
@@ -10,23 +9,15 @@ import android.view.View
import android.view.WindowManager
import androidx.annotation.StringRes
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.*
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.setFailureHandler
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource
import androidx.test.espresso.Root
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.GrantPermissionRule
import h_mal.appttude.com.driver.base.BaseActivity
import h_mal.appttude.com.driver.helpers.BaseViewAction
import h_mal.appttude.com.driver.helpers.SpoonFailureHandler
import h_mal.appttude.com.driver.helpers.SnapshotRule
import org.hamcrest.CoreMatchers
import org.hamcrest.Description
import org.hamcrest.Matcher
@@ -34,7 +25,11 @@ import org.hamcrest.TypeSafeMatcher
import org.hamcrest.core.AllOf
import org.junit.After
import org.junit.Before
import org.junit.ClassRule
import org.junit.Rule
import tools.fastlane.screengrab.Screengrab
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy
import tools.fastlane.screengrab.locale.LocaleTestRule
open class BaseUiTest<T : BaseActivity<*, *>>(
@@ -46,13 +41,19 @@ open class BaseUiTest<T : BaseActivity<*, *>>(
private lateinit var currentActivity: Activity
@JvmField
@get:Rule
var permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
@get:Rule
var snapshotRule: SnapshotRule = SnapshotRule()
@Rule
var permissionWrite = GrantPermissionRule.grant(WRITE_EXTERNAL_STORAGE)
@JvmField
var localeTestRule = LocaleTestRule()
@Before
fun setup() {
setFailureHandler(SpoonFailureHandler(getInstrumentation().targetContext))
Screengrab.setDefaultScreenshotStrategy(UiAutomatorScreenshotStrategy())
beforeLaunch()
mActivityScenarioRule = ActivityScenario.launch(activity)
mActivityScenarioRule.onActivity {

View File

@@ -1,27 +1,23 @@
package h_mal.appttude.com.driver.helpers
import android.app.Activity
import android.content.Context
import android.view.View
import androidx.test.espresso.FailureHandler
import androidx.test.espresso.base.DefaultFailureHandler
import com.squareup.spoon.Spoon
import org.hamcrest.Matcher
import tools.fastlane.screengrab.Screengrab
class SpoonFailureHandler(targetContext: Context) : FailureHandler {
class CustomFailureHandler(targetContext: Context) : FailureHandler {
private val delegate: FailureHandler
private val context: Context
init {
delegate = DefaultFailureHandler(targetContext)
context = targetContext
}
override fun handle(error: Throwable?, viewMatcher: Matcher<View?>?) {
override fun handle(error: Throwable, viewMatcher: Matcher<View>) {
delegate.handle(error, viewMatcher)
if (context is Activity) {
Spoon.screenshot(context, "error")
}
// Catch a screenshot on failure
Screengrab.screenshot("error")
}
}

View File

@@ -0,0 +1,20 @@
package h_mal.appttude.com.driver.helpers
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import tools.fastlane.screengrab.Screengrab
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy
/**
* Junit rule that takes a screenshot when a test fails.
*/
class SnapshotRule : TestWatcher() {
override fun failed(e: Throwable, description: Description) {
// Catch a screenshot on failure
Screengrab.screenshot("FAILURE-" + getScreenshotName(description))
}
fun getScreenshotName(description: Description): String {
return description.className.replace(".", "-") + "_" + description.methodName.replace(".", "-")
}
}

View File

@@ -1,8 +1,18 @@
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allows unlocking your device and activating its screen so UI tests can succeed -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Allows for storing and retrieving screenshots -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true"
tools:ignore="MissingApplicationIcon" />

View File

@@ -9,6 +9,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxWidth="350dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="28dp"
app:cardElevation="0dp"
@@ -18,11 +19,11 @@
<ImageView
android:id="@+id/imageView2"
android:layout_width="200dp"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
tools:src="@drawable/choice_img_round"
tools:src="@drawable/driver_license_private_hire"
android:contentDescription="@string/image_description" />
</androidx.cardview.widget.CardView>
@@ -33,7 +34,8 @@
android:text="@string/upload_private_hire_photo"
app:layout_constraintBottom_toTopOf="@id/til_submission"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
app:layout_constraintRight_toRightOf="parent"
tools:visibility="gone"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_submission"
@@ -48,7 +50,8 @@
style="@style/EditTextStyle"
android:hint="@string/private_hire_license_no"
android:importantForAutofill="no"
tools:ignore="TextFields" />
tools:ignore="TextFields"
tools:text="987651"/>
</com.google.android.material.textfield.TextInputLayout>
@@ -63,7 +66,8 @@
android:id="@+id/ph_expiry"
style="@style/EditTextStyle.Date"
android:hint="@string/private_hire_license_expiry"
android:autofillHints="date" />
android:autofillHints="date"
tools:text="30/12/2018"/>
</com.google.android.material.textfield.TextInputLayout>
@@ -76,6 +80,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/til_submission"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
app:layout_constraintVertical_bias="0.8"
tools:visibility="gone"/>
</androidx.constraintlayout.widget.ConstraintLayout>