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 541 custom kakao click support #546

Merged
merged 3 commits into from
Jul 28, 2023
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
19 changes: 19 additions & 0 deletions docs/Wiki/Kaspresso_configuration.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ class SomeTest : TestCase(

**Kaspresso** configuration contains:

#### Kakao clicks
Kaspresso provides the possibility to override Espresso custom clicks.
Kakao library provides a set of prepared custom clicks which improves the stability of the tests especially on the devices under high load.

All details about the problem and solutions are described in [Kakao documentation](https://github.com/KakaoCup/Kakao/tree/master/kakao-ext-clicks).

The example of how to apply the custom clicks in your test is presented in [ClickTest](../../samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/customclick_tests/ClickTest.kt).
```kotlin
class ClickTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple(
customize = {
clickParams = ClickParams.kakaoVisual()
}
)
) {
// your test
}
```

#### Loggers
Kaspresso provides two loggers: `libLogger` and `testLogger`.
```libLogger``` - inner Kaspresso logger <br>
Expand Down
19 changes: 19 additions & 0 deletions docs/Wiki/Kaspresso_configuration.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ class SomeTest : TestCase(

Конфигурация **Kaspresso** содержит:

#### Kakao clicks
Kaspresso предоставляет возможность переопределить кастомные клики Espresso.
Kakao библиотека предоставляет набор подготовленных имплементаций кликов, которые улучшают стабильность тестов на девайсах, находящихся под большой нагрузкой.

Все детали о проблеме и решениях описано в [Kakao документации](https://github.com/KakaoCup/Kakao/tree/master/kakao-ext-clicks).

Пример, как заиспользовать кастомные клики в вашем тесте, представлен в [CustomClickTest](../../samples/kaspresso-sample/src/androidTest/kotlin/com/kaspersky/kaspressample/customclick_tests/CustomClickTest.kt).
```kotlin
class ClickTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple(
customize = {
clickParams = ClickParams.kakaoVisual()
}
)
) {
// your test
}
```

#### Логгеры
Kaspresso предоставляет два вида логгеров: `libLogger` и `testLogger`.
```libLogger``` - внутренний логгер Kaspresso <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.kaspersky.kaspresso.interceptors.behaviorkautomator.DeviceBehaviorInt
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.ObjectBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.flakysafety.FlakySafeDeviceBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.flakysafety.FlakySafeObjectBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector.injectKaspressoInKakao
import com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector.injectKaspressoInKautomator
import com.kaspersky.kaspresso.interceptors.tolibrary.KakaoLibraryInjector.injectKaspressoInKakao
import com.kaspersky.kaspresso.interceptors.tolibrary.KakaoLibraryInjector.injectKaspressoInKautomator
import com.kaspersky.kaspresso.kaspresso.Kaspresso

/**
Expand Down Expand Up @@ -62,7 +62,8 @@ internal class FlakySafeInterceptorScalpel(
kaspresso.viewActionWatcherInterceptors,
kaspresso.viewAssertionWatcherInterceptors,
kaspresso.atomWatcherInterceptors,
kaspresso.webAssertionWatcherInterceptors
kaspresso.webAssertionWatcherInterceptors,
kaspresso.params.clickParams
)
}

Expand Down Expand Up @@ -93,7 +94,8 @@ internal class FlakySafeInterceptorScalpel(
kaspresso.viewActionWatcherInterceptors,
kaspresso.viewAssertionWatcherInterceptors,
kaspresso.atomWatcherInterceptors,
kaspresso.webAssertionWatcherInterceptors
kaspresso.webAssertionWatcherInterceptors,
kaspresso.params.clickParams
)

injectKaspressoInKautomator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import com.kaspersky.kaspresso.interceptors.watcher.view.AtomWatcherInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.view.ViewActionWatcherInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.view.ViewAssertionWatcherInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.view.WebAssertionWatcherInterceptor
import com.kaspersky.kaspresso.params.ClickParams

internal object LibraryInterceptorsInjector {
internal object KakaoLibraryInjector {

@Suppress("LongParameterList")
fun injectKaspressoInKakao(
Expand All @@ -29,7 +30,8 @@ internal object LibraryInterceptorsInjector {
viewActionWatcherInterceptors: List<ViewActionWatcherInterceptor>,
viewAssertionWatcherInterceptors: List<ViewAssertionWatcherInterceptor>,
atomWatcherInterceptors: List<AtomWatcherInterceptor>,
webAssertionWatcherInterceptors: List<WebAssertionWatcherInterceptor>
webAssertionWatcherInterceptors: List<WebAssertionWatcherInterceptor>,
clickParams: ClickParams
) {
val viewInterceptor =
KakaoViewInterceptor(
Expand Down Expand Up @@ -62,6 +64,12 @@ internal object LibraryInterceptorsInjector {
onPerform(isOverride = true, interceptor = webInterceptor::interceptPerform)
}
}

Kakao {
singleClickAction = clickParams.singleClickAction
doubleClickAction = clickParams.doubleClickAction
longClickAction = clickParams.longClickAction
}
}

fun injectKaspressoInKautomator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.flakysafety.
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.flakysafety.FlakySafeObjectBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.systemsafety.SystemDialogSafetyDeviceBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.systemsafety.SystemDialogSafetyObjectBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector.injectKaspressoInKakao
import com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector.injectKaspressoInKautomator
import com.kaspersky.kaspresso.interceptors.tolibrary.KakaoLibraryInjector.injectKaspressoInKakao
import com.kaspersky.kaspresso.interceptors.tolibrary.KakaoLibraryInjector.injectKaspressoInKautomator
import com.kaspersky.kaspresso.interceptors.tolibrary.kautomator.KautomatorDeviceInterceptor
import com.kaspersky.kaspresso.interceptors.tolibrary.kautomator.KautomatorObjectInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.kautomator.DeviceWatcherInterceptor
Expand Down Expand Up @@ -113,6 +113,7 @@ import com.kaspersky.kaspresso.interceptors.watcher.view.impl.logging.LoggingWeb
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.logger.UiTestLoggerImpl
import com.kaspersky.kaspresso.params.AutoScrollParams
import com.kaspersky.kaspresso.params.ClickParams
import com.kaspersky.kaspresso.params.ContinuouslyParams
import com.kaspersky.kaspresso.params.ElementLoaderParams
import com.kaspersky.kaspresso.params.FlakySafetyParams
Expand Down Expand Up @@ -475,6 +476,11 @@ data class Kaspresso(
*/
lateinit var elementLoaderParams: ElementLoaderParams

/**
* Holds the [ClickParams].
* If it was not specified, the default implementation is used.
*/
lateinit var clickParams: ClickParams
/**
* Holds an implementation of [DirsProvider] interface. If it was not specified, the default implementation is used.
*/
Expand Down Expand Up @@ -737,6 +743,7 @@ data class Kaspresso(
if (!::screenshotParams.isInitialized) screenshotParams = ScreenshotParams()
if (!::videoParams.isInitialized) videoParams = VideoParams()
if (!::elementLoaderParams.isInitialized) elementLoaderParams = ElementLoaderParams()
if (!::clickParams.isInitialized) clickParams = ClickParams.default()

if (!::screenshots.isInitialized) {
screenshots = ScreenshotsImpl(
Expand Down Expand Up @@ -952,7 +959,8 @@ data class Kaspresso(
screenshotParams = screenshotParams,
videoParams = videoParams,
elementLoaderParams = elementLoaderParams,
systemDialogsSafetyParams = systemDialogsSafetyParams
systemDialogsSafetyParams = systemDialogsSafetyParams,
clickParams = clickParams
),

viewActionWatcherInterceptors = viewActionWatcherInterceptors,
Expand Down Expand Up @@ -984,7 +992,8 @@ data class Kaspresso(
kaspresso.viewActionWatcherInterceptors,
kaspresso.viewAssertionWatcherInterceptors,
kaspresso.atomWatcherInterceptors,
kaspresso.webAssertionWatcherInterceptors
kaspresso.webAssertionWatcherInterceptors,
kaspresso.params.clickParams
)

injectKaspressoInKautomator(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.kaspersky.kaspresso.params

import io.github.kakaocup.kakao.common.actions.clicks.ClickAction
import io.github.kakaocup.kakao.common.actions.clicks.EspressoDoubleClick
import io.github.kakaocup.kakao.common.actions.clicks.EspressoLongClick
import io.github.kakaocup.kakao.common.actions.clicks.EspressoSingleClick
import io.github.kakaocup.kakao.ext.clicks.KakaoDoubleClick
import io.github.kakaocup.kakao.ext.clicks.KakaoLongClick
import io.github.kakaocup.kakao.ext.clicks.KakaoSingleClick
import io.github.kakaocup.kakao.ext.clicks.visualization.VisualClicksConfig

/**
* This class provides the possibility to override default espresso clicks.
* All details are described in https://github.com/KakaoCup/Kakao/tree/master/kakao-ext-clicks
*/
data class ClickParams(
val singleClickAction: ClickAction,
val doubleClickAction: ClickAction,
val longClickAction: ClickAction,
) {

companion object {
/**
* Default Espresso clicks
*/
fun default() = ClickParams(
singleClickAction = EspressoSingleClick(),
doubleClickAction = EspressoDoubleClick(),
longClickAction = EspressoLongClick()
)

/**
* Custom Kakao clicks
*/
fun kakao() = ClickParams(
singleClickAction = KakaoSingleClick(),
doubleClickAction = KakaoDoubleClick(),
longClickAction = KakaoLongClick()
)

/**
* Custom Kakao clicks with visualisation
*/
fun kakaoVisual() = ClickParams(
singleClickAction = KakaoSingleClick(VisualClicksConfig()),
doubleClickAction = KakaoDoubleClick(VisualClicksConfig()),
longClickAction = KakaoLongClick(VisualClicksConfig())
)

/**
* Custom clicks
*/
fun customise(
singleClickAction: ClickAction,
doubleClickAction: ClickAction,
longClickAction: ClickAction
) = ClickParams(
singleClickAction = singleClickAction,
doubleClickAction = doubleClickAction,
longClickAction = longClickAction
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ data class Params(
val screenshotParams: ScreenshotParams,
val videoParams: VideoParams,
val elementLoaderParams: ElementLoaderParams,
val systemDialogsSafetyParams: SystemDialogsSafetyParams
val systemDialogsSafetyParams: SystemDialogsSafetyParams,
val clickParams: ClickParams
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.kaspersky.kaspressample.customclick_tests

import android.Manifest
import android.os.Build
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.MainActivity
import com.kaspersky.kaspressample.R
import com.kaspersky.kaspressample.screen.MainScreen
import com.kaspersky.kaspressample.screen.SimpleScreen
import com.kaspersky.kaspressample.simple_tests.CheckEditScenario
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.params.ClickParams
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Assume
import org.junit.Rule
import org.junit.Test

/**
* The example of how to apply kakao custom clicks in Kaspresso
*/
class CustomClickTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple(
customize = {
clickParams = ClickParams.kakaoVisual()
}
)
) {

@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

@Test
fun test() = before {
Assume.assumeTrue(
"Click visualization supported only on Android M+",
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
)
}.after {
}.run {
step("Open Simple Screen") {
testLogger.i("I am testLogger")
device.screenshots.take("Additional_screenshot")
MainScreen {
simpleButton {
isVisible()
click()
}
}
}

step("Click button_1 and check button_2") {
SimpleScreen {
button1 {
click()
}
button2 {
isVisible()
}
}
}

step("Click button_2 and check edit") {
SimpleScreen {
button2 {
click()
}
edit {
flakySafely(timeoutMs = 7000) { isVisible() }
hasText(R.string.simple_fragment_text_edittext)
}
}
}

step("Check all possibilities of edit") {
scenario(
CheckEditScenario()
)
}
}
}