Results transmit via interceptor.
This commit is contained in:
@@ -13,6 +13,8 @@ import com.kaspersky.components.composesupport.config.addComposeSupport
|
|||||||
import com.kaspersky.kaspresso.idlewaiting.KautomatorWaitForIdleSettings
|
import com.kaspersky.kaspresso.idlewaiting.KautomatorWaitForIdleSettings
|
||||||
import com.kaspersky.kaspresso.kaspresso.Kaspresso
|
import com.kaspersky.kaspresso.kaspresso.Kaspresso
|
||||||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
|
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
|
||||||
|
import com.kaspersky.kaspresso.testcases.core.sections.AfterTestSection
|
||||||
|
import com.kaspersky.kaspresso.testcases.core.testcontext.BaseTestContext
|
||||||
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext
|
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
@@ -30,6 +32,7 @@ open class BaseTest<LaunchActivity : Activity>(
|
|||||||
) : TestCase(kaspressoBuilder = Kaspresso.Builder.simple {
|
) : TestCase(kaspressoBuilder = Kaspresso.Builder.simple {
|
||||||
kautomatorWaitForIdleSettings = KautomatorWaitForIdleSettings.boost()
|
kautomatorWaitForIdleSettings = KautomatorWaitForIdleSettings.boost()
|
||||||
}.apply {
|
}.apply {
|
||||||
|
testRunWatcherInterceptors.add(ResultTestRunWatcherInterceptor())
|
||||||
if (isEnabledCompose) addComposeSupport()
|
if (isEnabledCompose) addComposeSupport()
|
||||||
}) {
|
}) {
|
||||||
@get:Rule
|
@get:Rule
|
||||||
@@ -84,4 +87,14 @@ open class BaseTest<LaunchActivity : Activity>(
|
|||||||
}
|
}
|
||||||
ResultTestsData.putResult(instrumentation, uiDevice)
|
ResultTestsData.putResult(instrumentation, uiDevice)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun runWithGrade(grade: Int, testName: String, steps: TestContext<Unit>.() -> Unit) {
|
||||||
|
ResultTestsData.testGrade[testName] = grade
|
||||||
|
run(testName, steps)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun beforeWithGrade(grade: Int, testName: String, actions: BaseTestContext.() -> Unit): AfterTestSection<Unit, Unit> {
|
||||||
|
ResultTestsData.testGrade[testName] = grade
|
||||||
|
return before(testName, actions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.samsung.test.core.core
|
||||||
|
|
||||||
|
import com.kaspersky.kaspresso.testcases.core.sections.MainTestSection
|
||||||
|
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext
|
||||||
|
|
||||||
|
fun MainTestSection<Unit, Unit>.runWithInit(grade: Int, steps: TestContext<Unit>.() -> Unit, testName: String) {
|
||||||
|
|
||||||
|
this.run(steps)
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.samsung.test.core.core
|
||||||
|
|
||||||
|
import android.app.Instrumentation
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import com.kaspersky.kaspresso.interceptors.watcher.testcase.TestRunWatcherInterceptor
|
||||||
|
import com.kaspersky.kaspresso.testcases.models.info.TestInfo
|
||||||
|
import ru.samsung.test.core.utils.ResultTestsData
|
||||||
|
|
||||||
|
class ResultTestRunWatcherInterceptor: TestRunWatcherInterceptor {
|
||||||
|
override fun onTestStarted(testInfo: TestInfo) {
|
||||||
|
val grade: Int = ResultTestsData.testGrade[testInfo.testName] ?: 0
|
||||||
|
ResultTestsData.setupTest(grade)
|
||||||
|
super.onTestStarted(testInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMainSectionFinishedSuccess(testInfo: TestInfo) {
|
||||||
|
val grade: Int = ResultTestsData.testGrade[testInfo.testName] ?: 0
|
||||||
|
ResultTestsData.successTest(grade)
|
||||||
|
super.onMainSectionFinishedSuccess(testInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTestFinished(testInfo: TestInfo, success: Boolean) {
|
||||||
|
ResultTestsData.putResult(InstrumentationRegistry.getInstrumentation(), UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()))
|
||||||
|
super.onTestFinished(testInfo, success)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ object ResultTestsData {
|
|||||||
private var totalTests = 0
|
private var totalTests = 0
|
||||||
private var maxGrade = 0
|
private var maxGrade = 0
|
||||||
private var passTests = 0
|
private var passTests = 0
|
||||||
|
val testGrade: MutableMap<String, Int> = mutableMapOf()
|
||||||
|
|
||||||
fun setupTest(grade: Int) {
|
fun setupTest(grade: Int) {
|
||||||
totalTests++
|
totalTests++
|
||||||
|
|||||||
Reference in New Issue
Block a user