Skip to content
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

Shared repository Variable duplicate fix, Re run Failed fix and Edge … #3976

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

prashelke
Copy link
Contributor

@prashelke prashelke commented Oct 28, 2024

…browser profile and selenium arguments fix

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

    • Enhanced browser interaction capabilities with new methods for network log monitoring and improved alert handling.
    • Streamlined element information retrieval for better efficiency.
  • Bug Fixes

    • Simplified variable management during repository operations, improving clarity and functionality.
  • Refactor

    • Updated logic for execution status checks in the CLIHelper class, improving the accuracy of runset and flow status identification.
  • Style

    • Minor adjustments to comments and formatting for better readability.

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

This pull request introduces modifications to several classes within the GingerCore namespace, focusing on enhancing functionality and code clarity. Key changes include updates to the Activity class for variable handling during activity copying, improvements in the SeleniumDriver class for browser interactions and network logging, and alterations in the SharedRepositoryOperations class concerning variable management during uploads. Additionally, the CLIHelper class has been updated to utilize a new enumeration for execution status checks. Overall, these changes aim to streamline operations and improve code maintainability.

Changes

File Path Change Summary
Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs Modified CopySharedRepositoryActivity method to update FlowControl instances instead of iterating over Variables. Removed redundant handling of ParentGuid. Minor comments and formatting adjustments made.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs Added methods for network log management (StartMonitoringNetworkLog, GetNetworkLogAsync, StopMonitoringNetworkLog), refined alert handling with HandleBrowserAlert, and updated frame navigation methods. Code refactored for readability.
Ginger/GingerCoreNET/Repository/SharedRepositoryOperations.cs Removed handling of ParentGuid and Guid properties for VariableBase in UploadItemToRepository and SaveLinkedActivity. Changed initialization of TelemetryMetadata to an empty array. Error handling structure remains unchanged.
Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs Updated execution status checks to use AccountReport.Contracts.Enum.eExecutionStatus. Adjusted conditions in CheckforReRunConfig method for failed statuses while maintaining existing error handling.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

🐇 In the code where rabbits play,
Changes hop in bright array.
Activities now flow with ease,
Selenium dances in the breeze.
With logs and alerts, oh what a sight,
Code is clearer, all feels right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
Ginger/GingerCoreNET/Repository/SharedRepositoryOperations.cs (3)

107-107: Remove unnecessary empty line.

This empty line doesn't serve any purpose and affects code readability.

-

Line range hint 607-626: Consider optimizing GUID updates for large activities.

The current implementation using LINQ's Any and First inside a loop could be inefficient for activities with many actions and flow controls. Consider using a Dictionary for O(1) lookup:

- List<KeyValuePair<Guid, Guid>> oldNewActionGuidList = [];
+ Dictionary<Guid, Guid> guidMapping = new();
  foreach (Act action in sharedActivity.Acts.Cast<Act>())
  {
      if (action.ParentGuid != Guid.Empty)
      {
-         oldNewActionGuidList.Add(new(action.Guid, action.ParentGuid));
+         guidMapping[action.Guid] = action.ParentGuid;
          action.Guid = action.ParentGuid;
      }
      action.ParentGuid = Guid.Empty;
  }
  foreach (FlowControl fc in sharedActivity.Acts.SelectMany(a => a.FlowControls))
  {
      Guid targetGuid = fc.GetGuidFromValue();
-     if (oldNewActionGuidList.Any(oldNew => oldNew.Key == targetGuid))
+     if (guidMapping.TryGetValue(targetGuid, out Guid newTargetGuid))
      {
-         Guid newTargetGuid = oldNewActionGuidList.First(oldNew => oldNew.Key == targetGuid).Value;
          fc.Value = fc.Value.Replace(targetGuid.ToString(), newTargetGuid.ToString());
      }
  }

Line range hint 607-626: Add documentation for GUID management logic.

The GUID management logic is complex and critical for maintaining proper relationships. Consider adding XML documentation to explain:

  1. The purpose of GUID updates
  2. The relationship between action GUIDs and their parents
  3. The flow control GUID update process
+ /// <summary>
+ /// Updates GUIDs for actions in a shared activity:
+ /// 1. Replaces action GUIDs with their parent GUIDs
+ /// 2. Clears ParentGuid references
+ /// 3. Updates flow control references to maintain consistency
+ /// </summary>
  List<KeyValuePair<Guid, Guid>> oldNewActionGuidList = [];
Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs (1)

Based on the complete context, I can now generate the final response:

API calls need consistent error handling and null safety improvements

The code has several issues with API response handling:

  • No try-catch blocks around API calls to handle potential network or server errors
  • Inconsistent null/empty checks across different API responses:
    • GetRunsetExecutionDataFromCentralDB: Has both null and count check
    • GetRunnerExecutionDataFromCentralDB: Only has null check
    • GetBusinessflowExecutionDataFromCentralDB: Has both null and count check
  • No validation of the status values before accessing them
  • Direct string comparison for status without enum parsing validation
🔗 Analysis chain

Line range hint 354-424: Consider adding null checks and error handling for API responses.

The code assumes that the API responses will always have valid status values. It's recommended to add proper null checks and error handling.

Consider implementing a response validation helper method to ensure consistent error handling across all API responses:

private bool ValidateApiResponse<T>(IEnumerable<T> response, string context) where T : class
{
    if (response == null || !response.Any())
    {
        Reporter.ToLog(eLogLevel.INFO, $"No {context} records found for reference execution id: {mRunSetConfig.ReRunConfigurations.ReferenceExecutionID}");
        return false;
    }
    return true;
}

Let me analyze the API response handling patterns shown in the search results.

I can see that:

  1. For GetRunsetExecutionDataFromCentralDB - There's a null check and count check
  2. For GetRunnerExecutionDataFromCentralDB - There's only a null check
  3. For GetBusinessflowExecutionDataFromCentralDB - There's a null check and count check

Let me verify if there's any try-catch error handling around these API calls.


Let me try a different approach to check for error handling patterns around these API calls.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar API response handling patterns in the codebase
rg -A 5 "accountReportApiHandler\.Get.*FromCentralDB"

Length of output: 2845


Script:

#!/bin/bash
# Search for try-catch blocks around the API calls
rg -B 5 -A 10 "try.*\{.*accountReportApiHandler\.Get.*FromCentralDB" 

Length of output: 70


Script:

#!/bin/bash
# Search for the broader context around these API calls to understand error handling
rg -B 10 -A 10 "accountReportApiHandler\.Get.*FromCentralDB" --context-separator="---"

Length of output: 7431

Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs (1)

Based on the search results, I can now make a determination. The code shows:

  1. Variables are actively used and tracked in the Activity class with proper parent-child relationships
  2. In CopySharedRepositoryActivity, the code updates ParentGuid for actions but previously had variable ParentGuid updates that were removed
  3. The GingerExecutionEngine and DynamicExecutionManager (from earlier search) rely on variable ParentGuid for lookups

Warning: Removing variable ParentGuid updates could break variable tracking.

The removal of variable parent GUID updates while keeping action parent GUID updates creates an inconsistency in the shared repository activity copy process. This could lead to:

  • Broken variable lookups during execution
  • Issues with variable relationship tracking
  • Problems with dynamic execution variable mapping
🔗 Analysis chain

Line range hint 932-940: LGTM! The FlowControl GUID update logic looks correct.

The code properly updates FlowControl target GUIDs by:

  1. Collecting all FlowControls across all actions
  2. Checking if their target GUIDs exist in the oldNewActionGuidList
  3. Replacing old GUIDs with new ones in the FlowControl value

However, let's verify that removing the variable parent GUID updates doesn't cause issues elsewhere.


Let me analyze the results from the executed scripts. The search results show:

  1. The Variables.*ParentGuid usage appears primarily in test resources and configuration files, not in actual implementation code.
  2. Most occurrences are in HTML report configurations and test data, where ParentGuid is used for reference tracking.
  3. The only implementation-related references are in:
    • GingerExecutionEngine.cs - for variable lookup during execution
    • DynamicExecutionManager.cs - for customized variable handling

The search results indicate that variable ParentGuid is still actively used in the codebase for variable tracking and relationship management. Removing the variable parent GUID updates could break this functionality.

Let me verify the specific variable handling in the Activity class to make a final determination.


Let me try a different search pattern to find the variable handling code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any code that depends on Activity Variables ParentGuid

# Test: Search for variable parent GUID usage
rg -A 3 "Variables.*ParentGuid"

# Test: Search for potential variable relationship handling
ast-grep --pattern 'class $_ {
  $$$
  Variables {
    $$$
    ParentGuid
    $$$
  }
  $$$
}'

Length of output: 75094


Script:

#!/bin/bash
# Check Activity class implementation for variable handling
ast-grep --pattern 'class Activity {
  $$$
  CopyInstance($_) {
    $$$
  }
  $$$
}'

# Search for variable-related code in Activity
rg -A 3 "Variables.*Copy" Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs

Length of output: 6111


Script:

#!/bin/bash
# Search for variable handling in Activity.cs
rg -A 5 "CopySharedRepositoryActivity" Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs

# Search for variable-related code in Activity.cs
rg -A 5 "Variables\." Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs

# Look for variable parent updates
rg -A 5 "\.ParentGuid\s*=" Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs

Length of output: 6620

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 36aef18 and 6c53bd5.

📒 Files selected for processing (4)
  • Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1 hunks)
  • Ginger/GingerCoreNET/Repository/SharedRepositoryOperations.cs (1 hunks)
  • Ginger/GingerCoreNET/RunLib/CLILib/CLIHelper.cs (3 hunks)
🧰 Additional context used
📓 Learnings (1)
Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs (3)
Learnt from: Maheshkale447
PR: Ginger-Automation/Ginger#3918
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs:1271-1287
Timestamp: 2024-10-09T01:33:39.965Z
Learning: Prefers the original implementation of the `VariablesSummary` property using explicit list creation over LINQ for better readability.
Learnt from: Maheshkale447
PR: Ginger-Automation/Ginger#3918
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs:1271-1287
Timestamp: 2024-10-09T01:33:41.350Z
Learning: Prefers the original implementation of the `VariablesSummary` property using explicit list creation over LINQ for better readability.
Learnt from: Maheshkale447
PR: Ginger-Automation/Ginger#3918
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/Activity.cs:1271-1287
Timestamp: 2024-09-22T17:01:36.055Z
Learning: Prefers the original implementation of the `VariablesSummary` property using explicit list creation over LINQ for better readability.
🔇 Additional comments (3)
Ginger/GingerCoreNET/Repository/SharedRepositoryOperations.cs (1)

Line range hint 607-626: Consider adding error handling for edge cases.

While the GUID management logic is correct, consider adding error handling for scenarios where:

  1. Action GUIDs are duplicated
  2. Flow control target GUIDs are invalid
  3. ParentGuid references are circular

This will improve the robustness of the code.

Let's verify if there are any existing error cases:

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

806-806: Proper handling of UserProfileFolderPath for Edge browser

The addition of the --user-data-dir argument to EdgeOptions when UserProfileFolderPath is valid ensures that Edge uses the specified user data directory. This mirrors the behavior implemented for other browsers and promotes consistency.


812-818: Consistent addition of Selenium user arguments for Edge browser

The loop correctly adds SeleniumUserArgs to EdgeOptions, aligning the Edge browser configuration with the implementations for Chrome and Brave browsers. This enhances flexibility by allowing user-defined arguments to be passed to the Edge browser.

@Maheshkale447 Maheshkale447 merged commit 5d2151a into master Oct 28, 2024
3 checks passed
@Maheshkale447 Maheshkale447 deleted the BugFix/SharedRepositoryFix branch October 28, 2024 10:38
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.

2 participants