Skip to content
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
3 changes: 1 addition & 2 deletions docs/docs/intro/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ dependencies {

If you need another Espresso library in dependencies. It's better to use the same Espresso version as Ultron.

Now - [Ultron Espresso verion](https://github.com/open-tool/ultron/blob/1c81014f4cbea97b2f24128831a13e601936ef57/buildSrc/src/main/kotlin/Versions.kt#L9) is `3.4.0`.
We don't update to `3.5.1` because it brings only a set of problems and nothing improve.
Now - [Ultron Espresso verion](https://github.com/open-tool/ultron/blob/master/buildSrc/src/main/kotlin/Versions.kt#L9) is `3.6.1`.

## Allure Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import com.atiurin.ultron.extensions.perform
import com.atiurin.ultron.extensions.performMouseInput
import com.atiurin.ultron.extensions.replaceText
import com.atiurin.ultron.extensions.selectText
import com.atiurin.ultron.extensions.swipe
import com.atiurin.ultron.extensions.swipeDown
import com.atiurin.ultron.extensions.swipeLeft
import com.atiurin.ultron.extensions.swipeRight
Expand Down Expand Up @@ -240,13 +241,24 @@ class ComposeUIElementsTest : BaseTest() {
page.status.assertTextEquals(ActionsStatus.SwipeLeft.name)
}

@Test
fun swipe_general() {
page.swipeableNode.swipe(ComposeSwipeOption(
startXOffset = 0.1f,
startYOffset = 0.1f,
endXOffset = 0.9f,
endYOffset = 0.1f,
durationMs = 1000L
))
page.status.assertTextEquals(ActionsStatus.SwipeRight.name)
}

@Test
fun inputText() {
val text = "some text"
page.editableText.inputText(text).assertTextContains(text)
}


@Test
fun typeText() {
val text = "some text"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.atiurin.sampleapp.tests.compose

import com.atiurin.sampleapp.activity.ActionsStatus
import com.atiurin.sampleapp.activity.ComposeElementsActivity
import com.atiurin.sampleapp.pages.ComposeElementsPage
import com.atiurin.sampleapp.tests.BaseTest
import com.atiurin.ultron.core.common.options.TextContainsOption
import com.atiurin.ultron.core.compose.createUltronComposeRule
import com.atiurin.ultron.core.compose.nodeinteraction.click
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClick
import com.atiurin.ultron.core.compose.nodeinteraction.longClick
import com.atiurin.ultron.core.compose.option.ComposeSwipeOption
import com.atiurin.ultron.extensions.assertTextEquals
import com.atiurin.ultron.extensions.withMetaInfo
import com.atiurin.ultron.extensions.withName
import org.junit.Rule
import org.junit.Test

class SemNodeInteractionObjectTest : BaseTest() {
@get:Rule
val composeRule = createUltronComposeRule<ComposeElementsActivity>()
val page = ComposeElementsPage

@Test
fun clickTest(){
page.likesCounter.withMetaInfo("likesCounter")
.click()
.assertTextContains(option = TextContainsOption(substring = true), expected = "= 1")
}

@Test
fun longClickTest(){
page.longAndDoubleClickButton.withName("longAndDoubleClickButton").longClick()
page.status.assertTextEquals(ActionsStatus.LongClicked.name)
}

@Test
fun doubleClick_doubleClickable() {
page.longAndDoubleClickButton.withName("longAndDoubleClickButton").doubleClick()
page.status.assertTextEquals(ActionsStatus.DoubleClicked.name)
}

@Test
fun swipeDownTest(){
page.swipeableNode.withName("swipeableNode").swipeDown()
page.status.assertTextEquals(ActionsStatus.SwipeDown.name)
}

@Test
fun swipeUp() {
page.swipeableNode.withName("swipeableNode").swipeUp()
page.status.assertTextEquals(ActionsStatus.SwipeUp.name)
}

@Test
fun swipeRight() {
page.swipeableNode.withName("swipeableNode").swipeRight()
page.status.assertTextEquals(ActionsStatus.SwipeRight.name)
}

@Test
fun swipeLeft() {
page.swipeableNode.withName("swipeableNode").swipeLeft()
page.status.assertTextEquals(ActionsStatus.SwipeLeft.name)
}

@Test
fun swipe_option() {
page.swipeableNode.withName("swipeableNode").swipeLeft(ComposeSwipeOption(durationMs = 1000L))
page.status.assertTextEquals(ActionsStatus.SwipeLeft.name)
}

@Test
fun swipe_general() {
page.swipeableNode.withName("Swipeable Node").swipe(ComposeSwipeOption(
startXOffset = 0.1f,
startYOffset = 0.1f,
endXOffset = 0.9f,
endYOffset = 0.1f,
durationMs = 1000L
))
page.status.assertTextEquals(ActionsStatus.SwipeRight.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ open class UltronComposeListItem {
fun swipeUp(option: ComposeSwipeOption? = null) = apply { getItemUltronComposeInteraction().swipeUp(option) }
fun swipeLeft(option: ComposeSwipeOption? = null) = apply { getItemUltronComposeInteraction().swipeLeft(option) }
fun swipeRight(option: ComposeSwipeOption? = null) = apply { getItemUltronComposeInteraction().swipeRight(option) }
fun swipe(option: ComposeSwipeOption) = apply { getItemUltronComposeInteraction().swipe(option) }

fun imeAction() = apply { getItemUltronComposeInteraction().imeAction() }
fun pressKey(keyEvent: KeyEvent) = apply { getItemUltronComposeInteraction().pressKey(keyEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.atiurin.ultron.core.compose.ComposeTestContainer
import com.atiurin.ultron.core.compose.config.UltronComposeConfig
import com.atiurin.ultron.core.compose.operation.ComposeOperationExecutor
import com.atiurin.ultron.core.compose.operation.ComposeOperationResult
import com.atiurin.ultron.core.compose.operation.ComposeOperationType
import com.atiurin.ultron.core.compose.operation.ComposeOperationType.ASSERT_MATCHES
import com.atiurin.ultron.core.compose.operation.ComposeOperationType.CLEAR_TEXT
import com.atiurin.ultron.core.compose.operation.ComposeOperationType.CLICK
Expand Down Expand Up @@ -266,7 +267,7 @@ open class UltronComposeSemanticsNodeInteraction constructor(
)
}

internal fun swipeDown(option: ComposeSwipeOption? = null) = apply {
fun swipeDown(option: ComposeSwipeOption? = null) = apply {
val _option = option ?: ComposeSwipeOption(0f, 0f, 0f, 0f, DEFAULT_SWIPE_DURATION)
executeOperation(
operationBlock = {
Expand All @@ -281,7 +282,7 @@ open class UltronComposeSemanticsNodeInteraction constructor(
)
}

internal fun swipeUp(option: ComposeSwipeOption? = null) = apply {
fun swipeUp(option: ComposeSwipeOption? = null) = apply {
val _option = option ?: ComposeSwipeOption(0f, 0f, 0f, 0f, DEFAULT_SWIPE_DURATION)
executeOperation(
operationBlock = {
Expand All @@ -296,7 +297,7 @@ open class UltronComposeSemanticsNodeInteraction constructor(
)
}

internal fun swipeLeft(option: ComposeSwipeOption? = null) = apply {
fun swipeLeft(option: ComposeSwipeOption? = null) = apply {
val _option = option ?: ComposeSwipeOption(0f, 0f, 0f, 0f, DEFAULT_SWIPE_DURATION)
executeOperation(
operationBlock = {
Expand All @@ -311,7 +312,7 @@ open class UltronComposeSemanticsNodeInteraction constructor(
)
}

internal fun swipeRight(option: ComposeSwipeOption? = null) = apply {
fun swipeRight(option: ComposeSwipeOption? = null) = apply {
val _option = option ?: ComposeSwipeOption(0f, 0f, 0f, 0f, DEFAULT_SWIPE_DURATION)
executeOperation(
operationBlock = {
Expand All @@ -326,6 +327,20 @@ open class UltronComposeSemanticsNodeInteraction constructor(
)
}

fun swipe(option: ComposeSwipeOption) = apply {
executeOperation(
operationBlock = {
semanticsNodeInteraction.performTouchInput {
val position = provideSwipeRightPosition(option)
this.swipe(position.start, position.end, option.durationMs)
}
},
name = "Swipe to '${elementInfo.name}'",
type = ComposeOperationType.SWIPE,
description = "Compose swipe '${elementInfo.name}' with option = '$option' during $timeoutMs ms ",
)
}

fun scrollTo() = apply {
executeOperation(
operationBlock = { semanticsNodeInteraction.performScrollTo() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum class ComposeOperationType : UltronOperationType {
TEXT_INPUT, REPLACE_TEXT, CLEAR_TEXT, PRESS_KEY, TEXT_INPUT_SELECTION, COPY_TEXT, PASTE_TEXT, CUT_TEXT, SET_TEXT,
GET_TEXT, GET_SEMANTICS_NODE, GET_SEMANTICS_CONFIG_PROPERTY,
IME_ACTION, COLLAPSE, EXPAND, DISMISS, SET_PROGRESS, SET_SELECTION,
SWIPE_LEFT, SWIPE_RIGHT, SWIPE_UP, SWIPE_DOWN,
SWIPE_LEFT, SWIPE_RIGHT, SWIPE_UP, SWIPE_DOWN, SWIPE,
SCROLL_TO, SCROLL_TO_INDEX, SCROLL_TO_KEY, SCROLL_TO_NODE,
CUSTOM, MOUSE_INPUT, SEMANTIC_ACTION,
IS_DISPLAYED, IS_NOT_DISPLAYED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.atiurin.ultron.extensions

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.semantics.AccessibilityAction
import androidx.compose.ui.semantics.ProgressBarRangeInfo
Expand All @@ -14,13 +13,45 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.unit.Dp
import com.atiurin.ultron.core.common.assertion.OperationAssertion
import com.atiurin.ultron.core.common.options.*
import com.atiurin.ultron.*
import com.atiurin.ultron.core.common.options.ClickOption
import com.atiurin.ultron.core.common.options.ContentDescriptionContainsOption
import com.atiurin.ultron.core.common.options.DoubleClickOption
import com.atiurin.ultron.core.common.options.LongClickOption
import com.atiurin.ultron.core.common.options.PerformCustomBlockOption
import com.atiurin.ultron.core.common.options.TextContainsOption
import com.atiurin.ultron.core.common.options.TextEqualsOption
import com.atiurin.ultron.core.compose.nodeinteraction.UltronComposeSemanticsNodeInteraction
import com.atiurin.ultron.core.compose.nodeinteraction.click
import com.atiurin.ultron.core.compose.nodeinteraction.clickBottomCenter
import com.atiurin.ultron.core.compose.nodeinteraction.clickBottomLeft
import com.atiurin.ultron.core.compose.nodeinteraction.clickBottomRight
import com.atiurin.ultron.core.compose.nodeinteraction.clickCenterLeft
import com.atiurin.ultron.core.compose.nodeinteraction.clickCenterRight
import com.atiurin.ultron.core.compose.nodeinteraction.clickTopCenter
import com.atiurin.ultron.core.compose.nodeinteraction.clickTopLeft
import com.atiurin.ultron.core.compose.nodeinteraction.clickTopRight
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClick
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickBottomCenter
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickBottomLeft
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickBottomRight
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickCenterLeft
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickCenterRight
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickTopCenter
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickTopLeft
import com.atiurin.ultron.core.compose.nodeinteraction.doubleClickTopRight
import com.atiurin.ultron.core.compose.nodeinteraction.longClick
import com.atiurin.ultron.core.compose.nodeinteraction.longClickBottomCenter
import com.atiurin.ultron.core.compose.nodeinteraction.longClickBottomLeft
import com.atiurin.ultron.core.compose.nodeinteraction.longClickBottomRight
import com.atiurin.ultron.core.compose.nodeinteraction.longClickCenterLeft
import com.atiurin.ultron.core.compose.nodeinteraction.longClickCenterRight
import com.atiurin.ultron.core.compose.nodeinteraction.longClickTopCenter
import com.atiurin.ultron.core.compose.nodeinteraction.longClickTopLeft
import com.atiurin.ultron.core.compose.nodeinteraction.longClickTopRight
import com.atiurin.ultron.core.compose.operation.ComposeOperationResult
import com.atiurin.ultron.core.compose.operation.UltronComposeOperation
import com.atiurin.ultron.core.compose.option.ComposeSwipeOption
import com.atiurin.ultron.core.compose.nodeinteraction.*
import com.atiurin.ultron.core.compose.operation.UltronComposeOperationParams
import com.atiurin.ultron.core.compose.option.ComposeSwipeOption

fun SemanticsMatcher.isSuccess(action: SemanticsMatcher.() -> Unit) = UltronComposeSemanticsNodeInteraction(this).isSuccess { action() }

Expand Down Expand Up @@ -101,6 +132,8 @@ fun SemanticsMatcher.swipeLeft(option: ComposeSwipeOption? = null) = UltronCompo

fun SemanticsMatcher.swipeRight(option: ComposeSwipeOption? = null) = UltronComposeSemanticsNodeInteraction(this).swipeRight(option)

fun SemanticsMatcher.swipe(option: ComposeSwipeOption) = UltronComposeSemanticsNodeInteraction(this).swipe(option)

fun SemanticsMatcher.scrollTo() = UltronComposeSemanticsNodeInteraction(this).scrollTo()
fun SemanticsMatcher.scrollToIndex(index: Int) = UltronComposeSemanticsNodeInteraction(this).scrollToIndex(index)
fun SemanticsMatcher.scrollToKey(key: String) = UltronComposeSemanticsNodeInteraction(this).scrollToKey(key)
Expand Down