Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Added inputShouldBeRecognizedTimeout parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedictP committed Jan 9, 2024
1 parent 1d8d2d5 commit 1d3b39f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## [Unreleased]

# [1.1.8] - 2024-01-09

Changed:
- Added `inputShouldBeRecognizedTimeout` parameter to `inputText` method to ensure we recognize a hierarchy change after entering a text.

# [1.1.7] - 2023-12-15

Changed
Expand Down Expand Up @@ -166,9 +171,10 @@ New:

Initial release.

[unreleased]: https://github.com/getyourguide/UiTestGlaze/compare/1.1.7...HEAD
[1.1.5]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.7
[1.1.5]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.6
[unreleased]: https://github.com/getyourguide/UiTestGlaze/compare/1.1.8...HEAD
[1.1.8]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.8
[1.1.7]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.7
[1.1.6]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.6
[1.1.5]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.5
[1.1.4]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.4
[1.1.3]: https://github.com/getyourguide/UiTestGlaze/releases/tag/1.1.3
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.7'
PUBLISH_VERSION = '1.1.8'
PUBLISH_ARTIFACT_ID = 'uitestglaze'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.getyourguide.uitestglazesample

import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import kotlin.time.Duration

internal class InputTextHelper(
private val getHierarchyHelper: GetHierarchyHelper,
Expand All @@ -14,6 +15,7 @@ internal class InputTextHelper(
device: UiDevice,
hierarchy: TreeNode,
numberOfRetries: Int,
inputShouldBeRecognizedTimeout: Duration,
) {
var isEnteringTextSuccessfully: Boolean
var currentHierarchy = hierarchy
Expand Down Expand Up @@ -84,6 +86,20 @@ internal class InputTextHelper(
if (!isEnteringTextSuccessfully) {
throw IllegalStateException("Can not enter text")
}

val startTime = System.currentTimeMillis()
var hierarchyChanged = false
do {
val hierarchyAfterEnteringText = getHierarchyHelper.getHierarchy(device)
if (hierarchy != hierarchyAfterEnteringText) {
hierarchyChanged = true
break
}
} while ((System.currentTimeMillis() - startTime) < inputShouldBeRecognizedTimeout.inWholeMilliseconds)

if (!hierarchyChanged) {
throw IllegalStateException("Hierarchy did not change after entering text")
}
}

private fun enterText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ data class UiTestGlaze(
*
* @param text Text to input.
* @param uiElementIdentifier Identifier of the element to input text.
* @param numberOfRetries Number of times to retry if the input is not recognized.
* @param numberOfRetries Number of times to retry if the input is not entered.
* @param inputShouldBeRecognizedTimeout Timeout to wait till the input is recognized.
*/
fun inputText(
text: String,
uiElementIdentifier: UiElementIdentifier,
numberOfRetries: Int = 3,
inputShouldBeRecognizedTimeout: Duration = 10.seconds,
) {
val hierarchy = hierarchySettleHelper.waitTillHierarchySettles(
config.loadingResourceIds,
Expand All @@ -241,6 +243,7 @@ data class UiTestGlaze(
device = device,
hierarchy = hierarchy,
numberOfRetries = numberOfRetries,
inputShouldBeRecognizedTimeout = inputShouldBeRecognizedTimeout
)
}

Expand Down

0 comments on commit 1d3b39f

Please sign in to comment.