Skip to content

Commit

Permalink
display AI warning as insight when optional: true
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Sep 6, 2024
1 parent 21edc14 commit 3aceb2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
11 changes: 11 additions & 0 deletions e2e/workspaces/demo_app/ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
appId: com.example.example
tags:
- android
- failing
- ai
---
- launchApp:
clearState: true
- assertWithAI:
optional: true
assertion: A login screen is visible
24 changes: 10 additions & 14 deletions maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,28 @@ class Orchestra(
)
}
Insights.onInsightsUpdated(callback)

try {
try {
executeCommand(evaluatedCommand, config)
onCommandComplete(index, command)
} catch (e: MaestroException) {
val isOptional = command.asCommand()?.optional == true
if (isOptional) throw CommandWarned
if (isOptional) throw CommandWarned(e.message)
else throw e
}
} catch (ignored: CommandWarned) {
// Swallow exception
// Swallow exception, but add a warning as an insight
Insights.report(Insight(message = ignored.message, level = Insight.Level.WARNING))
onCommandWarned(index, command)
} catch (ignored: CommandSkipped) {
// Swallow exception
onCommandSkipped(index, command)
} catch (e: Throwable) {
when (onCommandFailed(index, command, e)) {
val errorResolution = onCommandFailed(index, command, e)
when (errorResolution) {
ErrorResolution.FAIL -> return false
ErrorResolution.CONTINUE -> {
// Do nothing
}
ErrorResolution.CONTINUE -> {} // Do nothing
}
}
Insights.unregisterListener(callback)
Expand Down Expand Up @@ -362,12 +363,10 @@ class Orchestra(
if (defects.isNotEmpty()) {
onCommandGeneratedOutput(command, defects, imageData)

if (command.optional) throw CommandWarned

val word = if (defects.size == 1) "defect" else "defects"
throw MaestroException.AssertionFailure(
"Found ${defects.size} possible $word. See the report after the test completes to learn more.",
maestro.viewHierarchy().root,
message = "Found ${defects.size} possible $word. See the report after the test completes to learn more.",
hierarchyRoot = maestro.viewHierarchy().root,
)
}

Expand All @@ -392,9 +391,6 @@ class Orchestra(

if (defect != null) {
onCommandGeneratedOutput(command, listOf(defect), imageData)

if (command.optional) throw CommandWarned

throw MaestroException.AssertionFailure(
message = """
|Assertion is false: ${command.assertion}
Expand Down Expand Up @@ -1201,7 +1197,7 @@ class Orchestra(

private object CommandSkipped : Exception()

private object CommandWarned : Exception()
class CommandWarned(override val message: String) : Exception(message)

data class CommandMetadata(
val numberOfRuns: Int? = null,
Expand Down

0 comments on commit 3aceb2f

Please sign in to comment.