Skip to content

Brave Browser Agent#3716

Merged
Maheshkale447 merged 8 commits into
masterfrom
Feature/BraveBrowserSupportSelenium
Jun 7, 2024
Merged

Brave Browser Agent#3716
Maheshkale447 merged 8 commits into
masterfrom
Feature/BraveBrowserSupportSelenium

Conversation

@GokulBothe

@GokulBothe GokulBothe commented May 20, 2024

Copy link
Copy Markdown
Collaborator

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

    • Introduced support for the Brave browser using Selenium in various methods and configurations.
  • Enhancements

    • Added Brave browser-specific settings and logic, including executable paths and user arguments.
    • Refactored Chrome browser configuration to support both Chrome and Brave browsers.
  • Bug Fixes

    • Updated methods to include the new SeleniumBrave driver type, ensuring comprehensive support across the application.

@coderabbitai

coderabbitai Bot commented May 20, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The recent updates introduce support for the Brave browser in the Selenium-based automation framework. This includes adding a new driver type SeleniumBrave, integrating it into the existing driver management system, and configuring the necessary settings and executable paths for the Brave browser. The changes span multiple files, enhancing the framework's flexibility and browser compatibility.

Changes

File(s) Change Summary
Ginger/Ginger/DotNetFrameworkHelper.cs Added support for SeleniumBrave in GetDriverObject and GetDriverType methods.
Ginger/GingerCoreCommon/RunLib/Agent.cs Added SeleniumBrave to the eDriverType enum and updated related methods to support this new driver type.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs Added Brave to the eBrowserType enum, introduced BrowserExecutablePath property, and refactored browser configuration for Chrome and Brave.
Ginger/GingerCoreNET/RunLib/DriverInfo.cs Included SeleniumBrave in the list of supported driver types in the GetDriver method.

Poem

In the realm of code so bright,
Brave joins the browser fight,
Selenium's new knight.
With paths and types all set to go,
Automation's bound to grow,
Brave steps in with a glow,
Making testing quite a show!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@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: 3

Out of diff range and nitpick comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

104-104: Add a description for the new Brave enum value.

It's good practice to include a description for each enum value, similar to other values in this enum, to improve code readability and maintainability.


413-413: Consider removing or implementing the commented-out code.

It's generally a good practice to avoid leaving commented-out code in production code as it can lead to confusion and clutter. If this setting is necessary, consider implementing it; otherwise, it should be removed.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cf2ee81 and cab44be.
Files selected for processing (4)
  • Ginger/Ginger/DotNetFrameworkHelper.cs (2 hunks)
  • Ginger/GingerCoreCommon/RunLib/Agent.cs (5 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (8 hunks)
  • Ginger/GingerCoreNET/RunLib/DriverInfo.cs (1 hunks)
Additional comments not posted (9)
Ginger/GingerCoreNET/RunLib/DriverInfo.cs (1)

123-123: Addition of SeleniumBrave to the driver services list is correctly implemented.

Verification successful

The search results indicate that SeleniumBrave is referenced in the following files:

  • Ginger/GingerCoreNET/RunLib/DriverInfo.cs
  • Ginger/GingerCoreCommon/RunLib/Agent.cs
  • Ginger/Ginger/DotNetFrameworkHelper.cs

To ensure proper integration, let's review the context and usage of SeleniumBrave in Agent.cs and DotNetFrameworkHelper.cs.


The integration of SeleniumBrave appears to be consistent and thorough across the codebase. The references in Agent.cs and DotNetFrameworkHelper.cs show that SeleniumBrave is treated similarly to other Selenium-based drivers, ensuring it is included in relevant switch cases and driver type lists.

  • Agent.cs includes SeleniumBrave in driver type descriptions, switch cases for driver support, platform type determination, and driver type lists.
  • DotNetFrameworkHelper.cs includes SeleniumBrave in switch cases for creating SeleniumDriver instances and determining driver types.

These integrations confirm that SeleniumBrave is properly added and handled in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of SeleniumBrave with other components.

# Test: Search for references to `SeleniumBrave` in other relevant files.
rg --type csharp 'SeleniumBrave'

Length of output: 663



Script:

#!/bin/bash
# Description: Review the context and usage of SeleniumBrave in Agent.cs and DotNetFrameworkHelper.cs.

# Display lines around the references to SeleniumBrave in Agent.cs
rg --type csharp --context 5 'SeleniumBrave' Ginger/GingerCoreCommon/RunLib/Agent.cs

# Display lines around the references to SeleniumBrave in DotNetFrameworkHelper.cs
rg --type csharp --context 5 'SeleniumBrave' Ginger/Ginger/DotNetFrameworkHelper.cs

Length of output: 3341

Ginger/GingerCoreCommon/RunLib/Agent.cs (4)

71-72: Addition of SeleniumBrave to the eDriverType enum is correctly implemented.


224-224: Update to IsSupportRecording to include SeleniumBrave is correctly implemented.


333-333: Update to GetDriverPlatformType to include SeleniumBrave is correctly implemented.


371-371: Update to GetDriverTypesByPlatfrom to include SeleniumBrave is correctly implemented.

Verification successful

The integration of SeleniumBrave appears to be correctly implemented across multiple files. Here are the key points confirming its integration:

  • Ginger/GingerCoreNET/RunLib/DriverInfo.cs: SeleniumBrave is added to the services list for the Web platform type.
  • Ginger/GingerCoreCommon/RunLib/Agent.cs: SeleniumBrave is included in various switch cases and driver type lists, ensuring it is recognized and handled appropriately.
  • Ginger/Ginger/DotNetFrameworkHelper.cs: SeleniumBrave is mapped to the SeleniumDriver with the Brave browser type.

These references indicate that SeleniumBrave is integrated consistently with other driver types.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of SeleniumBrave with other components.

# Test: Search for references to `SeleniumBrave` in other relevant files.
rg --type csharp 'SeleniumBrave'

Length of output: 663



Script:

#!/bin/bash
# Extract relevant code snippets for detailed examination.

# Extract the snippet from DriverInfo.cs
rg --type csharp --context 5 'SeleniumBrave' Ginger/GingerCoreNET/RunLib/DriverInfo.cs

# Extract the snippet from Agent.cs
rg --type csharp --context 5 'SeleniumBrave' Ginger/GingerCoreCommon/RunLib/Agent.cs

# Extract the snippet from DotNetFrameworkHelper.cs
rg --type csharp --context 5 'SeleniumBrave' Ginger/Ginger/DotNetFrameworkHelper.cs

Length of output: 4037

Ginger/Ginger/DotNetFrameworkHelper.cs (2)

106-107: Addition of SeleniumBrave to GetDriverObject method is correctly implemented.


154-154: Addition of SeleniumBrave to GetDriverType method is correctly implemented.

Verification successful

The integration of SeleniumBrave appears to be correctly implemented across multiple files in the codebase. The references found in DriverInfo.cs and Agent.cs indicate that SeleniumBrave is being utilized appropriately.

  • Ginger/GingerCoreNET/RunLib/DriverInfo.cs
  • Ginger/GingerCoreCommon/RunLib/Agent.cs
  • Ginger/Ginger/DotNetFrameworkHelper.cs
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of SeleniumBrave with other components.

# Test: Search for references to `SeleniumBrave` in other relevant files.
rg --type csharp 'SeleniumBrave'

Length of output: 663

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

458-458: Validate the existence of SeleniumUserArguments before splitting.

Ensure that SeleniumUserArguments is defined and checked before use to avoid potential runtime errors.

Verification successful

The SeleniumUserArguments property is properly defined and checked for null or empty values before being used in the SeleniumDriver.cs file. Here are the relevant lines:

  • Definition: public string SeleniumUserArguments { get; set; }
  • Checks before usage:
    • if (!string.IsNullOrEmpty(SeleniumUserArguments))
    • if (!(String.IsNullOrEmpty(SeleniumUserArguments) && String.IsNullOrWhiteSpace(SeleniumUserArguments)))
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `SeleniumUserArguments` is defined and used properly elsewhere in the codebase.

# Test: Search for the definition and usage of `SeleniumUserArguments`. Expect: Proper definition and checks before usage.
rg --type csharp $'SeleniumUserArguments'

Length of output: 1193


1020-1020: Ensure proper cleanup of driver processes.

It's crucial to ensure that the driver processes are properly cleaned up to prevent resource leaks, especially in the case of exceptions or errors.

Comment on lines +822 to +940
private void chromeDriverconfig(ChromeOptions options)
{

options.AddArgument("--start-maximized");
SetCurrentPageLoadStrategy(options);
SetBrowserLogLevel(options);
SetUnhandledPromptBehavior(options);
SetBrowserVersion(options);
if (IsUserProfileFolderPathValid())
{
options.AddArguments("user-data-dir=" + UserProfileFolderPath);
}
else if (!string.IsNullOrEmpty(ExtensionPath))
{
string[] extensionPaths = ExtensionPath.Split(';');
options.AddExtensions(extensionPaths);
}

//setting proxy
SetProxy(options);

//DownloadFolderPath
if (!string.IsNullOrEmpty(DownloadFolderPath))
{
if (!System.IO.Directory.Exists(DownloadFolderPath))
{
System.IO.Directory.CreateDirectory(DownloadFolderPath);
}
options.AddUserProfilePreference("download.default_directory", DownloadFolderPath);
}

if (BrowserPrivateMode == true)
{
options.AddArgument("--incognito");
}

if (HeadlessBrowserMode == true || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
options.AddArgument("--headless=new");
}

if (SeleniumUserArgs != null)
{
foreach (string arg in SeleniumUserArgs)
{
options.AddArgument(arg);
}
}

if (!string.IsNullOrEmpty(EmulationDeviceName))
{
options.EnableMobileEmulation(EmulationDeviceName);
}
else if (!string.IsNullOrEmpty(BrowserUserAgent))
{
options.AddArgument("--user-agent=" + BrowserUserAgent.Trim());
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey);
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl);
}

if (!string.IsNullOrEmpty(DebugAddress))
{
options.DebuggerAddress = DebugAddress.Trim();
}

driverService = ChromeDriverService.CreateDefaultService();

AddCustomDriverPath(driverService);

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
}

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{
//If the os is alpine linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
}

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.

Review and optimize the chromeDriverconfig method.

The chromeDriverconfig method is quite lengthy and handles multiple responsibilities. Consider breaking it down into smaller, more focused methods to improve readability and maintainability. Additionally, ensure that all configurations are necessary and correctly applied.

[UserConfigured]
[UserConfiguredDefault("")]
[UserConfiguredDescription("Provide the path to the browser executable.")]
public string BrowserExcutablePath { get; set; }

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.

Ensure the property name is correctly spelled.

- public string BrowserExcutablePath { get; set; }
+ public string BrowserExecutablePath { get; set; }

Typographical errors in property names can lead to confusion and errors in usage. It's important to correct this to BrowserExecutablePath.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public string BrowserExcutablePath { get; set; }
public string BrowserExecutablePath { get; set; }

Comment on lines +570 to +588
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
var braveBrowser32 = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
var braveBrowser64 = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
if (BrowserExcutablePath != null && BrowserExcutablePath.Trim().Length > 0 && File.Exists(BrowserExcutablePath)) {

brave_options.BinaryLocation = BrowserExcutablePath;
}

if (!string.IsNullOrEmpty(DebugAddress))
{
options.DebuggerAddress = DebugAddress.Trim();
else if (File.Exists(braveBrowser64)) {
brave_options.BinaryLocation = braveBrowser64;
}

driverService = ChromeDriverService.CreateDefaultService();

AddCustomDriverPath(driverService);

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
else if (File.Exists(braveBrowser32)) {
brave_options.BinaryLocation = braveBrowser32;
}
else {
throw new Exception("Brave browser valid executable path required!");

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{
//If the os is alpine linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
chromeDriverconfig(brave_options);

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.

Refactor to simplify the setting of BinaryLocation.

- var braveBrowser32 = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
- var braveBrowser64 = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
- if (BrowserExcutablePath != null && BrowserExcutablePath.Trim().Length > 0 && File.Exists(BrowserExcutablePath)) { 
-     brave_options.BinaryLocation = BrowserExcutablePath;
- }
- else if (File.Exists(braveBrowser64)) {
-     brave_options.BinaryLocation = braveBrowser64;
- }
- else if (File.Exists(braveBrowser32)) {
-     brave_options.BinaryLocation = braveBrowser32;
- }
- else { 
-     throw new Exception("Brave browser valid executable path required!");
- }
+ string defaultPath = BrowserExcutablePath ?? braveBrowser64 ?? braveBrowser32;
+ if (!string.IsNullOrEmpty(defaultPath) && File.Exists(defaultPath)) {
+     brave_options.BinaryLocation = defaultPath;
+ } else {
+     throw new Exception("Brave browser valid executable path required!");
+ }

This refactor simplifies the logic for setting the BinaryLocation by using a more streamlined approach, reducing redundancy and improving readability.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
var braveBrowser32 = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
var braveBrowser64 = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
if (BrowserExcutablePath != null && BrowserExcutablePath.Trim().Length > 0 && File.Exists(BrowserExcutablePath)) {
brave_options.BinaryLocation = BrowserExcutablePath;
}
if (!string.IsNullOrEmpty(DebugAddress))
{
options.DebuggerAddress = DebugAddress.Trim();
else if (File.Exists(braveBrowser64)) {
brave_options.BinaryLocation = braveBrowser64;
}
driverService = ChromeDriverService.CreateDefaultService();
AddCustomDriverPath(driverService);
if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
else if (File.Exists(braveBrowser32)) {
brave_options.BinaryLocation = braveBrowser32;
}
else {
throw new Exception("Brave browser valid executable path required!");
try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{
//If the os is alpine linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");
if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";
//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
chromeDriverconfig(brave_options);
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
string defaultPath = BrowserExcutablePath ?? braveBrowser64 ?? braveBrowser32;
if (!string.IsNullOrEmpty(defaultPath) && File.Exists(defaultPath)) {
brave_options.BinaryLocation = defaultPath;
} else {
throw new Exception("Brave browser valid executable path required!");
}
chromeDriverconfig(brave_options);

@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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cab44be and 6c398e5.
Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs

@GokulBothe
GokulBothe requested a review from Maheshkale447 May 20, 2024 13:05
//checking the windows 32 and 64 bit version exists or not. if not then user can provide the path mannually.
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
var braveBrowser32 = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";

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.

Declare constant strings for both paths

@Maheshkale447
Maheshkale447 requested a review from MeniKadosh1 May 20, 2024 20:39

@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: 5

Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1)

206-206: Ensure consistent naming convention for properties.

The property BrowserExecutablePath is inconsistently named compared to EdgeExcutablePath. Consider renaming to BrowserExecutablePath to BrowserExecutablePath for consistency.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6c398e5 and 76f041d.
Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (8 hunks)
Additional comments not posted (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

106-106: Addition of Brave to eBrowserType enum.

This change is necessary to support the new Brave browser functionality. Ensure that all references to this enum are updated accordingly.


460-460: Handle potential null or empty SeleniumUserArguments.

Ensure that SeleniumUserArguments is not null or empty before splitting to avoid runtime errors.

Verification successful

The results indicate that SeleniumUserArguments is declared as a property and is used multiple times in the SeleniumDriver.cs file. The usages include checks for null or empty values using string.IsNullOrEmpty and String.IsNullOrWhiteSpace, which are appropriate for handling potential null or empty values.

Key Findings:

  • Declaration: public string SeleniumUserArguments { get; set; }
  • Usages:
    • if (!string.IsNullOrEmpty(SeleniumUserArguments))
    • SeleniumUserArgs = SeleniumUserArguments.Split(';');
    • if (!(String.IsNullOrEmpty(SeleniumUserArguments) && String.IsNullOrWhiteSpace(SeleniumUserArguments)))
    • ieoptions.BrowserCommandLineArguments += "," + SeleniumUserArguments;
    • ieOptions.BrowserCommandLineArguments += "," + SeleniumUserArguments;

Conclusion:

The code already includes checks to ensure that SeleniumUserArguments is not null or empty before it is used. Therefore, the concern mentioned in the review comment is already addressed in the code.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `SeleniumUserArguments` is always initialized before use.

# Test: Search for the initialization of `SeleniumUserArguments`. Expect: Initialization before use.
rg --type csharp $'SeleniumUserArguments ='

Length of output: 44



Script:

#!/bin/bash
# Description: Verify the declaration and usage of `SeleniumUserArguments` in the codebase.

# Step 1: Search for the declaration of `SeleniumUserArguments`.
rg --type csharp --word-boundary 'SeleniumUserArguments'

# Step 2: Search for all instances where `SeleniumUserArguments` is used.
rg --type csharp 'SeleniumUserArguments'

# Step 3: Check if there are any null or empty checks before its usage.
rg --type csharp --word-boundary 'SeleniumUserArguments' | xargs -I {} rg --type csharp 'if\s*\(\s*SeleniumUserArguments\s*==\s*null\s*\|\|\s*SeleniumUserArguments\s*==\s*""\s*\)' {}

Length of output: 2331



Script:

#!/bin/bash
# Description: Verify the declaration and usage of `SeleniumUserArguments` in the codebase.

# Step 1: Search for the declaration of `SeleniumUserArguments`.
rg --type csharp --word-regexp 'SeleniumUserArguments'

# Step 2: Search for all instances where `SeleniumUserArguments` is used.
rg --type csharp 'SeleniumUserArguments'

# Step 3: Check if there are any null or empty checks before its usage.
rg --type csharp --word-regexp 'SeleniumUserArguments' | xargs -I {} rg --type csharp 'if\s*\(\s*SeleniumUserArguments\s*==\s*null\s*\|\|\s*SeleniumUserArguments\s*==\s*""\s*\)' {}

Length of output: 4013

Comment on lines +824 to +940
private void chromeDriverconfig(ChromeOptions options)
{

options.AddArgument("--start-maximized");
SetCurrentPageLoadStrategy(options);
SetBrowserLogLevel(options);
SetUnhandledPromptBehavior(options);
SetBrowserVersion(options);
if (IsUserProfileFolderPathValid())
{
options.AddArguments("user-data-dir=" + UserProfileFolderPath);
}
else if (!string.IsNullOrEmpty(ExtensionPath))
{
string[] extensionPaths = ExtensionPath.Split(';');
options.AddExtensions(extensionPaths);
}

SetProxy(options);

if (!string.IsNullOrEmpty(DownloadFolderPath))
{
if (!System.IO.Directory.Exists(DownloadFolderPath))
{
System.IO.Directory.CreateDirectory(DownloadFolderPath);
}
options.AddUserProfilePreference("download.default_directory", DownloadFolderPath);
}

if (BrowserPrivateMode == true)
{
options.AddArgument("--incognito");
}

if (HeadlessBrowserMode == true || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
options.AddArgument("--headless=new");
}

if (SeleniumUserArgs != null)
{
foreach (string arg in SeleniumUserArgs)
{
options.AddArgument(arg);
}
}

if (!string.IsNullOrEmpty(EmulationDeviceName))
{
options.EnableMobileEmulation(EmulationDeviceName);
}
else if (!string.IsNullOrEmpty(BrowserUserAgent))
{
options.AddArgument("--user-agent=" + BrowserUserAgent.Trim());
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey);
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl);
}

if (!string.IsNullOrEmpty(DebugAddress))
{
options.DebuggerAddress = DebugAddress.Trim();
}

driverService = ChromeDriverService.CreateDefaultService();

AddCustomDriverPath(driverService);

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
}

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
}

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.

Review extensive configuration method for ChromeOptions.

The chromeDriverconfig method is quite extensive and handles multiple responsibilities. Consider breaking this method into smaller, more focused methods to improve readability and maintainability.

Comment on lines +572 to +589
//checking the windows 32 and 64 bit version exists or not. if not then user can provide the path mannually.
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
if (BrowserExecutablePath != null && BrowserExecutablePath.Trim().Length > 0 && File.Exists(BrowserExecutablePath)) {

AddCustomDriverPath(driverService);
brave_options.BinaryLocation = BrowserExecutablePath;
}
else if (File.Exists(BRAVE_64BIT_BINARY_PATH)) {
brave_options.BinaryLocation = BRAVE_64BIT_BINARY_PATH;
}
else if (File.Exists(BRAVE_32BIT_BINARY_PATH)) {
brave_options.BinaryLocation = BRAVE_32BIT_BINARY_PATH;
}
else {
throw new Exception("Brave browser valid executable path required!");

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
}

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{
//If the os is alpine linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
}
chromeDriverconfig(brave_options);

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.

Refactor handling of Brave browser binary paths.

The current implementation for determining the Brave browser binary path is verbose and hard to maintain. Consider refactoring this into a separate method to improve readability and maintainability.

- if (BrowserExecutablePath != null && BrowserExecutablePath.Trim().Length > 0 && File.Exists(BrowserExecutablePath)) { 
-     brave_options.BinaryLocation = BrowserExecutablePath;
- } else if (File.Exists(BRAVE_64BIT_BINARY_PATH)) {
-     brave_options.BinaryLocation = BRAVE_64BIT_BINARY_PATH;
- } else if (File.Exists(BRAVE_32BIT_BINARY_PATH)) {
-     brave_options.BinaryLocation = BRAVE_32BIT_BINARY_PATH;
- } else { 
-     throw new Exception("Brave browser valid executable path required!");
- }
+ SetBraveBinaryPath(brave_options);

Committable suggestion was skipped due low confidence.

@GokulBothe
GokulBothe requested a review from Maheshkale447 May 30, 2024 08:58
private const string EDGE_DRIVER_NAME = "msedgedriver";
private const string FIREFOX_DRIVER_NAME = "geckodriver";
private const string TRANSLATOR_FOR_CASE_INSENSITIVE_MATCH = "translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
private const string BRAVE_32BIT_BINARY_PATH = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";

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.

not good practice to put static paths in code, this may change by user and not supporting Linux.
i recoomand to have dedicated AgentPAram for it and set it as default for the 64 bit path

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

'BrowserExecutablePath' is a new generic param added for all web agents, Ginger will automatically detect the brave path using this static path, in case it not available on mentioned path, user can provide his custom browser path in new BrowserExecutablePath param.

{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl);
}
chromeDriverconfig(options);

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.

Change function name to ConfigChromeDriverAndStart

@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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76f041d and 13a96b1.

Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (8 hunks)
Additional context used
Learnings (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)
User: prashelke
PR: Ginger-Automation/Ginger#3429
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:1581-1616
Timestamp: 2024-01-05T14:23:27.219Z
Learning: The user has implemented the use of `using` statements for `Bitmap` objects and added a `finally` block to clear the `bitmapsToMerge` list. They have also handled exceptions that may occur during bitmap operations.
User: prashelke
PR: Ginger-Automation/Ginger#3429
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:1581-1616
Timestamp: 2024-01-05T14:23:27.219Z
Learning: The user has implemented the use of `using` statements for `Bitmap` objects and added a `finally` block to clear the `bitmapsToMerge` list. They have also handled exceptions that may occur during bitmap operations.
Additional comments not posted (3)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (3)

106-106: Addition of Brave browser type to enum looks good.


203-207: Proper use of user-configurable attributes for BrowserExecutablePath.


460-460: Proper handling of Selenium user arguments.

Comment on lines +94 to +95
private const string BRAVE_32BIT_BINARY_PATH = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";
private const string BRAVE_64BIT_BINARY_PATH = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe";

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.

Consider using configuration for hardcoded paths.

The hardcoded paths for the Brave browser binaries could lead to issues in environments where the browser is installed in a different directory. Consider using a configuration setting to specify these paths, which can be adjusted per environment.

{
//Close launched driver process as it does not gets closed by Selenium in case of exception
if (driverService?.ProcessId != 0)
if (driverService != null && driverService.ProcessId != 0)

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.

Ensure proper resource management in CloseDriverProcess.

The CloseDriverProcess method attempts to close the driver process if it is still running. However, the catch block is empty, which means any exceptions thrown by Process.GetProcessById(driverService.ProcessId)?.Kill() will be silently ignored. This could potentially lead to resource leaks if the process is not successfully terminated.

  • Consider logging the exception in the catch block to ensure any issues are recorded and can be addressed.

//System.Environment.SetEnvironmentVariable("NO_PROXY", @"http://localhost");

DriverService driverService = null;

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.

Incomplete code fragment detected.

This line appears to be an incomplete code fragment. Please ensure that the implementation is completed or remove this fragment if it's not needed.

Comment on lines +572 to +589
//checking the windows 32 and 64 bit version exists or not. if not then user can provide the path mannually.
case eBrowserType.Brave:
ChromeOptions brave_options = new ChromeOptions();
if (BrowserExecutablePath != null && BrowserExecutablePath.Trim().Length > 0 && File.Exists(BrowserExecutablePath)) {

AddCustomDriverPath(driverService);
brave_options.BinaryLocation = BrowserExecutablePath;
}
else if (File.Exists(BRAVE_64BIT_BINARY_PATH)) {
brave_options.BinaryLocation = BRAVE_64BIT_BINARY_PATH;
}
else if (File.Exists(BRAVE_32BIT_BINARY_PATH)) {
brave_options.BinaryLocation = BRAVE_32BIT_BINARY_PATH;
}
else {
throw new Exception("Brave browser valid executable path required!");

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
}

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{
//If the os is alpine linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
}
configChromeDriverAndStart(brave_options);

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.

Improve exception handling for Brave browser configuration.

Consider providing a more informative error message when the Brave browser executable path is not found. For example, include suggestions on how to resolve the issue or where to specify the custom path.

Comment on lines +823 to +940
//created common method for Chrome and Brave browser because both support ChromeDriver
private void configChromeDriverAndStart(ChromeOptions options)
{

options.AddArgument("--start-maximized");
SetCurrentPageLoadStrategy(options);
SetBrowserLogLevel(options);
SetUnhandledPromptBehavior(options);
SetBrowserVersion(options);
if (IsUserProfileFolderPathValid())
{
options.AddArguments("user-data-dir=" + UserProfileFolderPath);
}
else if (!string.IsNullOrEmpty(ExtensionPath))
{
string[] extensionPaths = ExtensionPath.Split(';');
options.AddExtensions(extensionPaths);
}

SetProxy(options);

if (!string.IsNullOrEmpty(DownloadFolderPath))
{
if (!System.IO.Directory.Exists(DownloadFolderPath))
{
System.IO.Directory.CreateDirectory(DownloadFolderPath);
}
options.AddUserProfilePreference("download.default_directory", DownloadFolderPath);
}

if (BrowserPrivateMode == true)
{
options.AddArgument("--incognito");
}

if (HeadlessBrowserMode == true || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
options.AddArgument("--headless=new");
}

if (SeleniumUserArgs != null)
{
foreach (string arg in SeleniumUserArgs)
{
options.AddArgument(arg);
}
}

if (!string.IsNullOrEmpty(EmulationDeviceName))
{
options.EnableMobileEmulation(EmulationDeviceName);
}
else if (!string.IsNullOrEmpty(BrowserUserAgent))
{
options.AddArgument("--user-agent=" + BrowserUserAgent.Trim());
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiKey);
}

if (!(String.IsNullOrEmpty(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl) && String.IsNullOrWhiteSpace(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl)))
{
options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl);
}

if (!string.IsNullOrEmpty(DebugAddress))
{
options.DebuggerAddress = DebugAddress.Trim();
}

driverService = ChromeDriverService.CreateDefaultService();

AddCustomDriverPath(driverService);

if (HideConsoleWindow)
{
driverService.HideCommandPromptWindow = HideConsoleWindow;
}

try
{
Driver = new ChromeDriver((ChromeDriverService)driverService, options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
this.mDriverProcessId = driverService.ProcessId;
}
catch (Exception ex)
{

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ex.Message.ToLower().Contains("no such file or directory"))
{
Reporter.ToLog(eLogLevel.INFO, "Chrome binary isn't found at default location, checking for Chromium...");

if (Directory.GetFiles(@"/usr/bin", "chromium-browser.*").Length > 0 && Directory.GetFiles(@"/usr/lib/chromium", "chromedriver.*").Length > 0)
{
options.BinaryLocation = @"/usr/bin/chromium-browser";

//List of Chromium Command Line Switches
//https://peter.sh/experiments/chromium-command-line-switches/
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--start-maximized");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(@"/usr/lib/chromium", options, TimeSpan.FromSeconds(Convert.ToInt32(HttpServerTimeOut)));
}
else
{
throw ex;
}
}
else
{
throw ex;
}
}
}

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.

Refactor handling of HideConsoleWindow in configChromeDriverAndStart.

Consider refactoring the handling of the HideConsoleWindow property to ensure it is set correctly based on user configuration and not just set to hide by default. This will enhance configurability and user control over the driver behavior.

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.

3 participants