Skip to content

Commit

Permalink
Refresh SemanticsNodeInteraction provider state (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tiurin authored Aug 6, 2024
1 parent 41b55a7 commit b483429
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package com.atiurin.sampleapp.tests

import android.os.Environment
import androidx.test.platform.app.InstrumentationRegistry
import com.atiurin.ultron.testlifecycle.rulesequence.RuleSequence
import com.atiurin.sampleapp.data.repositories.CURRENT_USER
import com.atiurin.sampleapp.managers.AccountManager
import com.atiurin.ultron.allure.config.UltronAllureConfig
import com.atiurin.ultron.allure.listeners.DetailedOperationAllureListener
import com.atiurin.ultron.allure.listeners.ScreenshotAttachListener
import com.atiurin.ultron.allure.listeners.WindowHierarchyAttachListener
import com.atiurin.ultron.core.compose.config.UltronComposeConfig
import com.atiurin.ultron.core.config.UltronConfig
import com.atiurin.ultron.testlifecycle.rulesequence.RuleSequence
import com.atiurin.ultron.testlifecycle.setupteardown.SetUpRule
import org.junit.BeforeClass
import org.junit.Rule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.atiurin.sampleapp.tests.compose

import androidx.compose.ui.test.hasTestTag
import com.atiurin.sampleapp.activity.ComposeElementsActivity
import com.atiurin.sampleapp.tests.BaseTest
import com.atiurin.ultron.core.compose.createUltronComposeRule
import com.atiurin.ultron.extensions.assertIsDisplayed
import com.atiurin.ultron.extensions.withName
import com.atiurin.ultron.extensions.withTimeout
import com.atiurin.ultron.page.Page
import org.junit.Rule
import org.junit.Test

class SampleClassTest : BaseTest() {
@get:Rule
val composeRuleBase = createUltronComposeRule<ComposeElementsActivity>()

@Test
fun test() {
SomePage{
elementWithName.assertIsDisplayed()
elementWithTimeout.assertIsDisplayed()
elementMatcher.assertIsDisplayed()
}
}

@Test
fun test2() {
SomePage{
elementWithName.assertIsDisplayed()
elementWithTimeout.assertIsDisplayed()
elementMatcher.assertIsDisplayed()
}
}
}

object SomePage : Page<SomePage>() {
val elementWithName = hasTestTag("statusText").withName("sample element name")
val elementWithTimeout = hasTestTag("statusText").withTimeout(4000)
val elementMatcher = hasTestTag("statusText")
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.atiurin.ultron.extensions.simpleClassName
import com.atiurin.ultron.listeners.LogLifecycleListener
import com.atiurin.ultron.listeners.UltronLifecycleListener
import com.atiurin.ultron.log.UltronLog
import com.atiurin.ultron.log.UltronLogcatLogger
import com.atiurin.ultron.log.getFileLogger
import com.atiurin.ultron.testlifecycle.setupteardown.ConditionExecutorWrapper
import com.atiurin.ultron.testlifecycle.setupteardown.ConditionsExecutor
Expand Down Expand Up @@ -75,6 +76,7 @@ object UltronConfig {
Espresso.ASSERTION_TIMEOUT = params.operationTimeoutMs
UiAutomator.OPERATION_TIMEOUT = params.operationTimeoutMs
UltronCommonConfig.addListener(LogLifecycleListener())
UltronLog.addLogger(UltronLogcatLogger())
if (params.logToFile) {
UltronLog.addLogger(UltronLog.fileLogger)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.atiurin.ultron.log

expect fun getFileLogger(): UltronFileLogger


object UltronLog {
val fileLogger by lazy { getFileLogger() }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.atiurin.ultron.core.compose.config

import com.atiurin.ultron.log.ULogger
import com.atiurin.ultron.log.UltronLogcatLogger

actual fun getPlatformLoggers(): List<ULogger> {
return listOf(UltronLogcatLogger())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.atiurin.ultron.core.compose.nodeinteraction

import android.os.Build
import androidx.annotation.RequiresApi
import com.atiurin.ultron.core.compose.operation.ComposeOperationType
import java.util.concurrent.atomic.AtomicReference
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.semantics.AccessibilityAction
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.captureToImage
import com.atiurin.ultron.core.compose.operation.ComposeOperationType
import com.atiurin.ultron.extensions.requireSemantics
import com.atiurin.ultron.utils.runOnUiThread
import java.util.concurrent.atomic.AtomicReference

@RequiresApi(Build.VERSION_CODES.O)
fun UltronComposeSemanticsNodeInteraction.captureToImage(): ImageBitmap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.atiurin.ultron.core.compose.config

import com.atiurin.ultron.core.config.UltronCommonConfig
import com.atiurin.ultron.core.common.Operation
import com.atiurin.ultron.core.common.OperationResult
import com.atiurin.ultron.core.common.OperationResultAnalyzer
import com.atiurin.ultron.core.common.UltronDefaultOperationResultAnalyzer
import com.atiurin.ultron.core.compose.operation.ComposeOperationResult
import com.atiurin.ultron.core.compose.operation.ComposeOperationType
import com.atiurin.ultron.core.compose.operation.UltronComposeOperation
import com.atiurin.ultron.core.compose.operation.UltronComposeOperationLifecycle
import com.atiurin.ultron.core.config.UltronCommonConfig
import com.atiurin.ultron.exceptions.UltronAssertionException
import com.atiurin.ultron.exceptions.UltronException
import com.atiurin.ultron.exceptions.UltronWrapperException
import com.atiurin.ultron.extensions.simpleClassName
import com.atiurin.ultron.listeners.LogLifecycleListener
import com.atiurin.ultron.listeners.UltronLifecycleListener
import com.atiurin.ultron.log.ULogger
import com.atiurin.ultron.log.UltronLog

object UltronComposeConfig {
Expand Down Expand Up @@ -88,6 +88,9 @@ object UltronComposeConfig {
}

private fun modify(){
getPlatformLoggers().forEach {
UltronLog.addLogger(it)
}
UltronCommonConfig.addListener(LogLifecycleListener())
if (UltronCommonConfig.logToFile) {
UltronLog.addLogger(UltronLog.fileLogger)
Expand All @@ -97,3 +100,5 @@ object UltronComposeConfig {
UltronLog.info("UltronComposeConfig applied with params $params}")
}
}

expect fun getPlatformLoggers(): List<ULogger>
Loading

0 comments on commit b483429

Please sign in to comment.