Skip to content

Commit

Permalink
change doesNotExistInAnyRoot -> doesNotExistInAnyVisibleRoot, fix tes…
Browse files Browse the repository at this point in the history
…ts, logic (#42)
  • Loading branch information
itsergpot authored May 30, 2023
1 parent ad25a21 commit c425f39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.atiurin.sampleapp.framework.utils.AssertUtils
import com.atiurin.sampleapp.framework.utils.TestDataUtils.getResourceString
import com.atiurin.sampleapp.pages.UiElementsPage
import com.atiurin.sampleapp.tests.UiElementsTest
import com.atiurin.ultron.custom.espresso.assertion.doesNotExistInAnyRoot
import com.atiurin.ultron.custom.espresso.assertion.doesNotExistInAnyVisibleRoot
import com.atiurin.ultron.custom.espresso.assertion.hasCurrentHintTextColor
import com.atiurin.ultron.custom.espresso.assertion.hasCurrentTextColor
import com.atiurin.ultron.custom.espresso.assertion.hasHighlightColor
Expand Down Expand Up @@ -60,12 +60,12 @@ class ViewInteractionAssertionsTest : UiElementsTest() {
//doesNotExistAnyRoot
@Test
fun doesNotExistAnyRoot_notExisted() {
page.notExistElement.doesNotExistInAnyRoot()
page.notExistElement.doesNotExistInAnyVisibleRoot()
}

@Test
fun doesNotExistAnyRoot_existed() {
AssertUtils.assertException { page.button.withTimeout(100).doesNotExistInAnyRoot() }
AssertUtils.assertException { page.button.withTimeout(100).doesNotExistInAnyVisibleRoot() }
}

//exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@ import androidx.test.espresso.DataInteraction
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.RootMatchers.withDecorView
import com.atiurin.ultron.core.espresso.UltronEspressoInteraction
import com.atiurin.ultron.core.espresso.assertion.EspressoAssertionType
import com.atiurin.ultron.custom.espresso.base.getRootViewsList
import org.hamcrest.CoreMatchers.*
import com.atiurin.ultron.custom.espresso.base.getVisibleRootViews
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.Matcher

fun <T> UltronEspressoInteraction<T>.doesNotExistInAnyRoot() = apply {
executeAssertion(
operationBlock = {
getRootViewsList().forEach { root ->
this@doesNotExistInAnyRoot.apply {
inRoot(RootMatchers.withDecorView(`is`(root.decorView)))
getInteractionAssertionBlock(ViewAssertions.doesNotExist())
}
}
},
name = "DoesNotExist of '${getInteractionMatcher()}'",
type = EspressoAssertionType.DOES_NOT_EXIST,
description = "${interaction.className()} assertion '${EspressoAssertionType.DOES_NOT_EXIST}' of '${getInteractionMatcher()}' with root '${getInteractionRootMatcher()}' during ${getAssertionTimeout()} ms"
)
fun <T> UltronEspressoInteraction<T>.doesNotExistInAnyVisibleRoot() : UltronEspressoInteraction<T> {
val defaultUltronEspressoInteraction = this
getVisibleRootViews().forEach { root ->
this.inRoot(withDecorView(`is`(root.decorView)))
executeAssertion(
operationBlock = getInteractionAssertionBlock(ViewAssertions.doesNotExist()),
name = "DoesNotExist of '${getInteractionMatcher()}'",
type = EspressoAssertionType.DOES_NOT_EXIST,
description = "${interaction.className()} assertion '${EspressoAssertionType.DOES_NOT_EXIST}' of '${getInteractionMatcher()}' with root '${getInteractionRootMatcher()}' during ${getAssertionTimeout()} ms"
)
}
return defaultUltronEspressoInteraction
}

fun Matcher<View>.doesNotExistInAnyRoot() = UltronEspressoInteraction(onView(this)).doesNotExistInAnyRoot()
fun ViewInteraction.doesNotExistInAnyRoot() = UltronEspressoInteraction(this).doesNotExistInAnyRoot()
fun DataInteraction.doesNotExistInAnyRoot() = UltronEspressoInteraction(this).doesNotExistInAnyRoot()
fun Matcher<View>.doesNotExistInAnyVisibleRoot() = UltronEspressoInteraction(onView(this)).doesNotExistInAnyVisibleRoot()
fun ViewInteraction.doesNotExistInAnyVisibleRoot() = UltronEspressoInteraction(this).doesNotExistInAnyVisibleRoot()
fun DataInteraction.doesNotExistInAnyVisibleRoot() = UltronEspressoInteraction(this).doesNotExistInAnyVisibleRoot()
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.atiurin.ultron.custom.espresso.base

import androidx.test.espresso.Root
import com.atiurin.ultron.core.config.UltronConfig
import com.atiurin.ultron.utils.isVisible
import com.atiurin.ultron.utils.runOnUiThread

fun getRootViewsList(): List<Root> = runOnUiThread {
UltronConfig.Espresso.activeRootLister.listActiveRoots()
}
}

fun getVisibleRootViews(): List<Root> = getRootViewsList().filter { it.decorView.isVisible }

0 comments on commit c425f39

Please sign in to comment.