-
Notifications
You must be signed in to change notification settings - Fork 0
Add test rule to compare screenshots #1
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
Conversation
|
|
||
| @Test | ||
| @IgnoreLogs | ||
| fun testLaunchActivity() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test to check a basic screenshot
| lastFile?.renameTo(File(this, "$key.txt")) | ||
|
|
||
| lastFile?.renameTo(File(this, key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm including the extension in the original file so no need to include it here
| } | ||
|
|
||
| kotlin { | ||
| explicitApi() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to force the classes to define their visibility.
| @@ -0,0 +1,10 @@ | |||
| package com.telefonica.loggerazzi | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a new annotation to ignore the screenshots checks and rename the logs one
| @@ -0,0 +1,33 @@ | |||
| package com.telefonica.loggerazzi | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy from dropshots, it allows you to customize the threshold
| @@ -0,0 +1,72 @@ | |||
| package com.telefonica.loggerazzi | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy from dropshots, it generates the diff image file
| @RequiresApi(Build.VERSION_CODES.O) | ||
| public fun compareScreenshot( | ||
| rule: ComposeTestRule, | ||
| name: String?, | ||
| ) { | ||
| rule.waitForIdle() | ||
| val bitmap = rule.onRoot().captureToImage().asAndroidBitmap() | ||
| compareScreenshot(bitmap, name) | ||
| } | ||
|
|
||
| public fun compareScreenshot( | ||
| activity: Activity, | ||
| name: String?, | ||
| ) { | ||
| val bitmap = Screenshot.capture(activity).bitmap | ||
| compareScreenshot(bitmap, name) | ||
| } | ||
|
|
||
| @Suppress("MemberVisibilityCanBePrivate") | ||
| public fun compareScreenshot( | ||
| bitmap: Bitmap, | ||
| name: String? | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've copied the same API that Shot has
| if (InstrumentationRegistry.getArguments().getString("record") != "true" && !isTestIgnored) { | ||
| val goldenBitmap = getGoldenBitmap(resourceName) | ||
| compareImagesSize(bitmap, goldenBitmap, fileName, name) | ||
| compareImages(bitmap, goldenBitmap, fileName, resourceName) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are not recording the baseline or this test is ignored, we compare the screenshot.
yamal-alm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good 👍
| private val loggerazziDir = File(downloadDir, "loggerazzi-logs/${context.packageName}") | ||
| private val failuresDir = File(loggerazziDir, "failures") | ||
| private val recordedDir = File(loggerazziDir, "recorded") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though we was going to stop using loggerazzi. I'm seeing it in many places (package, class names, etc), is there a renaming task in the roadmap or aren't we going to stop using that name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the rename is pending, I will do it after this
dpastor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Probably in the renaming task we can change things like "LoggerazziRule" to "LogsRule", in general to make all naming more consistent with the "generic" or "multiple" snapshoting idea of the library, but everything else looks ok!
🥅 What's the goal?
Add support for screenshot testing
🚧 How do we do it?
ScreenshotsRuletest rule to capture and check screenshots.🧪 How can I test this?