Skip to content
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

[java] add deprecation notices to Grid logs and Java stdout #10408

Closed
wants to merge 4 commits into from

Conversation

titusfortner
Copy link
Member

@titusfortner titusfortner commented Mar 2, 2022

Update

I had to change the code quite a bit because what Java was building and what the Grid was receiving turned out to be more different than I realized. So most of the discussion in this initial post is out of date.


As discussed in TLC meeting today, to address #10374

Note: this is in DRAFT until we add the documentation (and update the URL as desired) and write the blog post.

This is what the output looks like: https://gist.github.com/titusfortner/f75a3bff9b1b9946687ae8069f112f7f
4 conditions:

  1. Client sends Options with only w3c syntax (Se 4 Ruby/.NET/JS) — No warnings
  2. Client sends Options with a valid handshake with both W3C & OSS and driver supports w3c (Se 3; Se 4 Java) — No warnings
  3. Client sends Options a valid handshake with both W3C & OSS, but driver only supports or is set to use OSS — Warning that OSS mode deprecated
  4. Client sends only OSS Capabilities (Se 2 or DesiredCapabilities class) — Warning to use W3C Capabilities

One issue is for use case 2, if the user is working with Selenium 3.0 - 3.8.1 (handshake, but not fully w3c compliant), Selenium reports w3c mode, but will attempt to convert any commands that aren't w3c compliant. So these people might likely wouldn't get warnings, but would have code stop working after we remove deprecations. The bright side is that only 6% of downloads are in this range for Java, and the likelihood that these people have not updated their client version, but *have updated their Grid version is likely an extremely small cross-section

@codecov-commenter
Copy link

codecov-commenter commented Mar 9, 2022

Codecov Report

Merging #10408 (b33b53c) into trunk (1877b9d) will not change coverage.
The diff coverage is n/a.

❗ Current head b33b53c differs from pull request most recent head a14aae3. Consider uploading reports for the commit a14aae3 to get more accurate results

@@           Coverage Diff           @@
##            trunk   #10408   +/-   ##
=======================================
  Coverage   46.30%   46.30%           
=======================================
  Files          86       86           
  Lines        5799     5799           
  Branches      277      277           
=======================================
  Hits         2685     2685           
  Misses       2837     2837           
  Partials      277      277           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e541ed...a14aae3. Read the comment docs.

Copy link
Contributor

@pujagani pujagani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @titusfortner! Using parameterized logging is better performance-wise rather than string concatenation. I made a quick fix for that and now SonarLint should be happy.
Appreciate the effort, especially the data-backed details in the pull request template. The changes look good to me 👍

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell B 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@titusfortner titusfortner added this to the 4.2 milestone May 20, 2022
@titusfortner
Copy link
Member Author

Well... This code isn't right :(
I built the grid from this PR, and this is what I'm getting:

        MutableCapabilities caps = new MutableCapabilities();
        caps.setCapability("browserName", "firefox");
        RemoteWebDriver driver = new RemoteWebDriver(caps);
INFO: Detected dialect: W3C
May 20, 2022 2:30:31 PM org.openqa.selenium.remote.ProtocolHandshake createSession
WARNING: Support for Legacy Capabilities is deprecated; Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/

@titusfortner
Copy link
Member Author

So, this code is weird.
NewSessionPayload always sets desiredCapabilities, regardless

https://github.com/SeleniumHQ/selenium/blob/702b3aa/java/src/org/openqa/selenium/remote/NewSessionPayload.java#L64-L67

So, passing in an Options instance will always add OSS to the list of dialogs, and it adds W3C based on whether you have firstMatch/alwaysMatch, which I think means it only happens when using the WebDriverBuilder
So my idea of calling payload.getDownstreamDialects() and checking if OSS is in there, is absolutely useless.

Fortunately, command includes both capabilities & desiredCapabilities, so I think the answer is to get the keys from each, and if there are any of keys in desiredCapabilities that aren't in capabilities, throw the warning.
We can even list which keys aren't valid in the message.

This should work for the scenario where the Java bindings are sending invalid capabilities, but I need to run a bunch more tests to make sure.

I'm not certain how this applies to the scenario where something is sending commands to the grid, yet.

@titusfortner titusfortner force-pushed the grid_warning branch 2 times, most recently from 67a4374 to 3aa1a05 Compare May 22, 2022 01:40
@titusfortner titusfortner requested a review from pujagani May 22, 2022 01:40
@titusfortner titusfortner marked this pull request as ready for review May 22, 2022 01:41
@titusfortner
Copy link
Member Author

I tested this a number of ways including building the grid with this code and testing it with Selenium 3 Ruby & Python bindings.

This should do exactly what we want for local Java client code which always goes through this loop in an expected way. It will log results to console.

For grid it is trickier because the messages are in the grid logs not stdout. Also, because of grid weirdness (https://gist.github.com/titusfortner/1956ca0e863b5fa7baff9a61ebbe135b), it won't always log a problem, even when the user is doing the wrong thing.

Either way, I think this is the best we're going to get as far as warning users of the change, and the weirdness will get fixed when we start removing the extra stuff.

@titusfortner titusfortner self-assigned this May 22, 2022
@titusfortner titusfortner marked this pull request as draft May 24, 2022 16:07
@titusfortner
Copy link
Member Author

I moved this back to draft so we can figure out if we can log issues when people use setCapability() with non-w3c capabilities. It likely will be supper chatty, so if we can also figure out how to silence it, people might appreciate that.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@diemol
Copy link
Member

diemol commented May 25, 2022

Implemented via a297017

@diemol diemol closed this May 25, 2022
@titusfortner titusfortner deleted the grid_warning branch December 4, 2022 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants