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 310/compose module #332

Merged
merged 6 commits into from
Nov 26, 2021
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 @@ -3,7 +3,6 @@ package com.kaspersky.components.kautomator.component.common.assertions

import com.google.common.truth.Truth.assertThat
import com.kaspersky.components.kautomator.intercept.delegate.UiObjectInteractionDelegate
import com.kaspersky.components.kautomator.intercept.exception.UnfoundedUiObjectException
import com.kaspersky.components.kautomator.intercept.operation.UiOperationType

/**
Expand All @@ -27,18 +26,11 @@ interface UiBaseAssertions {
* Checks if the view is not completely displayed
*/
fun isNotDisplayed() {
// the implementation is a little bit tricky because
// UiObjectInteractionDelegate throws UnfoundedUiObjectException in case of absence of a related UIObject2
// that's why we just catch the mentioned exception and do a final check
val notDisplayed = try {
isDisplayed()
false
} catch (exception: UnfoundedUiObjectException) {
true
} catch (exception: Throwable) {
false
}
assertThat(notDisplayed).isTrue()
// the implementation is a little bit tricky skipping 'view.check' way
// the reason: nullable uiObject2 triggers the work of all behavior Interceptors
// which can lead to unexpected behavior
// that's why we check uiObject2 directly
assertThat(view.interaction.uiObject2).isNull()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.test.rule.GrantPermissionRule
import com.kaspersky.components.kautomator.KautomatorConfigurator
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.screen.UiScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.kautomatorsample.MainActivity
import com.kaspersky.kaspresso.kautomatorsample.screen.MainScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
Expand All @@ -17,13 +16,7 @@ import org.junit.Test
/**
* The test demonstrating and checking work of interceptors concept in Kautomator
*/
class InterceptorTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple {
afterEachTest {
InterceptedMainScreen.resetScreenList()
}
}
) {
class InterceptorTest : TestCase() {

@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Expand All @@ -34,6 +27,8 @@ class InterceptorTest : TestCase(
@get:Rule
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false)

private val interceptorMainScreen = InterceptedMainScreen()

@Test
fun testKautomatorInterceptors() {
val list = mutableListOf<String>()
Expand Down Expand Up @@ -73,7 +68,7 @@ class InterceptorTest : TestCase(
}.after {
}.run {
step("Simple action on Intercepted Screen") {
InterceptedMainScreen {
interceptorMainScreen {
simpleButton {
isDisplayed()
click()
Expand All @@ -82,7 +77,7 @@ class InterceptorTest : TestCase(
}

step("Check Intercepting correctness") {
InterceptedMainScreen {
interceptorMainScreen {
assertEquals(mutableListOf("ALL", "CHECK", "ALL", "PERFORM"), screenList)
}
}
Expand Down Expand Up @@ -136,7 +131,7 @@ class InterceptorTest : TestCase(
}.after {
}.run {
step("Simple action on intercepted Screen with intercepted View") {
InterceptedMainScreen {
interceptorMainScreen {
simpleButton {
intercept {
onAll { list.add("ALL_VIEW") }
Expand All @@ -151,7 +146,7 @@ class InterceptorTest : TestCase(
}

step("Check Intercepting correctness") {
InterceptedMainScreen {
interceptorMainScreen {
assert(screenList == mutableListOf("ALL", "CHECK", "ALL", "PERFORM"))
}
assertEquals(
Expand Down Expand Up @@ -182,7 +177,7 @@ class InterceptorTest : TestCase(
}.after {
}.run {
step("Simple action on intercepted Screen with intercepted View") {
InterceptedMainScreen {
interceptorMainScreen {
simpleButton {
intercept {
onAll { list.add("ALL_VIEW") }
Expand All @@ -205,15 +200,15 @@ class InterceptorTest : TestCase(
}

step("Check Intercepting correctness") {
InterceptedMainScreen {
interceptorMainScreen {
assert(screenList.isEmpty())
}
assertEquals(mutableListOf("ALL_VIEW", "CHECK_VIEW", "ALL_VIEW", "PERFORM_VIEW"), list)
}
}
}

object InterceptedMainScreen : UiScreen<InterceptedMainScreen>() {
class InterceptedMainScreen : UiScreen<InterceptedMainScreen>() {

override val packageName: String = "com.kaspersky.kaspresso.kautomatorsample"

Expand All @@ -229,9 +224,5 @@ class InterceptorTest : TestCase(
}
}
}

fun resetScreenList() {
screenList.clear()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ class UiSimpleTest : TestCase() {
intercept {
onUiInteraction {
onCheck { uiInteraction, uiAssert ->
// reFindUiObject() is called to update elements in MainScreen that could stale because MainScreen is Object.
// Usually, Kautomator interceptors handle such cases. But here, we define our own Interceptors for Kautomator,
// that's why there is a risk to catch an Exception. All of this forces us to put reFindUiObject() manually.
uiInteraction.reFindUiObject()
testLogger.i("KautomatorIntercept", "interaction=$uiInteraction, assertion=$uiAssert")
uiInteraction.check(uiAssert)
}
onPerform { uiInteraction, uiAction ->
// reFindUiObject() is called to update elements in MainScreen that could stale because MainScreen is Object.
// Usually, Kautomator interceptors handle such cases. But here, we define our own Interceptors for Kautomator,
// that's why there is a risk to catch an Exception. All of this forces us to put reFindUiObject() manually.
uiInteraction.reFindUiObject()
testLogger.i("KautomatorIntercept", "interaction=$uiInteraction, action=$uiAction")
}
}
Expand Down