mirror of
https://github.com/hmalik144/Driver.git
synced 2026-03-18 07:26:03 +00:00
- 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:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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(".", "-")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user