Skip to content

Commit

Permalink
KasperskyLab#249. Reverted the previous behavior of ObjectAutoScrollP…
Browse files Browse the repository at this point in the history
…roviderImpl
  • Loading branch information
matzuk committed Nov 14, 2021
1 parent c8aa36b commit 44f3bbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,36 @@ class ObjectAutoScrollProviderImpl(
* @return the result of [action] invocation.
*/
override fun <T> scroll(interaction: UiObjectInteraction, action: () -> T, cachedError: Throwable): T {
return try {
// Looks for a scrollable content
val scrollable = UiScrollable(UiSelector().scrollable(true))
// Scrolls to the bottom and looks for the given view. Invokes the action if the view was found.
scrollable.scrollForward()
logger.i("UiObject autoscroll successfully performed.")
action.invoke()
} catch (error: Throwable) {
logger.i("UiObject autoscroll did not help. Throwing exception.")
throw cachedError
}
/**
* Looks for a scrollable content
*/
val scrollable = UiScrollable(UiSelector().scrollable(true))

/**
* Scrolls to the bottom and looks for the given view. Invokes the action if the view was found.
*/
do {
if (interaction.uiObject2 != null) {
logger.i("UiObject autoscroll to the bottom successfully performed.")
return action.invoke()
} else {
interaction.reCalculateUiObject()
}
} while (scrollable.scrollForward())

/**
* Scrolls to the beginning and looks for the given view. Invokes the action if the view was found.
*/
do {
if (interaction.uiObject2 != null) {
logger.i("UiObject autoscroll to the beginning successfully performed.")
return action.invoke()
} else {
interaction.reCalculateUiObject()
}
} while (scrollable.scrollBackward())

logger.i("UiObject autoscroll did not help. Throwing exception.")
throw cachedError
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ElementLoaderObjectBehaviorInterceptor(
assertion: UiObjectAssertion,
activity: () -> T
): T = passAction(
elementLoader = { interaction.reFindUiObject() },
elementLoader = { interaction.reCalculateUiObject() },
action = activity
)

Expand All @@ -43,7 +43,7 @@ class ElementLoaderObjectBehaviorInterceptor(
action: UiObjectAction,
activity: () -> T
): T = passAction(
elementLoader = { interaction.reFindUiObject() },
elementLoader = { interaction.reCalculateUiObject() },
action = activity
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FlakySafeObjectBehaviorInterceptor(
assertion: UiObjectAssertion,
activity: () -> T
): T = flakySafely(action = {
interaction.reFindUiObject()
interaction.reCalculateUiObject()
activity.invoke()
})

Expand All @@ -47,7 +47,7 @@ class FlakySafeObjectBehaviorInterceptor(
action: UiObjectAction,
activity: () -> T
): T = flakySafely(action = {
interaction.reFindUiObject()
interaction.reCalculateUiObject()
activity.invoke()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UiObjectInteraction(
action.execute(uiObject2 ?: throw UnfoundedUiObjectException(selector))
}

fun reFindUiObject() {
fun reCalculateUiObject() {
uiObject2 = calculateUiObject()
}

Expand Down

0 comments on commit 44f3bbd

Please sign in to comment.