Updated IOs screenshot fixed#4347
Conversation
WalkthroughAdded two public helpers to GenericAppiumDriver for extracting element bounds and cropping element screenshots; element screenshot flow now branches on device type (Android uses existing implementation; others use new helper). Error handling for screenshot capture was added. Changes
Sequence DiagramsequenceDiagram
participant App as Application
participant GAD as GenericAppiumDriver
participant Helper as New Helpers
participant Platform as DevicePlatform
App->>GAD: Request element screenshot (ElementInfo, fullImage)
GAD->>Platform: Check device type
alt Android
GAD->>GAD: Call General.TakeElementScreenShot(EI, fullImage)
GAD-->>App: Return element image (Base64) or null
else Other platforms
GAD->>Helper: TakeElementScreenShot(EI, fullImage)
Helper->>Helper: GetLocationAndSizeOfElement(EI)
Helper->>Helper: Clamp & crop fullImage to bounds
Helper->>Helper: Encode PNG -> Base64
Helper-->>GAD: Return Base64 or throw
GAD-->>App: Return element image (Base64) or null (on error)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs (2)
2692-2707: Inconsistent error handling between similar code blocks.Lines 2692-2700 lack the try-catch error handling that lines 2703-2707 have. Both blocks perform element screenshot operations and should have consistent error handling to prevent crashes.
Consider wrapping lines 2692-2700 in a try-catch block similar to lines 2703-2707:
+ try + { if(DevicePlatformType == eDevicePlatformType.Android) { EI.ScreenShotImage = GingerCoreNET.GeneralLib.General.TakeElementScreenShot(EI, fullImage); } else { - //EI.ScreenShotImage = GingerCoreNET.GeneralLib.General.TakeElementScreenShot(EI, fullImage); EI.ScreenShotImage = TakeElementScreenShot(EI, fullImage); } - + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, $"Skipping element due to screen-shot error: {ex.Message}", ex); + EI.ScreenShotImage = null; + }Then remove the duplicate try-catch at lines 2703-2707.
2716-2719: Empty catch block suppresses errors.The empty catch block silently swallows exceptions without logging or handling them. This makes debugging difficult and can hide important errors.
Add appropriate error logging:
catch(Exception ex) { - + Reporter.ToLog(eLogLevel.ERROR, "Failed to trigger fine tune with AI", ex); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs (2)
Ginger/GingerCoreNET/Drivers/DriversWindow/IMobileDriverWindow.cs (1)
eDevicePlatformType(35-35)Ginger/GingerCoreNET/GeneralLib/General.cs (3)
General(60-1494)TakeElementScreenShot(1219-1276)GetLocationAndSizeOfElement(1278-1323)
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs (1)
2732-2837: Remove the duplicated screenshot helpers.
GenericAppiumDriver.TakeElementScreenShot/GetLocationAndSizeOfElementare copy/paste twins of the implementations inGingerCoreNET.GeneralLib.General. Keeping two public copies guarantees drift (we already have behavior differences). Once the shared helper is patched with the invalid-dimension return, please delete these duplicates (or at most keep a private wrapper that simply delegates) so the logic lives in one place.-public static string TakeElementScreenShot(ElementInfo elementInfo, Bitmap fullImage) -{ - // copy of General.TakeElementScreenShot(...) -} - -public static void GetLocationAndSizeOfElement(ElementInfo elementInfo, out int cropX, out int cropY, out int cropWidth, out int cropHeight) -{ - // copy of General.GetLocationAndSizeOfElement(...) -} +// After fixing GingerCoreNET.GeneralLib.General.TakeElementScreenShot/GetLocationAndSizeOfElement, +// call those directly instead of maintaining duplicate code here.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-07-26T22:04:12.930Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#3429
File: Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs:1139-1142
Timestamp: 2024-07-26T22:04:12.930Z
Learning: The user has updated the code by removing or addressing the commented code as suggested in the review.
Applied to files:
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs
🧬 Code graph analysis (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs (1)
Ginger/GingerCoreNET/GeneralLib/General.cs (3)
General(60-1494)TakeElementScreenShot(1219-1276)GetLocationAndSizeOfElement(1278-1323)
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
Bug Fixes