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

Commit

Permalink
add timeout for assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedictP committed Sep 12, 2023
1 parent 5c7684a commit 60af8ca
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.getyourguide.uitestglazesample

import androidx.test.uiautomator.UiDevice
import kotlin.time.Duration.Companion.seconds

internal class AssertionHelper(private val findUiElementHelper: FindUiElementHelper) {

companion object {
private val TIMEOUT_TO_FIND_ELEMENT = 3.seconds
}

fun assert(
assertion: Assertion,
hierarchy: TreeNode,
Expand All @@ -16,6 +21,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
) != null
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is visible")
Expand All @@ -28,6 +34,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
) == null
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is not visible")
Expand All @@ -40,6 +47,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
)?.checked != true
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is not checked")
Expand All @@ -51,6 +59,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
)?.checked != false
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is checked")
Expand All @@ -61,6 +70,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
)?.enabled != true
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is not enabled")
Expand All @@ -71,6 +81,7 @@ internal class AssertionHelper(private val findUiElementHelper: FindUiElementHel
hierarchy = hierarchy,
optional = true,
device = uiDevice,
timeoutToGetAnUiElement = TIMEOUT_TO_FIND_ELEMENT,
)?.enabled != false
) {
throw IllegalStateException("Assertion: $assertion failed. UiElement is enabled")
Expand Down

0 comments on commit 60af8ca

Please sign in to comment.