Skip to content

Adding WaitForDownload test for .NET#1885

Merged
diemol merged 7 commits into
SeleniumHQ:trunkfrom
halex2005:trunk
Jul 22, 2026
Merged

Adding WaitForDownload test for .NET#1885
diemol merged 7 commits into
SeleniumHQ:trunkfrom
halex2005:trunk

Conversation

@halex2005

@halex2005 halex2005 commented Aug 22, 2024

Copy link
Copy Markdown
Contributor

User description

Hi!

Description

I've added WaitForDownload test case for .NET.
Review, please.

Note, that I've also added --no-sandbox switch to ChromeOptions because chrome crashes without it.
It's to make sure that tests are green.

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • [x ] Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • [x ] I have read the contributing document.
  • [x ] I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Tests, Enhancement


Description

  • Added a new WaitForDownload test method in NetworkTest.cs to handle and verify file downloads.
  • Enhanced BaseTest.cs by adding a --no-sandbox argument to ChromeOptions to prevent Chrome crashes during tests.
  • Updated documentation files to include CSharp code block references for better clarity and guidance.

Changes walkthrough 📝

Relevant files
Enhancement
BaseTest.cs
Add no-sandbox argument to ChromeOptions                                 

examples/dotnet/SeleniumDocs/BaseTest.cs

  • Added --no-sandbox argument to ChromeOptions.
  • Ensures Chrome does not crash during tests.
  • +1/-0     
    Tests
    NetworkTest.cs
    Add WaitForDownload test method for file downloads             

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs

  • Added WaitForDownload test method.
  • Implemented download behavior settings and event handling.
  • Verified file download completion and existence.
  • +47/-3   
    Documentation
    network.en.md
    Update CSharp tab with code block reference                           

    website_and_docs/content/documentation/webdriver/bidi/cdp/network.en.md

    • Updated CSharp tab with code block reference.
    +1/-1     
    network.ja.md
    Update CSharp tab with code block reference                           

    website_and_docs/content/documentation/webdriver/bidi/cdp/network.ja.md

    • Updated CSharp tab with code block reference.
    +1/-1     
    network.pt-br.md
    Update CSharp tab with code block reference                           

    website_and_docs/content/documentation/webdriver/bidi/cdp/network.pt-br.md

    • Updated CSharp tab with code block reference.
    +1/-1     
    network.zh-cn.md
    Update CSharp tab with code block reference                           

    website_and_docs/content/documentation/webdriver/bidi/cdp/network.zh-cn.md

    • Updated CSharp tab with code block reference.
    +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @netlify

    netlify Bot commented Aug 22, 2024

    Copy link
    Copy Markdown

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit d2847e8
    🔍 Latest deploy log https://app.netlify.com/projects/selenium-dev/deploys/68a0e03e5a25ef0008d22782
    😎 Deploy Preview https://deploy-preview-1885--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify project configuration.

    @CLAassistant

    CLAassistant commented Aug 22, 2024

    Copy link
    Copy Markdown

    CLA assistant check
    All committers have signed the CLA.

    @qodo-code-review

    Copy link
    Copy Markdown
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 Security concerns

    Security concern:
    Adding '--no-sandbox' to ChromeOptions (examples/dotnet/SeleniumDocs/BaseTest.cs, line 42) disables the Chrome sandbox, which is a security feature. This can potentially expose the system to security risks if malicious code is executed. While it may be necessary for testing environments, it should be used with caution and not in production environments.

    ⚡ Key issues to review

    Security Concern
    Adding '--no-sandbox' argument to ChromeOptions may introduce security risks in production environments.

    Error Handling
    The WaitForDownload test method lacks proper error handling for potential exceptions during file operations.

    @qodo-code-review

    qodo-code-review Bot commented Aug 22, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Error handling
    Add error handling when deleting files to manage potential exceptions
    Suggestion Impact:The commit replaced direct File.Delete with cleanup in a finally block using Directory.Delete(downloadPath, true), ensuring the downloaded file and temporary directory are removed even if the test fails. It does not catch deletion exceptions as explicitly suggested.

    code diff:

    +            var downloadPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
    +            Directory.CreateDirectory(downloadPath);
    +
    +            try
    +            {
    +                await domains.Browser.SetDownloadBehavior(new SetDownloadBehaviorCommandSettings
    +                {
    +                    Behavior = "allowAndName",
    +                    DownloadPath = downloadPath,
    +                    EventsEnabled = true
    +                });
    +
    +                var downloadCompleted = new TaskCompletionSource<bool>();
    +                string downloadId = null;
    +                domains.Browser.DownloadProgress += (sender, args) =>
    +                {
    +                    if (args.State == "completed" || args.State == "canceled")
    +                    {
    +                        downloadId = args.Guid;
    +                        downloadCompleted.TrySetResult(args.State == "completed");
    +                    }
    +                };
    +
    +                driver.FindElement(By.Id("file-1")).Click();
    +
    +                var completedTask = await Task.WhenAny(downloadCompleted.Task, Task.Delay(TimeSpan.FromSeconds(10)));
    +                Assert.AreEqual(downloadCompleted.Task, completedTask, "Timed out waiting for download to complete.");
    +                Assert.IsTrue(await downloadCompleted.Task);
    +
    +                var downloadedFilePath = Path.Combine(downloadPath, downloadId);
    +                Assert.IsTrue(File.Exists(downloadedFilePath));
    +            }
    +            finally
    +            {
    +                Directory.Delete(downloadPath, true);
    +            }

    Consider using File.Delete() within a try-catch block to handle potential exceptions
    that may occur during file deletion, such as access denied or file not found errors.

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs [192]

    -File.Delete(downloadedFilePath);
    +try
    +{
    +    File.Delete(downloadedFilePath);
    +}
    +catch (IOException ex)
    +{
    +    Console.WriteLine($"Error deleting file: {ex.Message}");
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion significantly enhances the code by adding error handling for file deletion, which is crucial for managing exceptions like access denied or file not found, thereby improving reliability.

    9
    Add exception handling to the event handler to catch and log specific errors
    Suggestion Impact:The generic event handler and dictionary lookups were replaced with a strongly typed DownloadProgress event and typed properties, eliminating the KeyNotFoundException risk instead of adding the suggested catch and logging.

    code diff:

    -            session.DevToolsEventReceived += (sender, args) =>
    +            domains.Browser.DownloadProgress += (sender, args) =>
                 {
    -                var downloadState = args.EventData["state"]?.ToString();
    -                if (args.EventName == "downloadProgress" &&
    -                    (string.Equals(downloadState, "completed") ||
    -                     string.Equals(downloadState, "canceled")))
    +                if (args.State == "completed" || args.State == "canceled")
                     {
    -                    downloadId = args.EventData["guid"].ToString();
    -                    downloaded = downloadState.Equals("completed");
    +                    downloadId = args.Guid;
    +                    downloaded = args.State == "completed";
                         downloadCompleted.Set();
                     }
                 };

    Consider using a more specific exception type instead of Exception when catching
    exceptions. This helps in better error handling and provides more information about
    the specific error that occurred.

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs [173-183]

     session.DevToolsEventReceived += (sender, args) =>
     {
    -    var downloadState = args.EventData["state"]?.ToString();
    -    if (args.EventName == "downloadProgress" &&
    -        (string.Equals(downloadState, "completed") ||
    -         string.Equals(downloadState, "canceled")))
    +    try
         {
    -        downloadId = args.EventData["guid"].ToString();
    -        downloaded = downloadState.Equals("completed");
    -        downloadCompleted.Set();
    +        var downloadState = args.EventData["state"]?.ToString();
    +        if (args.EventName == "downloadProgress" &&
    +            (string.Equals(downloadState, "completed") ||
    +             string.Equals(downloadState, "canceled")))
    +        {
    +            downloadId = args.EventData["guid"].ToString();
    +            downloaded = downloadState.Equals("completed");
    +            downloadCompleted.Set();
    +        }
    +    }
    +    catch (KeyNotFoundException ex)
    +    {
    +        Console.WriteLine($"Error accessing EventData: {ex.Message}");
         }
     };
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly adds exception handling to the event handler, which enhances error management by catching specific exceptions and logging them, improving robustness and debugging capabilities.

    8
    Best practice
    Use null-coalescing operator when combining paths to handle potential null values

    Consider using Path.Combine() to construct the file path instead of string
    concatenation. This ensures that the correct path separator is used for the current
    operating system.

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs [190]

    -var downloadedFilePath = Path.Combine(downloadPath, downloadId);
    +var downloadedFilePath = Path.Combine(downloadPath, downloadId ?? string.Empty);
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves the code by using a null-coalescing operator to handle potential null values when combining paths, ensuring that the path construction is robust and error-free.

    7
    Documentation
    Add a comment to explain the usage of a potentially security-impacting browser argument

    Consider adding a comment explaining why the "--no-sandbox" argument is being used.
    This argument can have security implications, so it's important to document the
    reason for its usage.

    examples/dotnet/SeleniumDocs/BaseTest.cs [35]

    +// Adding --no-sandbox for CI/CD environments or when running with limited privileges
     options.AddArgument("--no-sandbox");
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding a comment to explain the use of "--no-sandbox" is a good practice for documentation, especially given its security implications, but it is not critical to the functionality of the code.

    6

    @diemol

    diemol commented Aug 23, 2024

    Copy link
    Copy Markdown
    Member

    @halex2005 can you please sign the CLA?

    @halex2005

    Copy link
    Copy Markdown
    Contributor Author

    @diemol, signed

    @shbenzer

    Copy link
    Copy Markdown
    Contributor

    looks like the failing check is unrelated @diemol

    A1exKH

    This comment was marked as spam.

    @diemol
    diemol dismissed A1exKH’s stale review August 16, 2025 19:49

    This user approves PRs but never really checks them. Just to get activity in their GitHub profile.

    @diemol

    diemol commented Aug 16, 2025

    Copy link
    Copy Markdown
    Member

    @halex2005, there are compilation issues.

    cannot convert from 'string' to 'int'

    @netlify

    netlify Bot commented Jul 22, 2026

    Copy link
    Copy Markdown

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit 1b67106
    🔍 Latest deploy log https://app.netlify.com/projects/selenium-dev/deploys/6a60d55af2f5690008c98b4a
    😎 Deploy Preview https://deploy-preview-1885--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.
    🤖 Make changes Run an agent on this branch

    To edit notification comments on pull requests, go to your Netlify project configuration.

    The CDP DevToolsEventReceivedEventArgs.EventData is a JsonElement, not a
    string-keyed dictionary, so the merge from trunk didn't compile. Use the
    strongly-typed Browser.DownloadProgress event instead, matching the pattern
    already used by the SetCookie/PerformanceMetrics tests in this file, and
    correct the CSharp gh-codeblock line ranges across all locales.
    @qodo-code-review

    qodo-code-review Bot commented Jul 22, 2026

    Copy link
    Copy Markdown
    Contributor

    Code Review by Qodo

    🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

    Context used
    ✅ Compliance rules (platform): 10 rules

    Grey Divider


    Remediation recommended

    1. Cleanup delete can fail 🐞 Bug ☼ Reliability ⭐ New
    Description
    WaitForDownload calls Directory.Delete(downloadPath, true) unconditionally in a finally block; if
    deletion fails (e.g., file still locked/in-use), the cleanup exception will fail the test and can
    mask the original download/assertion failure.
    
    Code

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[R193-196]

    +            finally
    +            {
    +                Directory.Delete(downloadPath, true);
    +            }
    Evidence
    The new test creates a temp download directory and always deletes it in the finally block without
    handling IO exceptions, so any cleanup failure becomes the test result and can obscure the real
    cause of failure.
    

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[161-196]

    Agent prompt
    The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    
    ### Issue description
    `WaitForDownload()` deletes the temp download directory in a `finally` block via `Directory.Delete(downloadPath, true)`. If that deletion throws (common causes: file handle not released yet, transient IO issues, permissions), MSTest will report the cleanup exception and potentially hide the actual assertion/timeout failure.
    
    ### Issue Context
    This is test-only code, but cleanup-caused failures are noisy in CI and make failures harder to diagnose.
    
    ### Fix Focus Areas
    - examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[193-196]
    
    ### Suggested fix
    Wrap the directory deletion in a best-effort guard (and optionally log the exception):
    - `if (Directory.Exists(downloadPath)) { try { Directory.Delete(downloadPath, true); } catch (IOException) { /* log/ignore */ } catch (UnauthorizedAccessException) { /* log/ignore */ } }`
    Optionally consider a small retry/backoff if you see intermittent Windows file-lock issues.
    

    ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


    2. Sync wait in async ✓ Resolved 🐞 Bug ☼ Reliability
    Description
    WaitForDownload blocks the test thread using ManualResetEvent.WaitOne(...) inside an async
    test, which is avoidable and can reduce test-runner scalability. Use an awaitable signal (e.g.,
    TaskCompletionSource) with a timeout so the wait is non-blocking and cancellation-friendly.
    
    Code

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[R170-186]

    +            var downloadCompleted = new ManualResetEvent(false);
    +            string downloadId = null;
    +            bool downloaded = false;
    +            domains.Browser.DownloadProgress += (sender, args) =>
    +            {
    +                if (args.State == "completed" || args.State == "canceled")
    +                {
    +                    downloadId = args.Guid;
    +                    downloaded = args.State == "completed";
    +                    downloadCompleted.Set();
    +                }
    +            };
    +
    +            driver.FindElement(By.Id("file-1")).Click();
    +
    +            Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.FromSeconds(10)));
    +            Assert.IsTrue(downloaded);
    Evidence
    The new test blocks synchronously on downloadCompleted.WaitOne(...) inside an async test method.
    Other .NET examples in this repo use wait primitives (WebDriverWait) to wait for asynchronous
    conditions rather than manual reset events, indicating a preference for higher-level waiting
    patterns.
    

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[170-186]
    examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs[19-31]

    Agent prompt
    The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    
    ### Issue description
    `WaitForDownload` uses a synchronous `ManualResetEvent.WaitOne` inside an `async` method. This blocks a test-runner thread while waiting for the CDP `DownloadProgress` event.
    
    ### Issue Context
    The method is already asynchronous (`await domains.Browser.SetDownloadBehavior(...)`), so it can be fully async by using a `TaskCompletionSource` completed from the `DownloadProgress` handler, awaited with a timeout.
    
    ### Fix Focus Areas
    - examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[170-186]
    

    ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


    3. Shared temp download path ✓ Resolved 🐞 Bug ☼ Reliability
    Description
    WaitForDownload downloads into the global temp directory and only deletes the file on the success
    path, so failures can leak artifacts and shared temp usage can cause cross-test interference. Create
    a unique temp subdirectory per test run and clean it up in a finally block (best-effort) to keep
    CI deterministic.
    
    Code

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[R162-190]

    +            var downloadPath = Path.GetTempPath();
    +            await domains.Browser.SetDownloadBehavior(new SetDownloadBehaviorCommandSettings
    +            {
    +                Behavior = "allowAndName",
    +                DownloadPath = downloadPath,
    +                EventsEnabled = true
    +            });
    +
    +            var downloadCompleted = new ManualResetEvent(false);
    +            string downloadId = null;
    +            bool downloaded = false;
    +            domains.Browser.DownloadProgress += (sender, args) =>
    +            {
    +                if (args.State == "completed" || args.State == "canceled")
    +                {
    +                    downloadId = args.Guid;
    +                    downloaded = args.State == "completed";
    +                    downloadCompleted.Set();
    +                }
    +            };
    +
    +            driver.FindElement(By.Id("file-1")).Click();
    +
    +            Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.FromSeconds(10)));
    +            Assert.IsTrue(downloaded);
    +            var downloadedFilePath = Path.Combine(downloadPath, downloadId);
    +            Assert.IsTrue(File.Exists(downloadedFilePath));
    +            File.Delete(downloadedFilePath);
    +        }
    Evidence
    The new test explicitly sets downloadPath to the shared temp directory and then deletes only the
    expected file at the end, with no finally for failure cases. Elsewhere in the .NET examples, a
    unique temp directory is created for isolation (user-data-dir), showing an established pattern to
    follow.
    

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[162-190]
    examples/dotnet/SeleniumDocs/BaseTest.cs[36-48]

    Agent prompt
    The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    
    ### Issue description
    The test uses `Path.GetTempPath()` as the download directory and performs cleanup only at the end of the method. If any assertion fails before cleanup, the downloaded file remains in the shared temp directory.
    
    ### Issue Context
    The same test suite already uses per-run isolation for Chrome user-data dirs (random temp directory + create directory). Apply the same approach to downloads: create a unique temp directory, pass it as `DownloadPath`, and delete files/directories in `finally`.
    
    ### Fix Focus Areas
    - examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[162-190]
    - examples/dotnet/SeleniumDocs/BaseTest.cs[36-48]
    

    ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


    Grey Divider

    Previous review results

    Review updated until commit 1b67106

    Results up to commit 5981ddf ⚖️ Balanced


    🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


    Remediation recommended
    1. Sync wait in async ✓ Resolved 🐞 Bug ☼ Reliability
    Description
    WaitForDownload blocks the test thread using ManualResetEvent.WaitOne(...) inside an async
    test, which is avoidable and can reduce test-runner scalability. Use an awaitable signal (e.g.,
    TaskCompletionSource) with a timeout so the wait is non-blocking and cancellation-friendly.
    
    Code

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[R170-186]

    +            var downloadCompleted = new ManualResetEvent(false);
    +            string downloadId = null;
    +            bool downloaded = false;
    +            domains.Browser.DownloadProgress += (sender, args) =>
    +            {
    +                if (args.State == "completed" || args.State == "canceled")
    +                {
    +                    downloadId = args.Guid;
    +                    downloaded = args.State == "completed";
    +                    downloadCompleted.Set();
    +                }
    +            };
    +
    +            driver.FindElement(By.Id("file-1")).Click();
    +
    +            Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.FromSeconds(10)));
    +            Assert.IsTrue(downloaded);
    Evidence
    The new test blocks synchronously on downloadCompleted.WaitOne(...) inside an async test method.
    Other .NET examples in this repo use wait primitives (WebDriverWait) to wait for asynchronous
    conditions rather than manual reset events, indicating a preference for higher-level waiting
    patterns.
    

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[170-186]
    examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs[19-31]

    Agent prompt
    The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    
    ### Issue description
    `WaitForDownload` uses a synchronous `ManualResetEvent.WaitOne` inside an `async` method. This blocks a test-runner thread while waiting for the CDP `DownloadProgress` event.
    
    ### Issue Context
    The method is already asynchronous (`await domains.Browser.SetDownloadBehavior(...)`), so it can be fully async by using a `TaskCompletionSource` completed from the `DownloadProgress` handler, awaited with a timeout.
    
    ### Fix Focus Areas
    - examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[170-186]
    

    ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


    2. Shared temp download path ✓ Resolved 🐞 Bug ☼ Reliability
    Description
    WaitForDownload downloads into the global temp directory and only deletes the file on the success
    path, so failures can leak artifacts and shared temp usage can cause cross-test interference. Create
    a unique temp subdirectory per test run and clean it up in a finally block (best-effort) to keep
    CI deterministic.
    
    Code

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[R162-190]

    +            var downloadPath = Path.GetTempPath();
    +            await domains.Browser.SetDownloadBehavior(new SetDownloadBehaviorCommandSettings
    +            {
    +                Behavior = "allowAndName",
    +                DownloadPath = downloadPath,
    +                EventsEnabled = true
    +            });
    +
    +            var downloadCompleted = new ManualResetEvent(false);
    +            string downloadId = null;
    +            bool downloaded = false;
    +            domains.Browser.DownloadProgress += (sender, args) =>
    +            {
    +                if (args.State == "completed" || args.State == "canceled")
    +                {
    +                    downloadId = args.Guid;
    +                    downloaded = args.State == "completed";
    +                    downloadCompleted.Set();
    +                }
    +            };
    +
    +            driver.FindElement(By.Id("file-1")).Click();
    +
    +            Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.FromSeconds(10)));
    +            Assert.IsTrue(downloaded);
    +            var downloadedFilePath = Path.Combine(downloadPath, downloadId);
    +            Assert.IsTrue(File.Exists(downloadedFilePath));
    +            File.Delete(downloadedFilePath);
    +        }
    Evidence
    The new test explicitly sets downloadPath to the shared temp directory and then deletes only the
    expected file at the end, with no finally for failure cases. Elsewhere in the .NET examples, a
    unique temp directory is created for isolation (user-data-dir), showing an established pattern to
    follow.
    

    examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[162-190]
    examples/dotnet/SeleniumDocs/BaseTest.cs[36-48]

    Agent prompt
    The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    
    ### Issue description
    The test uses `Path.GetTempPath()` as the download directory and performs cleanup only at the end of the method. If any assertion fails before cleanup, the downloaded file remains in the shared temp directory.
    
    ### Issue Context
    The same test suite already uses per-run isolation for Chrome user-data dirs (random temp directory + create directory). Apply the same approach to downloads: create a unique temp directory, pass it as `DownloadPath`, and delete files/directories in `finally`.
    
    ### Fix Focus Areas
    - examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs[162-190]
    - examples/dotnet/SeleniumDocs/BaseTest.cs[36-48]
    

    ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


    Qodo Logo

    Comment thread examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs Outdated
    Comment thread examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs Outdated
    diemol
    diemol previously approved these changes Jul 22, 2026
    …ak-proof
    
    Replace the blocking ManualResetEvent.WaitOne with an awaited
    TaskCompletionSource, and download into a unique per-run temp directory
    that's cleaned up in a finally block so failed assertions don't leave
    artifacts behind or risk cross-test interference.
    Comment thread examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs
    @qodo-code-review

    Copy link
    Copy Markdown
    Contributor

    Code review by qodo was updated up to the latest commit 1b67106

    @diemol
    diemol merged commit d8444b0 into SeleniumHQ:trunk Jul 22, 2026
    10 checks passed
    selenium-ci added a commit that referenced this pull request Jul 22, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    6 participants