Skip to content

Add test for UnhandledPromptBehavior in ChromeOptions#2611

Open
kimtg wants to merge 1 commit intoSeleniumHQ:trunkfrom
kimtg:patch-1
Open

Add test for UnhandledPromptBehavior in ChromeOptions#2611
kimtg wants to merge 1 commit intoSeleniumHQ:trunkfrom
kimtg:patch-1

Conversation

@kimtg
Copy link
Copy Markdown

@kimtg kimtg commented Mar 30, 2026

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • 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

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

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 30, 2026

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7dd67a5

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add test for UnhandledPromptBehavior in ChromeOptions

🧪 Tests

Grey Divider

Walkthroughs

Description
• Add test method for UnhandledPromptBehavior option
• Demonstrates setting DismissAndNotify behavior in ChromeOptions
• Follows existing test pattern with driver initialization and cleanup
Diagram
flowchart LR
  A["OptionsTest.cs"] -- "adds new test method" --> B["SetUnhandledPromptBehavior"]
  B -- "sets UnhandledPromptBehavior" --> C["DismissAndNotify"]
  C -- "creates ChromeDriver" --> D["Navigate and cleanup"]
Loading

Grey Divider

File Changes

1. examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs 🧪 Tests +16/-1

Add UnhandledPromptBehavior test method

• Added new test method SetUnhandledPromptBehavior() with [TestMethod] attribute
• Sets chromeOptions.UnhandledPromptBehavior to UnhandledPromptBehavior.DismissAndNotify
• Initializes ChromeDriver with configured options and navigates to selenium.dev
• Includes proper try-finally block for driver cleanup
• Fixed missing newline at end of file

examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Mar 30, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Prompt behavior untested 🐞 Bug ✓ Correctness
Description
SetUnhandledPromptBehavior sets ChromeOptions.UnhandledPromptBehavior but never triggers an
alert/prompt/confirm, so the option is not exercised and the test provides false confidence.
Regressions in unhandled prompt handling would still pass because the only action is a normal
navigation.
Code

examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs[R56-65]

+        [TestMethod]
+        public void SetUnhandledPromptBehavior()
+        {
+            var chromeOptions = new ChromeOptions();
+            chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.DismissAndNotify;
+            IWebDriver driver = new ChromeDriver(chromeOptions);
+            try
+            {
+                driver.Navigate().GoToUrl("https://selenium.dev");
+            }
Evidence
The added test sets UnhandledPromptBehavior and then only navigates to https://selenium.dev; there
is no code that opens a JavaScript dialog (alert/prompt/confirm) or executes a command while such a
dialog is present, so the configured behavior cannot affect the run.

examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs[56-70]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`SetUnhandledPromptBehavior` sets `UnhandledPromptBehavior` but never triggers an alert/prompt/confirm, so it does not actually test the configured behavior.

### Issue Context
`UnhandledPromptBehavior` only matters when a JavaScript dialog is open and a subsequent WebDriver command is executed. The test currently performs a normal navigation to an external page that does not open such a dialog.

### Fix Focus Areas
- examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs[56-70]

### Suggested change
Update the test to load a deterministic page that opens an alert (e.g., via a `data:` URL with `alert()` on load), then execute a follow-up WebDriver command and assert the expected outcome for `DismissAndNotify` (typically an exception is thrown while the alert is dismissed).

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


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

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