mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Fix FailshotRule
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
package com.yandex.div.rule
|
||||
|
||||
import com.yandex.test.rules.ClosePopupsRule
|
||||
import com.yandex.test.rules.FailshotRule
|
||||
import com.yandex.test.rules.LogcatReportRule
|
||||
import com.yandex.test.rules.NoAnimationsRule
|
||||
import com.yandex.test.rules.WindowHierarchyRule
|
||||
import com.yandex.test.util.chain
|
||||
import org.junit.rules.TestRule
|
||||
import ru.tinkoff.allure.android.FailshotRule
|
||||
|
||||
fun uiTestRule(innerRule: () -> TestRule): TestRule {
|
||||
return LogcatReportRule()
|
||||
|
||||
@@ -5,13 +5,13 @@ package com.yandex.div.rule
|
||||
import com.yandex.divkit.demo.Container
|
||||
import com.yandex.test.idling.waitForIdlingResource
|
||||
import com.yandex.test.rules.ClosePopupsRule
|
||||
import com.yandex.test.rules.FailshotRule
|
||||
import com.yandex.test.rules.LogcatReportRule
|
||||
import com.yandex.test.rules.NoAnimationsRule
|
||||
import com.yandex.test.rules.WindowHierarchyRule
|
||||
import com.yandex.test.screenshot.ScreenshotRule
|
||||
import com.yandex.test.util.chain
|
||||
import org.junit.rules.TestRule
|
||||
import ru.tinkoff.allure.android.FailshotRule
|
||||
|
||||
fun screenshotRule(
|
||||
relativePath: String = "",
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yandex.test.rules
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import ru.tinkoff.allure.android.AllureAndroidLifecycle
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
private const val FILE_NAME = "failshot"
|
||||
private const val FILE_TYPE = "image/png"
|
||||
private const val FILE_EXTENSION = ".png"
|
||||
|
||||
class FailshotRule : TestRule {
|
||||
|
||||
private val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
|
||||
private val cacheDir get() = instrumentation.targetContext.cacheDir
|
||||
|
||||
private val uiDevice get() = UiDevice.getInstance(instrumentation)
|
||||
|
||||
override fun apply(base: Statement, description: Description) = object : Statement() {
|
||||
override fun evaluate() {
|
||||
runCatching {
|
||||
base.evaluate()
|
||||
}.onFailure { error ->
|
||||
failshot()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun failshot() {
|
||||
val file = File.createTempFile(FILE_NAME, FILE_TYPE, cacheDir)
|
||||
uiDevice.waitForIdle(TimeUnit.SECONDS.toMillis(5L))
|
||||
uiDevice.takeScreenshot(file)
|
||||
AllureAndroidLifecycle.addAttachment(FILE_NAME, FILE_TYPE, FILE_EXTENSION, file)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user