-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java] Add method to retrieve and display browser version #16422
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
Conversation
Introduce ShowBrowserVersionIntegrationTest to launch a real browser session Retrieve browser version from capabilities and print it to the console Assert that the browser version is not empty or null Implements feature to programmatically obtain browser version
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:
|
|
||
/** | ||
* Returns the browser version from the capabilities. | ||
* Compatible with Java 11 and Selenium 4. |
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.
All methods in Selenium 4 are compatible with Selenium 4 (and Java 11).
You can already do: |
I agree with @cgoldberg, this is possible already. Why do we need a convenience method? |
my mistake I didn’t saw the original method, we can close this PR, Sorry |
User description
💥 What does this PR do?
This PR adds a new capability to RemoteWebDriver: allowing the browser version (browserVersion) to be retrieved programmatically from the driver’s capabilities. A getBrowserVersion() method is added to extract that information safely. An integration test (ShowBrowserVersionIntegrationTest) is included to demonstrate its usage in a real browser session, printing the version to the console and asserting that it is neither null nor empty.
🔧 Implementation Notes
• The getBrowserVersion() method in RemoteWebDriver reads the browserVersion key from the capabilities object, converts it to string if present, or returns an empty string otherwise, ensuring compatibility with drivers that don’t provide it.
• No additional dependencies are introduced; this is compatible with Java 11 and Selenium 4.
• The integration test serves as a usage example, rather than being the focus; the central value is the new API.
💡 Additional Considerations
• Some drivers may not report browserVersion. In those cases, getBrowserVersion() will reliably return an empty string, avoiding errors or breaking changes.
• It would be beneficial to document, in Selenium’s capability documentation, that browserVersion is now available via this method.
• In the future, additional integration tests for other browsers (Firefox, Edge, etc.) could be added to increase confidence across platforms.
🔄 Types of changes
• ✅ New feature (non-breaking change which adds functionality and tests!)
• ✅ Enhancement / cleanup (documentation and method visibility improvements)
PR Type
Enhancement
Description
Add
getBrowserVersion()
method toRemoteWebDriver
for programmatic browser version retrievalInclude unit test validating version extraction from capabilities
Add integration test demonstrating real browser session version display
Enhance test fixture with
validSessionResponder
for mock session creationDiagram Walkthrough
File Walkthrough
RemoteWebDriver.java
Add getBrowserVersion method to RemoteWebDriver
java/src/org/openqa/selenium/remote/RemoteWebDriver.java
getBrowserVersion()
public method to extract browser version fromcapabilities
browserVersion
capability is not availableRemoteWebDriverUnitTest.java
Add unit test for getBrowserVersion method
java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java
canGetBrowserVersionFromCapabilities()
unit testShowBrowserVersionIntegrationTest.java
Add integration test for browser version retrieval
java/test/org/openqa/selenium/remote/ShowBrowserVersionIntegrationTest.java
WebDriverFixture.java
Add validSessionResponder to test fixture
java/test/org/openqa/selenium/remote/WebDriverFixture.java
validSessionResponder
static function for mock session responses