-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] Support UnhandledPromptBehavior option as string and map
#16557
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
cb357bf
5a2cdd8
5c53619
fc98a78
75fc654
50275d2
9accc2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,33 @@ | |
|
|
||
| namespace OpenQA.Selenium; | ||
|
|
||
| public abstract record UnhandledPromptBehaviorOption | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move out from this file to dedicated (with "nested/related" types). |
||
| { | ||
| public static implicit operator UnhandledPromptBehaviorOption(UnhandledPromptBehavior value) | ||
| => Single(value); | ||
|
|
||
| public static UnhandledPromptBehaviorOption Single(UnhandledPromptBehavior value) | ||
| => new UnhandledPromptBehaviorSingleOption(value); | ||
|
|
||
| public static UnhandledPromptBehaviorOption Multi() | ||
| => new UnhandledPromptBehaviorMultiOption(); | ||
| } | ||
|
|
||
| public sealed record UnhandledPromptBehaviorSingleOption(UnhandledPromptBehavior Value) : UnhandledPromptBehaviorOption; | ||
|
|
||
| public sealed record UnhandledPromptBehaviorMultiOption : UnhandledPromptBehaviorOption | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RenderMichael any alternative names for these records? I like |
||
| { | ||
| public UnhandledPromptBehavior Alert { get; set; } = UnhandledPromptBehavior.Default; | ||
|
|
||
| public UnhandledPromptBehavior Confirm { get; set; } = UnhandledPromptBehavior.Default; | ||
|
|
||
| public UnhandledPromptBehavior Prompt { get; set; } = UnhandledPromptBehavior.Default; | ||
|
|
||
| public UnhandledPromptBehavior BeforeUnload { get; set; } = UnhandledPromptBehavior.Default; | ||
|
|
||
| public UnhandledPromptBehavior Default { get; set; } = UnhandledPromptBehavior.Default; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies the behavior of handling unexpected alerts in the IE driver. | ||
| /// </summary> | ||
|
|
@@ -164,7 +191,7 @@ protected DriverOptions() | |
| /// Gets or sets the value for describing how unexpected alerts are to be handled in the browser. | ||
| /// Defaults to <see cref="UnhandledPromptBehavior.Default"/>. | ||
| /// </summary> | ||
| public UnhandledPromptBehavior UnhandledPromptBehavior { get; set; } = UnhandledPromptBehavior.Default; | ||
| public UnhandledPromptBehaviorOption? UnhandledPromptBehavior { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the value for describing how the browser is to wait for pages to load in the browser. | ||
|
|
@@ -303,7 +330,7 @@ public virtual DriverOptionsMergeResult GetMergeResult(DriverOptions other) | |
| return result; | ||
| } | ||
|
|
||
| if (this.UnhandledPromptBehavior != UnhandledPromptBehavior.Default && other.UnhandledPromptBehavior != UnhandledPromptBehavior.Default) | ||
| if (this.UnhandledPromptBehavior is not null && other.UnhandledPromptBehavior is not null) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does feel like this method should tolerate it when both values are the same. However, we should investigate the history of this method before making those decisions.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand it as don't send anything over wire if default.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh yes, we should understand the purpose of this method, not obvious to me at glance. |
||
| { | ||
| result.IsMergeConflict = true; | ||
| result.MergeConflictOptionName = "UnhandledPromptBehavior"; | ||
|
|
@@ -508,29 +535,55 @@ protected IWritableCapabilities GenerateDesiredCapabilities(bool isSpecification | |
| capabilities.SetCapability(CapabilityType.PageLoadStrategy, pageLoadStrategySetting); | ||
| } | ||
|
|
||
| if (this.UnhandledPromptBehavior != UnhandledPromptBehavior.Default) | ||
| static string UnhandledPromptBehaviorToString(UnhandledPromptBehavior behavior) => behavior switch | ||
| { | ||
| Selenium.UnhandledPromptBehavior.Ignore => "ignore", | ||
| Selenium.UnhandledPromptBehavior.Accept => "accept", | ||
| Selenium.UnhandledPromptBehavior.Dismiss => "dismiss", | ||
| Selenium.UnhandledPromptBehavior.AcceptAndNotify => "accept and notify", | ||
| Selenium.UnhandledPromptBehavior.DismissAndNotify => "dismiss and notify", | ||
| _ => throw new ArgumentOutOfRangeException(nameof(behavior), $"UnhandledPromptBehavior value '{behavior}' is not recognized."), | ||
| }; | ||
|
|
||
| if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorSingleOption singleOption && singleOption.Value != Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| var stringValue = UnhandledPromptBehaviorToString(singleOption.Value); | ||
|
|
||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, stringValue); | ||
| } | ||
| else if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorMultiOption multiOption) | ||
| { | ||
| string unhandledPropmtBehaviorSetting = "ignore"; | ||
| switch (this.UnhandledPromptBehavior) | ||
| Dictionary<string, string> multiOptionDictionary = []; | ||
|
|
||
| if (multiOption.Alert is not Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| case UnhandledPromptBehavior.Accept: | ||
| unhandledPropmtBehaviorSetting = "accept"; | ||
| break; | ||
| multiOptionDictionary["alert"] = UnhandledPromptBehaviorToString(multiOption.Alert); | ||
| } | ||
|
|
||
| case UnhandledPromptBehavior.Dismiss: | ||
| unhandledPropmtBehaviorSetting = "dismiss"; | ||
| break; | ||
| if (multiOption.Confirm is not Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| multiOptionDictionary["confirm"] = UnhandledPromptBehaviorToString(multiOption.Confirm); | ||
| } | ||
|
|
||
| case UnhandledPromptBehavior.AcceptAndNotify: | ||
| unhandledPropmtBehaviorSetting = "accept and notify"; | ||
| break; | ||
| if (multiOption.Prompt is not Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| multiOptionDictionary["prompt"] = UnhandledPromptBehaviorToString(multiOption.Prompt); | ||
| } | ||
|
|
||
| case UnhandledPromptBehavior.DismissAndNotify: | ||
| unhandledPropmtBehaviorSetting = "dismiss and notify"; | ||
| break; | ||
| if (multiOption.BeforeUnload is not Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| multiOptionDictionary["beforeUnload"] = UnhandledPromptBehaviorToString(multiOption.BeforeUnload); | ||
| } | ||
|
|
||
| if (multiOption.Default is not Selenium.UnhandledPromptBehavior.Default) | ||
| { | ||
| multiOptionDictionary["default"] = UnhandledPromptBehaviorToString(multiOption.Default); | ||
| } | ||
|
|
||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, unhandledPropmtBehaviorSetting); | ||
| if (multiOptionDictionary.Count != 0) | ||
| { | ||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, multiOptionDictionary); | ||
| } | ||
| } | ||
|
|
||
| if (this.Proxy != null) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add xml docs as soon as we approve the approach.