Skip to content

Commit

Permalink
Merge pull request #569 from KasperskyLab/ISSUE-561-interceptors
Browse files Browse the repository at this point in the history
ISSUE-561: setup Kakao and Kautomator settings before each test
  • Loading branch information
sumin93 authored Sep 6, 2023
2 parents 9c6abc3 + 0de3d73 commit e8e8b5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.test.espresso.FailureHandler
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.Configurator
import com.kaspersky.adbserver.common.log.logger.LogLevel
import com.kaspersky.components.kautomator.KautomatorConfigurator
import com.kaspersky.components.kautomator.intercept.interaction.UiDeviceInteraction
import com.kaspersky.components.kautomator.intercept.interaction.UiObjectInteraction
import com.kaspersky.kaspresso.device.Device
Expand Down Expand Up @@ -1001,29 +1002,36 @@ data class Kaspresso(
configurator.waitForIdleTimeout = kautomatorWaitForIdleSettings.waitForIdleTimeout
configurator.waitForSelectorTimeout = kautomatorWaitForIdleSettings.waitForSelectorTimeout

injectKaspressoInKakao(
kaspresso.viewBehaviorInterceptors,
kaspresso.dataBehaviorInterceptors,
kaspresso.webBehaviorInterceptors,
kaspresso.viewActionWatcherInterceptors,
kaspresso.viewAssertionWatcherInterceptors,
kaspresso.atomWatcherInterceptors,
kaspresso.webAssertionWatcherInterceptors,
kaspresso.params.clickParams
)

injectKaspressoInKautomator(
kaspresso.objectBehaviorInterceptors,
kaspresso.deviceBehaviorInterceptors,
kaspresso.objectWatcherInterceptors,
kaspresso.deviceWatcherInterceptors
)
kaspresso.injectInKakaoAndKautomator()

failureHandler?.let { Espresso.setFailureHandler(it) }

return kaspresso
}
}

internal fun reset(): Unit = Kakao.reset()
internal fun injectInKakaoAndKautomator() {
injectKaspressoInKakao(
viewBehaviorInterceptors,
dataBehaviorInterceptors,
webBehaviorInterceptors,
viewActionWatcherInterceptors,
viewAssertionWatcherInterceptors,
atomWatcherInterceptors,
webAssertionWatcherInterceptors,
params.clickParams
)

injectKaspressoInKautomator(
objectBehaviorInterceptors,
deviceBehaviorInterceptors,
objectWatcherInterceptors,
deviceWatcherInterceptors
)
}

internal fun reset() {
Kakao.reset()
KautomatorConfigurator.reset()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ internal class TestRunner<InitData, Data>(
private val kaspresso: Kaspresso
) {
fun run(testBody: TestBody<InitData, Data>) {
/**
* We reset Kakao and Kautomator settings after each test.
* So we should set it up before launching test because in some cases one test is launching several times
* e.g. Screenshot tests with several locales
*/
kaspresso.injectInKakaoAndKautomator()

val exceptions: MutableList<Throwable> = mutableListOf()
val resultException: Throwable?
val baseTestContext = BaseTestContext(kaspresso)
Expand Down

0 comments on commit e8e8b5d

Please sign in to comment.