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

Generated diff image does not show all differences #327

Open
simonwalter opened this issue Dec 9, 2022 · 0 comments
Open

Generated diff image does not show all differences #327

simonwalter opened this issue Dec 9, 2022 · 0 comments

Comments

@simonwalter
Copy link

We have a lot of red/reddish elements in the UI of our app and we realised that changes in those elements are not reflected in the diff images of the Shot verification report.

ℹ️ This test result shows a screenshot test in which an orange button has been moved slightly downwards. The change is correctly identified by Shot, but it's not clear from the diff image.

image

Expected behaviour

All differences between the original and the new screenshot are visible in the diff images in the verification report.

Actual behaviour

Differences of some elements are not visible in the diff images in the verification report: This mostly happens with red elements. But in the example below it also happens for green and blue elements when they are placed on black background.

Steps to reproduce

I created a test with a simple UI to reproduce the problem:

package example.test

import android.graphics.Color
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.TextView
import androidx.test.platform.app.InstrumentationRegistry
import com.karumi.shot.ScreenshotTest
import org.junit.Test

class ColorScreenshotTest : ScreenshotTest {

    private val textViewGravity = Gravity.LEFT  // change to Gravity.RIGHT for the verification run

    @Test
    fun colorTestBlack() {
        actualTest(backgroundColor = Color.BLACK)
    }

    @Test
    fun colorTestWhite() {
        actualTest(backgroundColor = Color.WHITE)
    }

    private fun actualTest(backgroundColor: Int) {
        val context = InstrumentationRegistry.getInstrumentation().targetContext

        val view = LinearLayout(context).apply {
            orientation = LinearLayout.VERTICAL
            setBackgroundColor(backgroundColor)

            addView(
                TextView(context).apply {
                    textSize = 30f
                    text = "Red text"
                    setTextColor(Color.RED)

                    gravity = textViewGravity
                }
            )

            addView(
                TextView(context).apply {
                    textSize = 30f
                    text = "Green text"
                    setTextColor(Color.GREEN)

                    gravity = textViewGravity
                }
            )

            addView(
                TextView(context).apply {
                    textSize = 30f
                    text = "Blue text"
                    setTextColor(Color.BLUE)

                    gravity = textViewGravity
                }
            )
        }

        compareScreenshot(
            view = view,
            heightInPx = 500,
            widthInPx = 500
        )
    }
}

image

Version of the library

5.14.1

More information

I guess that this is related to the RedComposite from the scrimage library which is used to merge the original and the new screenshot to create the diff image.

val diff = newImage.composite(new RedComposite(1d), originalImage)

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

No branches or pull requests

1 participant