Skip to content

Commit

Permalink
Add roborazzi.compare.output.dir gradle.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Dec 6, 2024
1 parent 10c66ac commit 9ed4b4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ data class RoborazziOptions(
}

data class CompareOptions(
val outputDirectoryPath: String = roborazziSystemPropertyOutputDirectory(),
val outputDirectoryPath: String = roborazziSystemPropertyCompareOutputDirectory(),
val imageComparator: ImageComparator = DefaultImageComparator,
val comparisonStyle: ComparisonStyle = ComparisonStyle.Grid(),
val aiAssertionOptions: AiAssertionOptions? = null,
Expand All @@ -127,7 +127,7 @@ data class RoborazziOptions(
imageComparator: ImageComparator = DefaultImageComparator,
resultValidator: (result: ImageComparator.ComparisonResult) -> Boolean = DefaultResultValidator,
): this(
outputDirectoryPath = roborazziSystemPropertyOutputDirectory(),
outputDirectoryPath = roborazziSystemPropertyCompareOutputDirectory(),
imageComparator = imageComparator,
resultValidator = resultValidator,
)
Expand All @@ -145,7 +145,7 @@ data class RoborazziOptions(
}

constructor(
outputDirectoryPath: String = roborazziSystemPropertyOutputDirectory(),
outputDirectoryPath: String = roborazziSystemPropertyCompareOutputDirectory(),
/**
* This value determines the threshold of pixel change at which the diff image is output or not.
* The value should be between 0 and 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ fun roborazziSystemPropertyOutputDirectory(): String {
return getSystemProperty("roborazzi.output.dir", DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH)
}

@ExperimentalRoborazziApi
fun roborazziSystemPropertyCompareOutputDirectory(): String {
return getSystemProperty("roborazzi.compare.output.dir", roborazziSystemPropertyOutputDirectory())
}

@ExperimentalRoborazziApi
fun roborazziSystemPropertyImageExtension(): String {
return getSystemProperty("roborazzi.record.image.extension", "png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ class MainActivity : ComponentActivity() {
file.appendText("\nroborazzi.record.filePathStrategy=relativePathFromRoborazziContextOutputDirectory")
}

fun addCompareOutputDirPathGradleProperty() {
val file = testProjectDir.root.resolve("gradle.properties")
file.appendText("\nroborazzi.compare.output.dir=build/outputs/custom_compare_outputDirectoryPath")
}

fun addRuleTest() {
val file =
testProjectDir.root.resolve("app/src/test/java/com/github/takahirom/integration_test_project/RoborazziTest.kt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,22 @@ class RoborazziGradleProjectTest {
}
}

@Test
fun compareWithGradlePropertyPath() {
RoborazziGradleRootProject(testProjectDir).appModule.apply {
addCompareOutputDirPathGradleProperty()
record()
changeScreen()
compare()

checkResultsSummaryFileExists()

checkRecordedFileExists("$screenshotAndName.testCapture.png")
checkRecordedFileExists("app/build/outputs/custom_compare_outputDirectoryPath/$className.testCapture_compare.png")
checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png")
}
}

@Test
fun secondImagesIsSkippedIfFirstVerificationFails() {
RoborazziGradleRootProject(testProjectDir).appModule.apply {
Expand Down

0 comments on commit 9ed4b4e

Please sign in to comment.