You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or 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
Thanks for contributing to the Selenium site and documentation! A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Demonstrate usage of log handlers.
Motivation and Context
Types of changes
Change to the site (I have double-checked the Netlify deployment, and my changes look good)
Code example added (and I also added the example to all translated languages)
Improved translation
Added new translation (and I also added a notice to each document missing translation)
Code Duplication The setup method for initializing the FirefoxDriver with FirefoxOptions is repeated in each test. Consider refactoring this into a common setup method to avoid redundancy and make the code cleaner.
long id = ((RemoteWebDriver) driver).script().addConsoleMessageHandler(future::complete);
-...-((RemoteWebDriver) driver).script().removeConsoleMessageHandler(id);+try {+ ...+} finally {+ ((RemoteWebDriver) driver).script().removeConsoleMessageHandler(id);+}
Suggestion importance[1-10]: 9
Why: This suggestion ensures that resources are reliably cleaned up, which is crucial for preventing resource leaks and ensuring test reliability. It addresses a significant best practice.
9
Add pre-action assertions to verify the correct state of elements
Consider adding assertions to check the state before performing actions to ensure that the test environment is set up correctly.
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
+Assertions.assertTrue(driver.findElement(By.id("consoleLog")).isDisplayed(), "Console log button should be visible");
driver.findElement(By.id("consoleLog")).click();
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Adding pre-action assertions enhances the robustness of the tests by ensuring that the environment is correctly set up before actions are performed. This is a good practice for reliable test execution.
8
Maintainability
Improve flexibility and maintainability of the driver initialization
Replace the direct instantiation of FirefoxDriver with a more flexible driver initialization. This allows for easier updates or changes to the browser driver without modifying the test setup method directly.
FirefoxOptions options = new FirefoxOptions();
options.setCapability("webSocketUrl", true);
-driver = new FirefoxDriver(options);+driver = createDriver(options);
Apply this suggestion
Suggestion importance[1-10]: 7
Why: This suggestion improves the flexibility and maintainability of the code by abstracting the driver initialization. However, it is not a critical change and does not address any major issues.
7
Use constants for repeated literal values to enhance maintainability
Refactor repeated URL strings into a constant to avoid duplication and facilitate changes.
-driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");+private static final String TEST_PAGE_URL = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
...
-driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");+driver.get(TEST_PAGE_URL);+...+driver.get(TEST_PAGE_URL);
Suggestion importance[1-10]: 6
Why: Using constants for repeated literal values improves maintainability by reducing duplication and making future changes easier. However, it is a minor improvement and not critical.
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.
User description
Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Demonstrate usage of log handlers.
Motivation and Context
Types of changes
Checklist
PR Type
Tests
Description
LogTest
to demonstrate the usage of BiDi API log handlers in Java.FirefoxDriver
with WebSocket capability.Changes walkthrough 📝
LogTest.java
Add BiDi API log handling tests in Java
examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/high_level/LogTest.java
LogTest
for BiDi API log examples.FirefoxDriver
with WebSocketcapability.