@@ -124,6 +124,8 @@ public void VerifyScreenshotOrSetException(
124124 ref Exception ? exception ,
125125 string ? name = null ,
126126 TimeSpan ? retryDelay = null ,
127+ int cropLeft = 0 ,
128+ int cropRight = 0 ,
127129 int cropTop = 0 ,
128130 int cropBottom = 0 ,
129131 double tolerance = 0.0
@@ -134,7 +136,7 @@ public void VerifyScreenshotOrSetException(
134136 {
135137 try
136138 {
137- VerifyScreenshot ( name , retryDelay , cropTop , cropBottom , tolerance
139+ VerifyScreenshot ( name , retryDelay , cropLeft , cropRight , cropTop , cropBottom , tolerance
138140#if MACUITEST || WINTEST
139141 , includeTitleBar
140142#endif
@@ -151,6 +153,8 @@ public void VerifyScreenshotOrSetException(
151153 /// </summary>
152154 /// <param name="name">Optional name for the screenshot. If not provided, a default name will be used.</param>
153155 /// <param name="retryDelay">Optional delay between retry attempts when verification fails.</param>
156+ /// <param name="cropLeft">Number of pixels to crop from the left of the screenshot.</param>
157+ /// <param name="cropRight">Number of pixels to crop from the right of the screenshot.</param>
154158 /// <param name="cropTop">Number of pixels to crop from the top of the screenshot.</param>
155159 /// <param name="cropBottom">Number of pixels to crop from the bottom of the screenshot.</param>
156160 /// <param name="tolerance">Tolerance level for image comparison as a percentage from 0 to 100.</param>
@@ -179,6 +183,8 @@ public void VerifyScreenshotOrSetException(
179183 public void VerifyScreenshot (
180184 string ? name = null ,
181185 TimeSpan ? retryDelay = null ,
186+ int cropLeft = 0 ,
187+ int cropRight = 0 ,
182188 int cropTop = 0 ,
183189 int cropBottom = 0 ,
184190 double tolerance = 0.0 // Add tolerance parameter (0.05 = 5%)
@@ -316,16 +322,24 @@ but both can happen.
316322 TestDevice . iOS => 40 ,
317323 _ => 0 ,
318324 } ;
319-
325+
326+ // Cropping from the left or right can be applied for any platform using the user-specified crop values.
327+ // The default values are set based on the platform, but the final cropping is determined by the parameters passed in.
328+ // This allows cropping of UI elements (such as navigation bars or home indicators) for any platform as needed.
329+ int cropFromLeft = 0 ;
330+ int cropFromRight = 0 ;
331+
332+ cropFromLeft = cropLeft > 0 ? cropLeft : cropFromLeft ;
333+ cropFromRight = cropRight > 0 ? cropRight : cropFromRight ;
320334 cropFromTop = cropTop > 0 ? cropTop : cropFromTop ;
321335 cropFromBottom = cropBottom > 0 ? cropBottom : cropFromBottom ;
322336
323- if ( cropFromTop > 0 || cropFromBottom > 0 )
337+ if ( cropFromLeft > 0 || cropFromRight > 0 || cropFromTop > 0 || cropFromBottom > 0 )
324338 {
325339 IImageEditor imageEditor = _imageEditorFactory . CreateImageEditor ( actualImage ) ;
326340 ( int width , int height ) = imageEditor . GetSize ( ) ;
327341
328- imageEditor . Crop ( 0 , cropFromTop , width , height - cropFromTop - cropFromBottom ) ;
342+ imageEditor . Crop ( cropFromLeft , cropFromTop , width - cropFromLeft - cropFromRight , height - cropFromTop - cropFromBottom ) ;
329343
330344 actualImage = imageEditor . GetUpdatedImage ( ) ;
331345 }
0 commit comments