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

Support threshold in DesktopScreenshotTestRule #1603

Open
wants to merge 3 commits into
base: jb-main
Choose a base branch
from

Conversation

MatkovIvan
Copy link
Member

Adoption of approximate image comparison for internal screenshot tests from Android.

Now it reports the percentage of similarity:

Image mismatch! Comparison stats: '[MSSIM] Required SSIM: 0.96, Actual SSIM: 0.953'

and corresponding diff as a separate image:

androidx_compose_ui_platform_GraphicsLayerTest_rotationZ_diff

Fixes CMP-5310

public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Landroidx/compose/ui/test/junit4/ScreenshotResultProto$Status;
public static fun values ()[Landroidx/compose/ui/test/junit4/ScreenshotResultProto$Status;
public final class androidx/compose/ui/test/junit4/DesktopScreenshotTestRule_desktopKt {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but we need to move this out of ui-test-juint4 to a private module in the future.

val SSIMTotal = calculateSSIM(expected, given, width, height)

val stats =
"[MSSIM] Required SSIM: $threshold, Actual " + "SSIM: " + "%.3f".format(SSIMTotal)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we have this exception:

Image mismatch! Comparison stats: '[MSSIM] Required SSIM: 0.99, Actual SSIM: 0.976'

Before the change we had:

java.lang.AssertionError: java.lang.AssertionError: Image mismatch! Expected image compose/ui/ui-desktop/platform/androidx_compose_ui_platform_GraphicsLayerTest_rotationXYZ.png, actual: compose/ui/ui-desktop/platform/androidx_compose_ui_platform_GraphicsLayerTest_rotationXYZ_actual.png. FS location: /home/teamcity/agent/work/8a20760945d0aeba/golden

We need to add paths to files

* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraphicsLayerTest.scale is successful when i change scaleY:

    @Test
    fun scale() {
        val snapshot = renderComposeScene(width = 40, height = 40) {
            Box(
                Modifier
                    .graphicsLayer(
                        scaleX = 2f,
                        scaleY = 1.0f,
                        transformOrigin = TransformOrigin(0f, 0f)
                    )
                    .requiredSize(10f.dp, 10f.dp).background(Color.Red)
            )
            Box(
                Modifier
                    .graphicsLayer(
                        translationX = 10f,
                        translationY = 20f,
                        scaleX = 2f,
                        scaleY = 0.5f
                    )
                    .requiredSize(10f.dp, 10f.dp).background(Color.Blue)
            )
        }
        screenshotRule.assertImageAgainstGolden(snapshot)
    }

and set threshold to 1.00.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants