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

feat: Add mobile swipe support for Compose elements #811

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ node_modules
build
.DS_Store
.gradle/
.idea
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/appium-espresso-driver.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Appium Espresso Driver
11# Appium Espresso Driver
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved

[![Build Status](https://dev.azure.com/AppiumCI/Appium%20CI/_apis/build/status/appium.appium-espresso-driver?branchName=master)](https://dev.azure.com/AppiumCI/Appium%20CI/_build/latest?definitionId=3&branchName=master)

Expand Down Expand Up @@ -197,7 +197,12 @@ In order to change between subdrivers use the [driver](#settings-api) setting. S
- getPageSource: The returned page source is retrieved from Compose and all elements there contain [Compose-specific](#compose-element-attributes) attributes.
- click, isDisplayed, isEnabled, clear, getText, sendKeys, getElementRect, getValue, isSelected: These commands should properly support compose elements.
- getAttribute: Accepts and returns Compose-specific element attributes. See [Compose Element Attributes](#compose-element-attributes) for the full list of supported Compose element attributes.

- mobile: swipe command should properly support compose element as long as the element is swipeable.
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
Name | Type | Required | Description | Example
--- | --- | --- | --- | ---
element | string | yes | The UDID of the element to perform the swipe on. | 123456-7890-3453-24234243
direction | string | yes | Swipe direction.The following values are supported: `up`, `down`, `left`, `right`

Calling other driver element-specific APIs not listed above would most likely throw an exception as Compose and Espresso elements are being stored in completely separated internal caches and must not be mixed.

You could also check end-to-end tests for more examples on how to setup test capabilities and
Expand Down Expand Up @@ -976,7 +981,7 @@ For example, in the following arguments map
"methods":
[
{
"name": "someMethod",
"name": "someMethod"
},
{
"name": "anotherMethod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ package io.appium.espressoserver.lib.handlers
import androidx.test.espresso.UiController
import androidx.test.espresso.action.GeneralSwipeAction
import androidx.test.espresso.action.ViewActions.*
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeUp
import androidx.compose.ui.test.swipeDown
import androidx.compose.ui.test.swipeLeft
import androidx.compose.ui.test.swipeRight
import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.helpers.getNodeInteractionById
import io.appium.espressoserver.lib.handlers.exceptions.AppiumException
import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException
import io.appium.espressoserver.lib.helpers.AndroidLogger
Expand All @@ -31,7 +39,7 @@ import io.appium.espressoserver.lib.viewaction.UiControllerRunnable
class MobileSwipe : RequestHandler<MobileSwipeParams, Void?> {

@Throws(AppiumException::class)
override fun handleInternal(params: MobileSwipeParams): Void? {
override fun handleEspresso(params: MobileSwipeParams): Void? {
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
// Get a reference to the view and call onData. This will automatically scroll to the view.
val viewInteraction = EspressoElement.getViewInteractionById(params.elementId)

Expand All @@ -49,10 +57,10 @@ class MobileSwipe : RequestHandler<MobileSwipeParams, Void?> {
val runnable = object : UiControllerRunnable<Void?> {
override fun run(uiController: UiController): Void? {
val swipeAction = GeneralSwipeAction(
params.swiper,
params.startCoordinates,
params.endCoordinates,
params.precisionDescriber
params.swiper,
params.startCoordinates,
params.endCoordinates,
params.precisionDescriber
)
AndroidLogger.info("""
Performing general swipe action with parameters
Expand All @@ -68,4 +76,24 @@ class MobileSwipe : RequestHandler<MobileSwipeParams, Void?> {

return null
}

override fun handleCompose(params: MobileSwipeParams): Void? {
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
// Get a reference to the compose node
val nodeInteractions = getNodeInteractionById(params.elementId)

if (params.direction != null) {
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
AndroidLogger.info("Performing swipe action with direction '${params.direction}'")
when (params.direction) {
UP -> nodeInteractions.performTouchInput{swipeUp()}
DOWN -> nodeInteractions.performTouchInput{swipeDown()}
LEFT -> nodeInteractions.performTouchInput{swipeLeft()}
RIGHT -> nodeInteractions.performTouchInput{swipeRight()}
else -> throw InvalidArgumentException("Direction cannot be ${params.direction}")
}
} else{
throw InvalidArgumentException("Must provide direction to swipe to :up,down,right,left")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using require instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used the require instead of line 94

}

return null
}
}