Skip to content

Commit

Permalink
Merge pull request #452 from KasperskyLab/TECH-sanity-tests
Browse files Browse the repository at this point in the history
Tech sanity tests
  • Loading branch information
Areyana authored Aug 2, 2023
2 parents 4abeb32 + 7983503 commit 924534a
Show file tree
Hide file tree
Showing 50 changed files with 1,890 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kaspersky.kaspresso.systemsafety

import java.util.regex.Pattern

enum class SystemDialogSafetyPattern(val pattern: Pattern) {
PERMISSION_API23(Pattern.compile("\\S*android.packageinstaller\\S*")),
PERMISSION_API30(Pattern.compile("\\S*android.permissioncontroller\\S*")),
OTHER(Pattern.compile("\\S*google.android\\S*"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class SystemDialogSafetyProviderImpl(
{ uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("android:id/button1")), DEFAULT_TIMEOUT).click() },
{ uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("android:id/closeButton")), DEFAULT_TIMEOUT).click() },
{ uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("com.android.internal:id/aerr_close")), DEFAULT_TIMEOUT).click() },
{ uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("com.android.packageinstaller:id/permission_deny_button")), DEFAULT_TIMEOUT).click() },
{ uiDevice, _ -> uiDevice.wait(Until.findObject(By.res("com.android.permissioncontroller:id/permission_deny_button")), DEFAULT_TIMEOUT).click() },
{ uiDevice, _ -> uiDevice.pressBack() }
)

Expand Down Expand Up @@ -108,7 +110,7 @@ class SystemDialogSafetyProviderImpl(
*/
private fun isAndroidSystemDetected(): Boolean {
with(uiDevice) {
var isSystemDialogVisible = isVisible(By.pkg(Pattern.compile("\\S*google.android\\S*")).clazz(FrameLayout::class.java))
var isSystemDialogVisible = SystemDialogSafetyPattern.values().any { isVisible(By.pkg(it.pattern).clazz(FrameLayout::class.java)) }

if (systemDialogsSafetyParams.shouldIgnoreKeyboard) {
val isKeyboardVisible = isVisible(By.pkg(Pattern.compile("\\S*google.android.inputmethod\\S*")).clazz(FrameLayout::class.java))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.kaspersky.kaspresso.composesupport.kaspresso.sanity.autoscroll

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.kaspersky.components.composesupport.config.withComposeSupport
import com.kaspersky.kaspresso.composesupport.sample.MainActivity
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeMainScreen
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeScrollScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.kakaocup.compose.node.element.ComposeScreen
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.AssertionError

@RunWith(AndroidJUnit4::class)
class AutoScrollSemanticsDisabledSanityTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withComposeSupport(
lateComposeCustomize = { composeBuilder ->
composeBuilder.semanticsBehaviorInterceptors = mutableListOf()
}
)
) {

@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun test() = run {
step("Open Flaky screen") {
ComposeScreen.onComposeScreen<ComposeMainScreen>(composeTestRule) {
scrollButton {
performClick()
}
}
}

step("Click on the First button") {
ComposeScreen.onComposeScreen<ComposeScrollScreen>(composeTestRule) {
firstButton {
assertIsDisplayed()
performClick()
}
}
}

step("Click on the Last button") {
ComposeScreen.onComposeScreen<ComposeScrollScreen>(composeTestRule) {
Assert.assertThrows(null, AssertionError::class.java) {
lastButton {
assertIsDisplayed()
performClick()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.kaspersky.kaspresso.composesupport.kaspresso.sanity.autoscroll

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.kaspersky.components.composesupport.config.withComposeSupport
import com.kaspersky.components.composesupport.interceptors.behavior.impl.autoscroll.AutoScrollSemanticsBehaviorInterceptor
import com.kaspersky.kaspresso.composesupport.sample.MainActivity
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeMainScreen
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeScrollScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.logger.UiTestLoggerImpl
import com.kaspersky.kaspresso.params.AutoScrollParams
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.kakaocup.compose.node.element.ComposeScreen
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class AutoScrollSemanticsEnabledSanityTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withComposeSupport(
lateComposeCustomize = { composeBuilder ->
composeBuilder.semanticsBehaviorInterceptors = mutableListOf(AutoScrollSemanticsBehaviorInterceptor(UiTestLoggerImpl(Kaspresso.DEFAULT_TEST_LOGGER_TAG), AutoScrollParams.default()))
}
)
) {

@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun test() = run {
step("Open Flaky screen") {
ComposeScreen.onComposeScreen<ComposeMainScreen>(composeTestRule) {
scrollButton {
performClick()
}
}
}

step("Click on the First button") {
ComposeScreen.onComposeScreen<ComposeScrollScreen>(composeTestRule) {
firstButton {
assertIsDisplayed()
performClick()
}
}
}

step("Click on the Last button") {
ComposeScreen.onComposeScreen<ComposeScrollScreen>(composeTestRule) {
lastButton {
assertIsDisplayed()
performClick()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.kaspersky.kaspresso.composesupport.kaspresso.sanity.flaky

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.kaspersky.components.composesupport.config.withComposeSupport
import com.kaspersky.kaspresso.composesupport.sample.MainActivity
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeMainScreen
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeSanityFlakyScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.kakaocup.compose.node.element.ComposeScreen
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FlakyComposeDisabledSanityTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withComposeSupport(
lateComposeCustomize = { composeBuilder ->
composeBuilder.semanticsBehaviorInterceptors = mutableListOf()
}
)
) {

@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun test() = run {
step("Open Flaky screen") {
ComposeScreen.onComposeScreen<ComposeMainScreen>(composeTestRule) {
sanityFlakyButton {
performClick()
}
}
}

step("Click on the First button") {
ComposeScreen.onComposeScreen<ComposeSanityFlakyScreen>(composeTestRule) {
firstButton {
assertIsDisplayed()
performClick()
}
}
}

step("Click on the Second button") {
ComposeScreen.onComposeScreen<ComposeSanityFlakyScreen>(composeTestRule) {
secondButton {
Assert.assertThrows(null, AssertionError::class.java) {
assertIsDisplayed()
performClick()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.kaspersky.kaspresso.composesupport.kaspresso.sanity.flaky

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.kaspersky.components.composesupport.config.withComposeSupport
import com.kaspersky.components.composesupport.interceptors.behavior.impl.flakysafety.FlakySafeSemanticsBehaviorInterceptor
import com.kaspersky.kaspresso.composesupport.sample.MainActivity
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeMainScreen
import com.kaspersky.kaspresso.composesupport.sample.screen.ComposeSanityFlakyScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.logger.UiTestLoggerImpl
import com.kaspersky.kaspresso.params.FlakySafetyParams
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.kakaocup.compose.node.element.ComposeScreen
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FlakyComposeEnabledSanityTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withComposeSupport(
lateComposeCustomize = { composeBuilder ->
composeBuilder.semanticsBehaviorInterceptors = mutableListOf(FlakySafeSemanticsBehaviorInterceptor(FlakySafetyParams.default(), UiTestLoggerImpl(Kaspresso.DEFAULT_TEST_LOGGER_TAG)))
}
)
) {

@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun test() = run {
step("Open Flaky screen") {
ComposeScreen.onComposeScreen<ComposeMainScreen>(composeTestRule) {
sanityFlakyButton {
performClick()
}
}
}

step("Click on the First button") {
ComposeScreen.onComposeScreen<ComposeSanityFlakyScreen>(composeTestRule) {
firstButton {
assertIsDisplayed()
performClick()
}
}
}

step("Click on the Second button") {
ComposeScreen.onComposeScreen<ComposeSanityFlakyScreen>(composeTestRule) {
secondButton {
assertIsDisplayed()
performClick()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ class ComposeMainScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
val simpleFlakyButton: KNode = child {
hasTestTag(C.Tag.main_screen_simple_flaky_button)
}

val sanityFlakyButton: KNode = child {
hasTestTag(C.Tag.main_screen_sanity_flaky_button)
}

val scrollButton: KNode = child {
hasTestTag(C.Tag.main_screen_scroll_button)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeSanityFlakyScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeSanityFlakyScreen>(
semanticsProvider = semanticsProvider,
viewBuilderAction = { hasTestTag(C.Tag.sanity_flaky_screen_container) }
) {

val firstButton: KNode = child {
hasTestTag(C.Tag.sanity_flaky_screen_simple_first_button)
}

val secondButton: KNode = child {
hasTestTag(C.Tag.sanity_flaky_screen_simple_second_button)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeScrollScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeScrollScreen>(
semanticsProvider = semanticsProvider,
viewBuilderAction = { hasTestTag(C.Tag.scroll_screen_container) }
) {

val firstButton: KNode = child {
hasTestTag(C.Tag.scroll_screen_buttons[0])
}

val lastButton: KNode = child {
hasTestTag(C.Tag.scroll_screen_buttons.last())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import androidx.navigation.compose.rememberNavController
import com.kaspersky.kaspresso.composesupport.sample.features.flaky.SimpleFlakyScreen
import com.kaspersky.kaspresso.composesupport.sample.features.flaky.SimpleFlakyViewModel
import com.kaspersky.kaspresso.composesupport.sample.features.main.MainScreen
import com.kaspersky.kaspresso.composesupport.sample.features.sanityflaky.SanityFlakyScreen
import com.kaspersky.kaspresso.composesupport.sample.features.sanityflaky.SanityFlakyViewModel
import com.kaspersky.kaspresso.composesupport.sample.features.scroll.ScrollScreen
import com.kaspersky.kaspresso.composesupport.sample.resources.C

class MainActivity : AppCompatActivity() {

private val simpleFlakyViewModel: SimpleFlakyViewModel by viewModels()
private val sanityFlakyViewModel: SanityFlakyViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -30,7 +34,9 @@ class MainActivity : AppCompatActivity() {
NavHost(navController = navController, startDestination = C.Screen.main_screen) {
composable(C.Screen.main_screen) {
MainScreen(
simpleFlakyClick = { navController.navigate(C.Screen.simple_flaky_screen) }
simpleFlakyClick = { navController.navigate(C.Screen.simple_flaky_screen) },
sanityFlakyClick = { navController.navigate(C.Screen.sanity_flaky_screen) },
scrollClick = { navController.navigate(C.Screen.scroll_screen) }
)
}

Expand All @@ -42,6 +48,15 @@ class MainActivity : AppCompatActivity() {
editTextChange = { simpleFlakyViewModel.editTextChange(it) }
)
}

composable(C.Screen.scroll_screen) {
ScrollScreen()
}

composable(C.Screen.sanity_flaky_screen) {
SanityFlakyScreen(sanityFlakyStateLiveData =
sanityFlakyViewModel.sanityFlakyStateLiveData, firstButtonClick = { sanityFlakyViewModel.firstButtonClick() })
}
}
}
}
Loading

0 comments on commit 924534a

Please sign in to comment.