Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add descriptions to missing element selector aspects #2111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ data class ElementSelector(
descriptions.add("id: $it")
}

enabled?.let {
when(enabled){
true -> descriptions.add("enabled")
false -> descriptions.add("disabled")
}
}

below?.let {
descriptions.add("Below ${it.description()}")
}
Expand Down Expand Up @@ -119,6 +126,20 @@ data class ElementSelector(
descriptions.add("Index: ${it.toDoubleOrNull()?.toInt() ?: it}")
}

selected?.let {
when(selected){
true -> descriptions.add("selected")
false -> descriptions.add("not selected")
}
}

focused?.let {
when(focused){
true -> descriptions.add("focused")
false -> descriptions.add("not focused")
}
}

childOf?.let {
descriptions.add("Child of: ${it.description()}")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package maestro.orchestra

import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
import kotlin.math.truncate

class ElementSelectorTest {
@Test
fun `simple text description`(){
val command = AssertConditionCommand(
condition = Condition(
visible = ElementSelector(
textRegex = "Hello"
)
)
)

assertThat(command.description()).isEqualTo("Assert that \"Hello\" is visible")
}

@Test
fun `simple id description`(){
val command = AssertConditionCommand(
condition = Condition(
visible = ElementSelector(
idRegex = "hello_element"
)
)
)

assertThat(command.description()).isEqualTo("Assert that id: hello_element is visible")
}

@Test
fun `description with optional`(){
val command = AssertConditionCommand(
condition = Condition(
visible = ElementSelector(
textRegex = "Hello"
)
),
optional = true
)

assertThat(command.description()).isEqualTo("Assert that (Optional) \"Hello\" is visible")
}

@Test
fun `description with enabled`(){
val command = AssertConditionCommand(
condition = Condition(
visible = ElementSelector(
textRegex = "Hello",
enabled = false
)
)
)

assertThat(command.description()).isEqualTo("Assert that \"Hello\", disabled is visible")
}

@Test
fun `complex description`(){
val command = AssertConditionCommand(
condition = Condition(
visible = ElementSelector(
textRegex = "Hello",
idRegex = "hello_element",
enabled = false,
below = ElementSelector(
textRegex = "World"
),
above = ElementSelector(
idRegex = "page_break_element"
),
leftOf = ElementSelector(
textRegex = "Right"
),
rightOf = ElementSelector(
idRegex = "left_element"
),
containsChild = ElementSelector(
idRegex = "hello_emoji_container"
),
containsDescendants = listOf(
ElementSelector(
idRegex = "hello_emoji"
),
ElementSelector(
idRegex = "hello_emoji_text"
),
ElementSelector(
idRegex = "have_been_greeted",
checked = true
)
),
index = "0",
selected = false,
focused = false,
childOf = ElementSelector(
textRegex = "Welcome Screen"
)
)
)
)

assertThat(command.description()).isEqualTo("Assert that \"Hello\", id: hello_element, disabled, Below \"World\", Above id: page_break_element, Left of \"Right\", Right of id: left_element, Contains child: id: hello_emoji_container, Contains descendants: [id: hello_emoji, id: hello_emoji_text, id: have_been_greeted], Index: 0, not selected, not focused, Child of: \"Welcome Screen\" is visible")
}
}
Loading