-
-
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 6 commits
cb357bf
5a2cdd8
5c53619
fc98a78
75fc654
50275d2
9accc2b
1acc7de
727a5b3
96cd5cd
83b5218
f5e5845
c83c67c
baf2939
bfd55e9
c94cc5d
4f60927
aeb98ae
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,37 @@ | |
|
|
||
| namespace OpenQA.Selenium; | ||
|
|
||
| public abstract record UnhandledPromptBehaviorOption | ||
nvborisenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public static implicit operator UnhandledPromptBehaviorOption(UnhandledPromptBehavior? value) | ||
| => Single(value); | ||
|
|
||
| public static UnhandledPromptBehaviorOption Single(UnhandledPromptBehavior? value) | ||
| => new UnhandledPromptBehaviorSingleOption(value); | ||
|
|
||
| public static UnhandledPromptBehaviorOption Multi(UnhandledPromptBehavior? alert = null, | ||
nvborisenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| UnhandledPromptBehavior? confirm = null, | ||
| UnhandledPromptBehavior? prompt = null, | ||
| UnhandledPromptBehavior? beforeUnload = null, | ||
| UnhandledPromptBehavior? @default = null) | ||
| => new UnhandledPromptBehaviorMultiOption() with { Alert = alert, Confirm = confirm, Prompt = prompt, BeforeUnload = beforeUnload, Default = @default }; | ||
| } | ||
|
|
||
| public sealed record UnhandledPromptBehaviorSingleOption(UnhandledPromptBehavior? Value) : UnhandledPromptBehaviorOption; | ||
nvborisenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public sealed record UnhandledPromptBehaviorMultiOption : UnhandledPromptBehaviorOption | ||
nvborisenko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public UnhandledPromptBehavior? Alert { get; set; } | ||
|
|
||
| public UnhandledPromptBehavior? Confirm { get; set; } | ||
|
|
||
| public UnhandledPromptBehavior? Prompt { get; set; } | ||
|
|
||
| public UnhandledPromptBehavior? BeforeUnload { get; set; } | ||
|
|
||
| public UnhandledPromptBehavior? Default { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies the behavior of handling unexpected alerts in the IE driver. | ||
| /// </summary> | ||
|
|
@@ -164,7 +195,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 +334,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) | ||
|
||
| { | ||
| result.IsMergeConflict = true; | ||
| result.MergeConflictOptionName = "UnhandledPromptBehavior"; | ||
|
|
@@ -508,29 +539,60 @@ protected IWritableCapabilities GenerateDesiredCapabilities(bool isSpecification | |
| capabilities.SetCapability(CapabilityType.PageLoadStrategy, pageLoadStrategySetting); | ||
| } | ||
|
|
||
| if (this.UnhandledPromptBehavior != UnhandledPromptBehavior.Default) | ||
| [return: NotNullIfNotNull(nameof(behavior))] | ||
| static string? UnhandledPromptBehaviorToString(UnhandledPromptBehavior? behavior) => behavior switch | ||
| { | ||
| string unhandledPropmtBehaviorSetting = "ignore"; | ||
| switch (this.UnhandledPromptBehavior) | ||
| Selenium.UnhandledPromptBehavior.Ignore => "ignore", | ||
| Selenium.UnhandledPromptBehavior.Accept => "accept", | ||
| Selenium.UnhandledPromptBehavior.Dismiss => "dismiss", | ||
| Selenium.UnhandledPromptBehavior.AcceptAndNotify => "accept and notify", | ||
| Selenium.UnhandledPromptBehavior.DismissAndNotify => "dismiss and notify", | ||
| null or Selenium.UnhandledPromptBehavior.Default => null, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(behavior), $"UnhandledPromptBehavior value '{behavior}' is not recognized."), | ||
| }; | ||
|
|
||
| if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorSingleOption singleOption) | ||
| { | ||
| var stringValue = UnhandledPromptBehaviorToString(singleOption.Value); | ||
|
|
||
| if (stringValue is not null) | ||
| { | ||
| case UnhandledPromptBehavior.Accept: | ||
| unhandledPropmtBehaviorSetting = "accept"; | ||
| break; | ||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, stringValue); | ||
| } | ||
| } | ||
| else if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorMultiOption multiOption) | ||
|
||
| { | ||
| Dictionary<string, string> multiOptionDictionary = []; | ||
|
|
||
| case UnhandledPromptBehavior.Dismiss: | ||
| unhandledPropmtBehaviorSetting = "dismiss"; | ||
| break; | ||
| if (multiOption.Alert is not null) | ||
| { | ||
| multiOptionDictionary["alert"] = UnhandledPromptBehaviorToString(multiOption.Alert); | ||
| } | ||
|
|
||
| case UnhandledPromptBehavior.AcceptAndNotify: | ||
| unhandledPropmtBehaviorSetting = "accept and notify"; | ||
| break; | ||
| if (multiOption.Confirm is not null) | ||
| { | ||
| multiOptionDictionary["confirm"] = UnhandledPromptBehaviorToString(multiOption.Confirm); | ||
| } | ||
|
|
||
| case UnhandledPromptBehavior.DismissAndNotify: | ||
| unhandledPropmtBehaviorSetting = "dismiss and notify"; | ||
| break; | ||
| if (multiOption.Prompt is not null) | ||
| { | ||
| multiOptionDictionary["prompt"] = UnhandledPromptBehaviorToString(multiOption.Prompt); | ||
| } | ||
|
|
||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, unhandledPropmtBehaviorSetting); | ||
| if (multiOption.BeforeUnload is not null) | ||
| { | ||
| multiOptionDictionary["beforeUnload"] = UnhandledPromptBehaviorToString(multiOption.BeforeUnload); | ||
| } | ||
|
|
||
| if (multiOption.Default is not null) | ||
| { | ||
| multiOptionDictionary["default"] = UnhandledPromptBehaviorToString(multiOption.Default); | ||
| } | ||
|
|
||
| if (multiOptionDictionary.Count != 0) | ||
|
||
| { | ||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, multiOptionDictionary); | ||
| } | ||
| } | ||
|
|
||
| if (this.Proxy != null) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.