Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-521: add option to ignore keyboard #529

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ComposeConfig {
SystemDialogSafetySemanticsBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetySemanticsBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
ElementLoaderSemanticsBehaviorInterceptor(libLogger, elementLoaderParams),
FlakySafeSemanticsBehaviorInterceptor(flakySafetyParams, libLogger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.kaspersky.components.composesupport.interceptors.behavior.impl.systemsafety

import com.kaspersky.components.composesupport.interceptors.behavior.SemanticsBehaviorInterceptor
import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.components.composesupport.interceptors.behavior.SemanticsBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
import io.github.kakaocup.compose.intercept.interaction.ComposeInteraction
Expand All @@ -17,9 +18,10 @@ import io.github.kakaocup.compose.intercept.operation.ComposeAssertion
class SystemDialogSafetySemanticsBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : SemanticsBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [activity] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.interceptors.behavior.DataBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl

Expand All @@ -15,9 +16,10 @@ import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
class SystemDialogSafetyDataBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : DataBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [action] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.interceptors.behavior.ViewBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl

Expand All @@ -15,9 +16,10 @@ import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
class SystemDialogSafetyViewBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : ViewBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [action] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.interceptors.behavior.WebBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl

Expand All @@ -15,9 +16,10 @@ import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
class SystemDialogSafetyWebBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : WebBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [action] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.DeviceBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl

Expand All @@ -17,9 +18,10 @@ import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
class SystemDialogSafetyDeviceBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : DeviceBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [activity] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.ObjectBehaviorInterceptor
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProvider
import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl

Expand All @@ -17,9 +18,10 @@ import com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl
class SystemDialogSafetyObjectBehaviorInterceptor(
logger: UiTestLogger,
instrumentalDependencyProvider: InstrumentalDependencyProvider,
adbServer: AdbServer
adbServer: AdbServer,
systemDialogsSafetyParams: SystemDialogsSafetyParams
) : ObjectBehaviorInterceptor,
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer) {
SystemDialogSafetyProvider by SystemDialogSafetyProviderImpl(logger, instrumentalDependencyProvider, adbServer, systemDialogsSafetyParams) {

/**
* Wraps the given [activity] invocation with the system dialog safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import com.kaspersky.kaspresso.params.FlakySafetyParams
import com.kaspersky.kaspresso.params.Params
import com.kaspersky.kaspresso.params.ScreenshotParams
import com.kaspersky.kaspresso.params.StepParams
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import com.kaspersky.kaspresso.params.VideoParams
import com.kaspersky.kaspresso.testcases.core.testcontext.BaseTestContext
import io.github.kakaocup.kakao.Kakao
Expand Down Expand Up @@ -435,6 +436,8 @@ data class Kaspresso(
*/
lateinit var flakySafetyParams: FlakySafetyParams

lateinit var systemDialogsSafetyParams: SystemDialogsSafetyParams

/**
* Holds the [ContinuouslyParams] for [com.kaspersky.kaspresso.flakysafety.ContinuouslyProvider]'s usage.
* If it was not specified, the default implementation is used.
Expand Down Expand Up @@ -727,6 +730,7 @@ data class Kaspresso(
if (!::logcat.isInitialized) logcat = LogcatImpl(libLogger, adbServer)

if (!::flakySafetyParams.isInitialized) flakySafetyParams = FlakySafetyParams.default()
if (!::systemDialogsSafetyParams.isInitialized) systemDialogsSafetyParams = SystemDialogsSafetyParams.default()
if (!::continuouslyParams.isInitialized) continuouslyParams = ContinuouslyParams.default()
if (!::autoScrollParams.isInitialized) autoScrollParams = AutoScrollParams.default()
if (!::stepParams.isInitialized) stepParams = StepParams()
Expand Down Expand Up @@ -828,7 +832,8 @@ data class Kaspresso(
SystemDialogSafetyViewBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetyViewBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
FlakySafeViewBehaviorInterceptor(flakySafetyParams, libLogger)
) else mutableListOf(
Expand All @@ -841,7 +846,8 @@ data class Kaspresso(
SystemDialogSafetyDataBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetyViewBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
FlakySafeDataBehaviorInterceptor(flakySafetyParams, libLogger)
) else mutableListOf(
Expand All @@ -855,7 +861,8 @@ data class Kaspresso(
SystemDialogSafetyWebBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetyViewBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
FlakySafeWebBehaviorInterceptor(flakySafetyParams, libLogger)
)
Expand All @@ -871,7 +878,8 @@ data class Kaspresso(
SystemDialogSafetyObjectBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetyViewBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
ElementLoaderObjectBehaviorInterceptor(libLogger, elementLoaderParams),
FlakySafeObjectBehaviorInterceptor(flakySafetyParams, libLogger)
Expand All @@ -881,7 +889,8 @@ data class Kaspresso(
SystemDialogSafetyDeviceBehaviorInterceptor(
libLogger,
instrumentalDependencyProviderFactory.getInterceptorProvider<SystemDialogSafetyViewBehaviorInterceptor>(instrumentation),
adbServer
adbServer,
systemDialogsSafetyParams
),
FlakySafeDeviceBehaviorInterceptor(flakySafetyParams, libLogger)
)
Expand Down Expand Up @@ -943,6 +952,7 @@ data class Kaspresso(
screenshotParams = screenshotParams,
videoParams = videoParams,
elementLoaderParams = elementLoaderParams,
systemDialogsSafetyParams = systemDialogsSafetyParams
),

viewActionWatcherInterceptors = viewActionWatcherInterceptors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ data class Params(
val screenshotParams: ScreenshotParams,
val videoParams: VideoParams,
val elementLoaderParams: ElementLoaderParams,
val systemDialogsSafetyParams: SystemDialogsSafetyParams
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kaspersky.kaspresso.params

data class SystemDialogsSafetyParams(
val shouldIgnoreKeyboard: Boolean
) {
companion object {
fun default() = SystemDialogsSafetyParams(shouldIgnoreKeyboard = false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.test.uiautomator.Until
import com.kaspersky.kaspresso.device.server.AdbServer
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProvider
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.SystemDialogsSafetyParams
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

Expand All @@ -17,7 +18,8 @@ import java.util.regex.Pattern
class SystemDialogSafetyProviderImpl(
private val logger: UiTestLogger,
private val instrumentalDependencyProvider: InstrumentalDependencyProvider,
private val adbServer: AdbServer
private val adbServer: AdbServer,
private val systemDialogsSafetyParams: SystemDialogsSafetyParams
) : SystemDialogSafetyProvider {

companion object {
Expand Down Expand Up @@ -106,7 +108,14 @@ class SystemDialogSafetyProviderImpl(
*/
private fun isAndroidSystemDetected(): Boolean {
with(uiDevice) {
if (isVisible(By.pkg(Pattern.compile("\\S*google.android\\S*")).clazz(FrameLayout::class.java))) {
var isSystemDialogVisible = isVisible(By.pkg(Pattern.compile("\\S*google.android\\S*")).clazz(FrameLayout::class.java))

if (systemDialogsSafetyParams.shouldIgnoreKeyboard) {
val isKeyboardVisible = isVisible(By.pkg(Pattern.compile("\\S*google.android.inputmethod\\S*")).clazz(FrameLayout::class.java))
isSystemDialogVisible = isSystemDialogVisible && !isKeyboardVisible
}

if (isSystemDialogVisible) {
logger.i("The android system dialog/window was detected")
return true
}
Expand Down