Skip to content

Updated IOs screenshot fixed#4347

Merged
prashelke merged 2 commits into
Releases/Official-Releasefrom
BugFix/IOSscreenshotFix
Oct 18, 2025
Merged

Updated IOs screenshot fixed#4347
prashelke merged 2 commits into
Releases/Official-Releasefrom
BugFix/IOSscreenshotFix

Conversation

@prashelke

@prashelke prashelke commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Added cross-platform element screenshot cropping and location extraction to improve how element images are captured and displayed.
  • Bug Fixes

    • Improved error handling and logging during element screenshot operations.
    • Added device-aware logic so screenshots are processed correctly across mobile platforms.

@coderabbitai

coderabbitai Bot commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Added 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

Cohort / File(s) Summary
Element screenshot helpers & flow
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs
Added public TakeElementScreenShot(ElementInfo, Bitmap) to crop element region and return PNG Base64; added public GetLocationAndSizeOfElement(ElementInfo, out int, out int, out int, out int) to parse bounds (supports "[x,y][x2,y2]" and x/y/width/height); updated element-screenshot flow to branch by device type (Android -> existing General.TakeElementScreenShot, otherwise -> new helper) and added exception logging with null fallback for element images.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

🐰 I hopped through code with careful art,

Cropped a pixel, gave each part,
Android kept its old-time tune,
Others got helpers — quick as lune,
Base64 carrots, captured bright. 📸🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description consists entirely of the contributor checklist template copied verbatim with no items checked and no substantive content added. While the template structure is present, the description fails to provide any actual explanation of the changes made, which directly contradicts the first checklist item stating "PR description and commit message should describe the changes done in this PR." The author has not filled in details about what was fixed, why it was necessary, or how the implementation works, leaving the description largely empty of meaningful information. Add a substantive description above or within the checklist that explains the changes, such as: what iOS screenshot issue was fixed, what helper methods were added (TakeElementScreenShot and GetLocationAndSizeOfElement), how the device-type-aware logic improves the implementation, and why these changes were necessary. The description should document the actual changes, not just include the template checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Updated IOs screenshot fixed" directly relates to the changeset, which adds element screenshot helper methods and device-type-aware logic for handling screenshots across platforms, specifically addressing iOS (as indicated by the branch name "BugFix/IOSscreenshotFix"). The title clearly identifies iOS screenshot handling as the primary focus of this change. While the phrasing is slightly awkward and could be more descriptive about the technical implementation (adding helper methods), it does effectively communicate the main change from a high-level perspective that a teammate would understand when scanning the project history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BugFix/IOSscreenshotFix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 63bfca2 and 3dfe64b.

📒 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)

Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / GetLocationAndSizeOfElement are copy/paste twins of the implementations in GingerCoreNET.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

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfe64b and bf4eef5.

📒 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)

@prashelke
prashelke enabled auto-merge October 18, 2025 08:26
@prashelke
prashelke merged commit 28594ae into Releases/Official-Release Oct 18, 2025
10 checks passed
@prashelke
prashelke deleted the BugFix/IOSscreenshotFix branch October 18, 2025 08:26
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

Successfully merging this pull request may close these issues.

1 participant