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

Fix the issue where errors are ignored and occur when changing the size during GIF recording. #210

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class ManualTest {
.captureRoboImage()

// Capture Jetpack Compose Node
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.onParent()
.captureRoboImage("build/compose.png")
}
Expand All @@ -280,7 +280,7 @@ Roborazzi supports the following APIs.
</td><td>

```kotlin
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.captureRoboImage()
```

Expand Down Expand Up @@ -635,7 +635,7 @@ fun SampleComposableFunction() {
) {
Box(
Modifier
.testTag("MyComposeButton")
.testTag("AddBoxButton")
.size(50.dp)
.clickable {
count++
Expand Down Expand Up @@ -676,7 +676,7 @@ class ComposeTest {
}
(0 until 3).forEach { _ ->
composeTestRule
.onNodeWithTag("MyComposeButton")
.onNodeWithTag("AddBoxButton")
.performClick()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ internal class DifferBufferedImage(private val bufferedImage: BufferedImage) : I
get() = bufferedImage.width

override fun getPixel(x: Int, y: Int): Color {
if (width <= x || height <= y) {
// Waiting for dropbox differs next release to support size difference
return Color(0, 0, 0, 0)
}
return Color(bufferedImage.getRGB(x, y))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.core.IsEqual
import java.io.File
import java.util.Locale
import java.util.*

fun ViewInteraction.captureRoboImage(
filePath: String = DefaultFileNameGenerator.generateFilePath("png"),
Expand Down Expand Up @@ -246,6 +246,7 @@ fun SemanticsNodeInteraction.captureRoboGif(
).apply {
saveGif(fileWithRecordFilePathStrategy(filePath))
clear()
result.getOrThrow()
}
}

Expand All @@ -260,6 +261,7 @@ fun SemanticsNodeInteraction.captureRoboGif(
captureComposeNode(composeRule, roborazziOptions, block).apply {
saveGif(file)
clear()
result.getOrThrow()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -61,27 +58,40 @@ class FirstFragment : Fragment() {

@Composable
fun SampleComposableFunction() {
var count by remember { mutableStateOf(0) }
var count by remember { mutableStateOf(2) }
Column(
Modifier
.size(300.dp)
.testTag("MyColumn")
) {
Box(
Text(
text = "Add",
Modifier
.testTag("MyComposeButton")
.testTag("AddBoxButton")
.background(Color.Gray)
.size(50.dp)
.clickable {
count++
}
)
(0 until count).forEach {
Text(
text = "Sub",
Modifier
.testTag("SubBoxButton")
.background(Color.Gray)
.clickable {
count--
}
)
(0 until count).forEach { index ->
Box(
Modifier
.background(Color.Red)
.testTag("child:$it")
.size(30.dp)
)
.testTag("child:$index")
.size(25.dp)
) {
Text(
text = "$index/$count"
)
}
}
}
}
3 changes: 2 additions & 1 deletion sample-android/src/main/res/layout/fragment_first.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
android:id="@+id/compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ComposeSetContentTest {
}
(0 until 3).forEach { _ ->
composeTestRule
.onNodeWithTag("MyComposeButton")
.onNodeWithTag("AddBoxButton")
.performClick()
}
} catch (e: Exception) {
Expand All @@ -73,7 +73,7 @@ fun SampleComposableFunction() {
) {
Box(
Modifier
.testTag("MyComposeButton")
.testTag("AddBoxButton")
.size(50.dp)
.clickable {
count++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ComposeTest {
}
(0 until 3).forEach { _ ->
composeTestRule
.onNodeWithTag("MyComposeButton")
.onNodeWithTag("AddBoxButton")
.performClick()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.material3.Text
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onParent
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
Expand Down Expand Up @@ -68,7 +67,7 @@ class ManualTest {

@Test
fun captureComposeImage() {
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.onParent()
.captureRoboImage()
}
Expand Down Expand Up @@ -134,10 +133,10 @@ class ManualTest {
)
)

composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.performClick()

composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.performClick()
composeTestRule.waitForIdle()

Expand Down Expand Up @@ -220,16 +219,16 @@ class ManualTest {
qualifiers = "w150dp-h200dp",
)
fun captureRoboGifSampleCompose() {
composeTestRule.onRoot(false)
composeTestRule.onNodeWithTag("MyColumn")
.captureRoboGif(
composeTestRule,
"$DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH/manual_captureRoboGifSampleCompose.gif"
) {
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("SubBoxButton")
.performClick()
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.performClick()
composeTestRule.onNodeWithTag("MyComposeButton")
composeTestRule.onNodeWithTag("AddBoxButton")
.performClick()
}
}
Expand Down