Skip to content

Commit

Permalink
feat: extend selector options
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKohan committed Oct 16, 2024
1 parent a0938e1 commit 9a6f069
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,14 @@ data class EraseTextCommand(

data class TakeScreenshotCommand(
val path: String,
val targetComponentId: String? = null,
val cropOn: ElementSelector?,
override val label: String? = null,
override val optional: Boolean = false,
) : Command {

override fun description(): String {
return label ?: if (targetComponentId != null) {
"Take screenshot $path, cropped on component with id $targetComponentId"
return label ?: if (cropOn != null) {
"Take screenshot $path, cropped to ${cropOn.description()}"
} else {
"Take screenshot $path"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,15 @@ class Orchestra(

private fun takeScreenshotCommand(command: TakeScreenshotCommand): Boolean {
val pathStr = command.path + ".png"
val targetComponent = command.targetComponentId?.let { maestro.findElementByIdRegex(regex = Regex(it), timeoutMs = 100) }

val cropped = command.cropOn?.let { findElement(it, optional = command.optional) }
val file = screenshotsDir
?.let { File(it, pathStr) }
?: File(pathStr)

if(targetComponent == null){
if(cropped == null){
maestro.takeScreenshot(file.sink(), false)
}else{
maestro.takePartialScreenshot(sink = file.sink(), bounds = targetComponent.bounds, compressed = false)
maestro.takePartialScreenshot(sink = file.sink(), bounds = cropped.element.bounds, compressed = false)
}

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ data class YamlFluentCommand(
hideKeyboard != null -> listOf(MaestroCommand(HideKeyboardCommand(label = hideKeyboard.label, optional = hideKeyboard.optional)))
pasteText != null -> listOf(MaestroCommand(PasteTextCommand(label = pasteText.label, optional = pasteText.optional)))
scroll != null -> listOf(MaestroCommand(ScrollCommand(label = scroll.label, optional = scroll.optional)))
takeScreenshot != null -> listOf(MaestroCommand(TakeScreenshotCommand(path = takeScreenshot.path, label = takeScreenshot.label, optional = takeScreenshot.optional, targetComponentId = takeScreenshot.targetComponentId)))
takeScreenshot != null -> listOf(
MaestroCommand(
TakeScreenshotCommand(
path = takeScreenshot.path,
label = takeScreenshot.label,
optional = takeScreenshot.optional,
cropOn = takeScreenshot.cropOn?.let { toElementSelector(selectorUnion = it) })
)
)

extendedWaitUntil != null -> listOf(extendedWait(extendedWaitUntil))
stopApp != null -> listOf(
MaestroCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
data class YamlTakeScreenshot(
val path: String,
val label: String? = null,
val targetComponentId: String? = null,
val cropOn: YamlElementSelectorUnion? = null,
val optional: Boolean = false,
) {

Expand Down

0 comments on commit 9a6f069

Please sign in to comment.