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

feat: add cropOn screenshots capability #2086

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add test cases
  • Loading branch information
TheKohan authored and Fishbowler committed Jan 4, 2025
commit 88d57b0e16451301b6715f177ed42e4e2d70a993
39 changes: 39 additions & 0 deletions maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ import java.io.File
import java.nio.file.Paths
import kotlin.system.measureTimeMillis
import maestro.orchestra.util.Env.withDefaultEnvVars
import javax.imageio.ImageIO

class IntegrationTest {

@@ -3279,6 +3280,44 @@ class IntegrationTest {
assertThat(action).isEqualTo(targetAction)
}

@Test
fun `Case 122 - Take cropped screenshot`() {
// Given
val commands = readCommands("122_take_cropped_screenshot")
val boundHeight = 100
val boundWidth = 100

val driver = driver {
element {
id = "element_id"
bounds = Bounds(0,0,boundHeight,boundWidth)
}
}

val device = driver.deviceInfo()
val dpr = device.heightPixels / device.heightGrid

// When
Maestro(driver).use {
orchestra(it).runFlow(commands)
}

// Then
// No test failure
driver.assertEvents(
listOf(
Event.TakeScreenshot,
)
)
val file = File("122_take_cropped_screenshot_with_filename.png")
val image = ImageIO.read(file)

assert(file.exists())
assert(image.width == (boundWidth * dpr))
assert(image.height == (boundHeight * dpr))
}


private fun orchestra(
maestro: Maestro,
) = Orchestra(
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appId: com.example.app
---
- takeScreenshot:
path: ${MAESTRO_FILENAME}_with_filename
cropOn:
id: element_id