-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[dotnet] implement high level API for WebDriver BiDi Log Events #14057
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a6700fe
[dotnet] allow driver to execute commands asynchronously
titusfortner 8872c88
[dotnet] implement navigation commands with async tasks
titusfortner aa484e9
[dotnet] add async navigation methods to interface and implement in e…
titusfortner 4b42c7a
[dotnet] add webdriver bidi dependency
titusfortner 5bcd3e9
[dotnet] tests should default to bidi disabled
titusfortner dc502b6
[dotnet] start a BiDi session if webSocketUrl is set
titusfortner 38a94b6
[dotnet] implement navigation commands with WebDriver BiDi
titusfortner d66e0e4
[dotnet] implement appropriate waiting for bidi navigation based on p…
titusfortner 5e29104
[dotnet] implement BiDi handlers for log events
titusfortner b38f405
[dotnet] create new test suite for running only BiDi tests
titusfortner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <copyright file="IScript.cs" company="WebDriver Committers"> | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using WebDriverBiDi.Log; | ||
|
||
namespace OpenQA.Selenium | ||
{ | ||
/// <summary> | ||
/// Defines an interface providing access to WebDriverBiDi events in script and log domains. | ||
/// </summary> | ||
[Obsolete("This class is in beta and may change in future releases.")] | ||
public interface IScript | ||
{ | ||
/// <summary> | ||
/// Add and remove handlers for console messages. | ||
/// </summary> | ||
[Obsolete("This event is in beta and may change in future releases.")] | ||
event EventHandler<EntryAddedEventArgs> ConsoleMessageHandler; | ||
|
||
/// <summary> | ||
/// Add and remove handlers for console messages. | ||
/// </summary> | ||
[Obsolete("This event is in beta and may change in future releases.")] | ||
event EventHandler<EntryAddedEventArgs> JavaScriptErrorHandler; | ||
|
||
/// <summary> | ||
/// Asynchronously starts monitoring for console and JavaScript log entries. | ||
/// </summary> | ||
/// <returns>A task object representing the asynchronous operation.</returns> | ||
[Obsolete("This task is in beta and may change in future releases.")] | ||
Task StartMonitoringLogEntries(); | ||
|
||
/// <summary> | ||
/// Asynchronously stops monitoring for console and JavaScript log entries. | ||
/// </summary> | ||
/// <returns>A task object representing the asynchronous operation.</returns> | ||
[Obsolete("This task is in beta and may change in future releases.")] | ||
Task StopMonitoringLogEntries(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the need for exposing start/stop API? I would probably just start when the first event handler is added and stop when the last one is removed.
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.
Yeah, it seems less intuitive to me that you need to register and then explicitly call to start monitoring, but apparently that's what is expected in the .NET world 🤷
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 thread promises to be interesting, and this thread is very important.
No, native events is a standard implementation of pub/sub pattern, or observable pattern, or any other notification based pattern. Events born at the beginning of .net. Technically you are able to know when somebody subscribes/unsubscribes on the event.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/add - pretty easy.
Now, in 2024, let's think about it deeper:
add
method issync
, but we need to call anotherasync
method. Sync-over-async problem.async
methods fromsync
context even when Microsoft doesn't recommend it.async
methods in theirs event handlers. This isasync void
problem. Again, Microsoft doesn't recommend it. Ah, this is exceptional case, async event handlers... move on.await async void
? Kind of impossible. There is tricky trick, but this trick is very rare in .net world. Nobody wants to code workarounds.How to be?
Why? It is fully manageable!
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.
Yeah, my first implementation had private variables for the handlers and then reference them to add/remove
But from what I've seen, .NET practices leans toward explicitness and clarity which means not assuming that adding or removing events will start and stop monitoring. (ChatGPT agrees with this 😁)
I'm not following all of your comment, though (and I'm not well-versed in async approach in general). Is there a use case for where we want to make one of these events manage async actions?
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.
For user it doesn't matter what you do behind: starting, stopping, laughing. He just subscribe on the event, what means he wants to get notifications every time when the event is occurred.
Use cases for async event handlers?.. My initial example can be considered as use case:
To be more precise:
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 guess my question is whether there is something that can't be done with a sync method, or if it's just that people want to do everything async on principle?
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.
With respect to explicit start/stop:
So I took a look at PuppeteerCSharp and Playwright .NET implementations; I don't want to take what they are doing as necessary indications of proper, idiomatic .NET behavior, but, neither of them require an extra step to start monitoring.
I generally see our priorities as:
I agree that explicit stop/starts follows the convention of explicitness, but that neither other project requires it and none of the other bindings will do it this way, I'm leaning toward having adding the event start it, but keep the methods for starting and stopping public in case the user wants more control.
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.
As far as the async implementation, I did some reading, and yes, we need to support it, I'll see about updating this code.
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.
Ok, looks like Async works out of the box...
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.
Your example is known
async void
problem. Just try slightly modified handler: