Repository navigation
Description
Related #136
Related #4
Related rstudio/chromote#96
Rounded corners are not being produced consistently on the same platforms. Shadows and borders are particularly difficult as they are being calculated with a bit of randomness. I believe this is due to inconsistent sub pixel rounding and/or snapping.
Related chromium issues:
- Issue 937273: Different rounding for subpixel border vs outline - https://bugs.chromium.org/p/chromium/issues/detail?id=937273&q=subpixel%20snapping&can=2
- Issue 1313330: Color picker's border displays incorrectly in high contrast mode - https://bugs.chromium.org/p/chromium/issues/detail?id=1313330
- Issue 1267773: One-off pixel error on layer - https://bugs.chromium.org/p/chromium/issues/detail?id=1267773#c9
This was originally addressed in #136 by not adjusting the screen size within {chromote}. While the output cards were addressed, the change in {chromote} did not fix all rounded corner issues.
Example:
See red corners of both the modal and focused text in the image below. Red color means that a difference was found using the command gm compare old.png new.png -highlight-style assign -file diff.png.
Proposal:
Add a compare function to AppDriver$expect_sreenshot(compare=). Add a new comparison method that computes a "difference" metric and compare it against a set threshold.
The current compare function is set to testthat::compare_file_binary(old, new).
Proposed shinytest2::image_threshold(threshold = 0, size = 100) algorithm:
- Compare images using
testthat::compare_file_binary()- If successful, return success
- Read in red, green, blue changes of each file
- Find abs differences in each channel for each file
- If threshold == 0 || size <= 1
- Return
sum(abs_diffs) == 0
- Return
- Run convolution over diff matrix using a kernal w/ width and height set to
size total = sum(convo_vals)- Return
total < threshold
Implementation would be done using {cpp11}.

Activity
bersbersbers commentedon Jun 23, 2022
Sorry to hear that #136 did not fix all rounded corners.
In addition, I have come across a potentially related case which I like to report here so it can maybe inform the improved image comparison algorithm. Namely, with sliders:
I have yet to 100% exclude the possibility that this is timing-related, but so far, I don't have much reason to believe it is. Edit: I have already added 3-s waits before taking these snapshots, and the issue still comes up from time to time. With 5-s wait, it currently looks stable, but I somehow feel I only have to wait some more time for it to come back.
schloerke commentedon Jun 23, 2022
@bersbersbers Could you reply with the two snapshot files? It'll help me play with different threshold values recommendations. Thank you!
bersbersbers commentedon Jun 23, 2022
@schloerke sure, here they are. I cropped the full snapshots to the slider area since it's a non-public Shiny app, but since I did everything based on PNG files, these operations should all be lossless.
jhen1115 commentedon Sep 12, 2022
Hi,
May I know if the below red points around Back button relates to this issue (rounded corners are not consistent) as well?
Because I found that the screenshots sometimes passed and sometimes failed in Linux, so I created small example to test in Linux and Windows.
The generated screenshots in Windows more stable than Linux, but it still has this issue when I rerun the test many times in Windows (for example, please refer to Rerun_Tests.txt, the screenshots were different when the test was reran 64 times, but the "64" will be changed everytime. Sometimes, the screenshots were all passed when rerunning for 100 times).
The generated 2 png files as below:


schloerke commentedon Sep 12, 2022
@jhen1115 Exactly this situation. 😞
@jhen1115 @bersbersbers, would you be willing to try a PR for me?
I've added a fuzzy image comparison method that sweeps across the image and looks at the differences within a square kernel. If any absolute sum of the differences is larger than the
threshold, then an error is thrown letting us know the images are different.With the default kernel size of 5 and 4 color channels, the max value is
5 * 5 * 4=100. This value will change given the kernel size.The code below using
thresholdshould be more stable.@bersbersbers You can also supply your own comparison method if you'd like.
app$expect_screenshot(compare = METHOD). If you have a method you like to use, I'd be keen to add it to the package.Thank you!
Using @jhen1115 's two images and #231...
... therefore a
thresholdvalue of0.1should be safe to use for this image.Ex:
bersbersbers commentedon Sep 14, 2022
@schloerke sorry for the delayed response - I am currently working non-R mostly, and the few times I have gone back to
shinytest2, I actually haven't come across this issue any more (which is not too surprising giving the tremendous amount of updates of related CRAN packages). I'll try this PR (well, main branch now, I guess) this weekend to see if it breaks anything, but there will be limited information from this test as nothing else is broken at this time :)jhen1115 commentedon Sep 14, 2022
@schloerke Hi, I will check the the development version and get back to you this week.
jhen1115 commentedon Sep 15, 2022
@schloerke Hi, I tested the development version in Windows and Linux, please find the findings as below.
And may I know how to decide the value of threshold? If we only can decide the value of threshold when we find the small issues in screenshots?
app$expect_screenshot(threshold = 0.1)is work, and the session information and Chrome version as below:The generated 2 png files as below:
The difference value, session information, and Chrome version as below:
schloerke commentedon Sep 15, 2022
@jhen1115 So
thresholdis an experimental value. I'd guess that a max difference of < 1 means you have fairly similar images. The default max value is 5 * 5 * 4 = 100. So finding a max diff of 0.78 means that "Given a 5x5 pixel kernel and 4 color channels, it found that 0.78 / (5 * 5 * 4) * 100% = 0.78% difference between the two photos".Pseudo code:
My interpretation from small empirical testing of the max value between two screenshots...
If it is < 5, then it is close enough, otherwise I treat it as a different picture. So I would set the
thresholdto 5. But each user has different needs and that value could be 20 or it could even be 0 /NULL.Odd that Chrome made the whole top left corner different. Haven't seen that before!
Thank you for testing!!
If
thresholdis too annoying to set or things do not make sense, please open a new issue. I am hoping to release{shinytest2}next weekjhen1115 commentedon Sep 16, 2022
@schloerke Thank you for your explanation, it's very helpful! The
thresholdcan help us to ignore those small issues (such as rounded corners and top left corner different), and I'm looking forward to the release. Thank you!bersbersbers commentedon Sep 16, 2022
Hi,
I have tested the main branch (6610a28, I believe) and it's working fine technically.
Doing so, I have come across (first time in a while, but that's unrelated, I think) across the issue from #220 (comment). So I played around with the thresholds, and what I find it despite this being small shifts, the intensity change in a single pixel is rather larger. For my full images, I get:
which I interpret as 28% for 5x5 and 17% for 8x8 - rather large values to set as a global threshold for comparison.
Just noting that here, keeping in mind that the original issue is about rounded corners and not subpixel position changes in text (but ultimately these can lead to the same user frustration).
I wonder if one might set an average threshold as well (averaging the convolution value over the whole image) and comparing that to a threshold, and/or allow a defined number of pixels to fail while still accepting the snapshot (allthough I assume the number if failing pixels is still rather large in my case). Either way, it seems that
AppDriver$expect_sreenshot(compare=)gives me/us enough freedom to explore such approaches - thank you :)schloerke commentedon Sep 16, 2022
Exactly!
28.11 / (5 * 5 * 4) = 28.11%
44.988 / (8 * 8 * 4) = 17.57%
Agreed, these values are fairly large as the numbers and ticks have shifted. Agreed that it can / will lead to the same user frustration as text shifting.
Would it work to use a large kernel? Something like 30 or 50? If it is a small set of large differences, then the max value should roughly stay the same as a smaller kernel.
Ex:
kernel_size = 50;
Max possible value = 10k
So a difference of 45 / 10k is 0.45%.
The speed of the algorithm actually gets faster the larger the kernel size. (
O((m - k)(n - k));m,nis image size;kiskernel_size)Yes! If you settle on a
compare_screenshot_pixels(max = )(or similar) method, please open an issue. I'd be happy to add more comparison methods.schloerke commentedon Sep 16, 2022
Thank you both for the quick feedbacks!