Skip to content

Commit

Permalink
add option to scroll vertical up
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedictP committed Sep 14, 2023
1 parent 1ac8b55 commit 0e88d0d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## [Unreleased]

# [1.1.3] - 2023-09-14

Added:
- Option to scroll vertical up to an element `ScrollOption.VerticalUpToElement`
- Option to scroll vertical up `ScrollOption.VerticalUp`

# [1.1.2] - 2023-09-13

Changed:
Expand Down Expand Up @@ -137,7 +143,8 @@ New:

Initial release.

[unreleased]: https://github.com/getyourguide/UiTestGlaze/compare/1.1.2...HEAD
[unreleased]: https://github.com/getyourguide/UiTestGlaze/compare/1.1.3...HEAD
[1.1.2]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.3
[1.1.2]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.2
[1.1.1]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.1
[1.1.0]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.0
Expand Down
2 changes: 1 addition & 1 deletion uiTestGlaze/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

ext {
PUBLISH_GROUP_ID = 'io.github.getyourguide'
PUBLISH_VERSION = '1.1.2'
PUBLISH_VERSION = '1.1.3'
PUBLISH_ARTIFACT_ID = 'uitestglaze'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ internal class ScrollHelper(
)
}

is ScrollOption.VerticalUpToElement -> {
scrollVerticalUpToElement(
config,
scrollOption.toUiElement,
scrollOption.inUiElement,
device,
)
}

is ScrollOption.HorizontalRight -> {
scrollHorizontalRight(
device,
Expand All @@ -35,6 +44,10 @@ internal class ScrollHelper(
scrollVerticalDown(device, scrollOption.inUiElement)
}

is ScrollOption.VerticalUp -> {
scrollVerticalUp(device, scrollOption.inUiElement)
}

is ScrollOption.HorizontalRightToElement -> scrollHorizontalRightToElement(
config,
scrollOption.toUiElement,
Expand Down Expand Up @@ -71,6 +84,22 @@ internal class ScrollHelper(
device.executeShellCommand("input swipe $startAndEndXPosition $startYPosition $startAndEndXPosition $endYPosition")
}

private fun scrollVerticalUp(
device: UiDevice,
inUiElement: UiElementIdentifier,
) {
val foundInUIElement = findUiElementHelper.getUiElement(
inUiElement,
getHierarchyHelper.getHierarchy(device),
true,
device,
) ?: throw IllegalStateException("Could not find element to scroll in")
val startAndEndXPosition = foundInUIElement.x + foundInUIElement.width / 2
val startYPosition = foundInUIElement.y + foundInUIElement.height * 0.3
val endYPosition = foundInUIElement.y + foundInUIElement.height * 0.7
device.executeShellCommand("input swipe $startAndEndXPosition $startYPosition $startAndEndXPosition $endYPosition")
}

private fun scrollHorizontalRight(
device: UiDevice,
inUiElement: UiElementIdentifier,
Expand Down Expand Up @@ -118,6 +147,17 @@ internal class ScrollHelper(
}
}

private fun scrollVerticalUpToElement(
config: UiTestGlaze.Config,
toUiElement: UiElementIdentifier,
inUiElement: UiElementIdentifier,
device: UiDevice,
) {
scroll(config, device, inUiElement, toUiElement) {
scrollVerticalUp(device, inUiElement)
}
}

private fun scroll(
config: UiTestGlaze.Config,
device: UiDevice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ sealed interface ScrollOption {
*/
data class VerticalDown(val inUiElement: UiElementIdentifier) : ScrollOption

/**
* Scroll vertical up.
*
* @param inUiElement UiElement to scroll in.
*/
data class VerticalUp(val inUiElement: UiElementIdentifier) : ScrollOption

/**
* Scroll vertical up.
*
Expand Down Expand Up @@ -389,6 +396,17 @@ sealed interface ScrollOption {
val inUiElement: UiElementIdentifier,
) : ScrollOption

/**
* Scroll vertical up to a given UiElement.
*
* @param toUiElement UiElement to scroll to.
* @param inUiElement UiElement to scroll in.
*/
data class VerticalUpToElement(
val toUiElement: UiElementIdentifier,
val inUiElement: UiElementIdentifier,
) : ScrollOption

/**
* Scroll vertical up to a given UiElement.
*
Expand Down

0 comments on commit 0e88d0d

Please sign in to comment.