-
-
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?
[dotnet] Support UnhandledPromptBehavior option as string and map
#16557
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
| } | ||
|
|
||
| if (this.UnhandledPromptBehavior != UnhandledPromptBehavior.Default && other.UnhandledPromptBehavior != UnhandledPromptBehavior.Default) | ||
| if (this.UnhandledPromptBehavior is not null && other.UnhandledPromptBehavior is not 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.
Hm, != operator for records?
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.
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.
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 understand it as don't send anything over wire if default.
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.
However, we should investigate the history of this method before making those decisions.
Oh yes, we should understand the purpose of this method, not obvious to me at glance.
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.
@jimevans do you know?
RenderMichael
left a comment
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.
A breaking change like this should be well-tested. Could we add tests here?
I have no capacity to test the functionality which was not indented to be tested. You can "request changes", please propose. |
I propose new tests for this functionality. |
|
Existing tests don't satisfy you? You ask me to increase the coverage. But what is coverage? |
|
@RenderMichael welcome to #15536 UPD: is it only one concern from your side? |
|
Generally, looks good, @nvborisenko. What I don't like is a nullability of properties and parameters ( |
| /// <summary> | ||
| /// Gets or sets the behavior to use when an unexpected alert is encountered during automation. | ||
| /// </summary> | ||
| public UnhandledPromptBehavior Alert { get; set; } = UnhandledPromptBehavior.Default; |
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.
Is it correct that
- All of these are set to Default
- They have setters?
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.
Please help me if you see hidden stones.
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 have no idea if these work because there are no tests yet, but this looks wrong.
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.
True, it looks strange because historically we have Default in enum. It should be nullable, but it is as is. Please read comments in this PR.
How to move on...
|
|
||
| capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, stringValue); | ||
| } | ||
| else if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorMultiOption multiOption) |
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.
We should follow our usual pattern here to have a ToDictionary() method directly on the UnhandledPromptBehaviorMultiOption type:
public Dictionary<string, string> ToDictionary()
{
Dictionary<string, string> multiOptionDictionary = [];
if (Alert is not Selenium.UnhandledPromptBehavior.Default)
{
multiOptionDictionary["alert"] = UnhandledPromptBehaviorToString(Alert);
}
if (Confirm is not Selenium.UnhandledPromptBehavior.Default)
{
multiOptionDictionary["confirm"] = UnhandledPromptBehaviorToString(Confirm);
}
if (Prompt is not Selenium.UnhandledPromptBehavior.Default)
{
multiOptionDictionary["prompt"] = UnhandledPromptBehaviorToString(Prompt);
}
if (BeforeUnload is not Selenium.UnhandledPromptBehavior.Default)
{
multiOptionDictionary["beforeUnload"] = UnhandledPromptBehaviorToString(BeforeUnload);
}
if (Default is not Selenium.UnhandledPromptBehavior.Default)
{
multiOptionDictionary["default"] = UnhandledPromptBehaviorToString(Default);
}
return multiOptionDictionary;
}and then to call that method here
else if (this.UnhandledPromptBehavior is UnhandledPromptBehaviorMultiOption multiOption)
{
multiOptionDictionary = multiOption.ToDictionary();
if (multiOptionDictionary.Count != 0)
{
capabilities.SetCapability(CapabilityType.UnhandledPromptBehavior, multiOptionDictionary);
}
}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.
This also allows us to move UnhandledPromptBehaviorToString to the UnhandledPromptBehaviorOption, cleaning up this 150-line method.
| multiOptionDictionary["default"] = UnhandledPromptBehaviorToString(multiOption.Default); | ||
| } | ||
|
|
||
| if (multiOptionDictionary.Count != 0) |
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.
Do we need to guard against {}? It feels like we should transparently sent this to the server.
What happens if we do this, anyway?
| /// Creates an <see cref="UnhandledPromptBehaviorOption"/> allowing individual <see cref="UnhandledPromptBehavior"/> values per prompt type. | ||
| /// </summary> | ||
| /// <returns>An <see cref="UnhandledPromptBehaviorOption"/> with per-prompt configurable behaviors.</returns> | ||
| public static UnhandledPromptBehaviorOption Multi() |
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.
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.
Since we are changing the type name, I think it would align better with the spec to call it UnhandledPromptHandlers


User description
🔗 Related Issues
Fixes #16102
💥 What does this PR do?
This PR changes
UnhandledPromptBehaviorproperty return type to custom type, supporting bothstringandmaprepresentation at serialization phase.🔧 Implementation Notes
It is not a breaking change at compilation level! One file change to emphasize that users are not affected.
💡 Additional Considerations
I intentionally didn't introduce new property in Options class, it would lead to a mess in my opinion.
🔄 Types of changes
PR Type
Enhancement
Description
Support
UnhandledPromptBehavioras both string and dictionary representationsIntroduce abstract record hierarchy for flexible prompt behavior configuration
Enable per-prompt-type behavior specification via
UnhandledPromptBehaviorMultiOptionMaintain backward compatibility with existing enum-based API
Diagram Walkthrough
File Walkthrough
DriverOptions.cs
Add flexible prompt behavior option types with dual serializationdotnet/src/webdriver/DriverOptions.cs
UnhandledPromptBehaviorOptionwith twosealed implementations:
UnhandledPromptBehaviorSingleOption(forstring representation) and
UnhandledPromptBehaviorMultiOption(fordictionary representation with per-prompt-type settings)
Single(),Multi()) forconvenient instantiation
UnhandledPromptBehaviorproperty type from enum to nullableUnhandledPromptBehaviorOptionGenerateDesiredCapabilities()tohandle both single and multi-option cases, converting to appropriate
capability format
comparison
UnhandledPromptBehaviorToString()