- 
 
- 
  Notifications
 You must be signed in to change notification settings 
- Fork 1.5k
Add WebDriverListener example with logging #2384
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
... config for Windows - Added example of `WebDriverListener` with logging before `findElement` and `click`. - Included logic to capture screenshots on error for better debugging. - Updated `junit-platform.properties` for Windows compatibility: - forkCount = 0 - junit.jupiter.execution.parallel.config.fixed.parallelism = 1 - junit.jupiter.execution.parallel.config.fixed.max-pool-size = 1 -Run test : mvn clean test -Dtest=WebDriverListenerTest
| 👷 Deploy request for selenium-dev pending review.Visit the deploys page to approve it 
 | 
CLA assistant check 
All committers have signed the CLA.
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
Redundant Logic
The beforeFindElement and beforeFindElements methods contain identical logic that calls findElements again, which could cause performance issues and infinite recursion. This debug counting should be removed or implemented differently.
try { if (driver instanceof HasCapabilities) { List<WebElement> elements = driver.findElements(locator); logger.info("DEBUG: Number of elements matching '" + locator + "': " + elements.size()); } } catch (Exception e) { logger.warning("Error while counting elements for locator " + locator + ": " + e.getMessage()); } } @Override public void afterFindElement(WebDriver driver, By locator, WebElement result) { logger.info("AFTER findElement -> Locator: " + locator + ", Result: " + getElementInfo(result)); } @Override public void beforeFindElements(WebDriver driver, By locator) { logger.info("BEFORE findElements -> Locator: " + locator); try { if (driver instanceof HasCapabilities) { List<WebElement> elements = driver.findElements(locator); logger.info("DEBUG: Number of elements matching '" + locator + "': " + elements.size()); } } catch (Exception e) { logger.warning("Error while counting elements for locator " + locator + ": " + e.getMessage()); }
Configuration Issue
The Maven Surefire configuration has malformed XML with incomplete configurationParameters tag and comments inside XML values, which could cause build failures.
<configurationParameters> junit.jupiter.execution.parallel.enabled = true junit.jupiter.execution.parallel.mode.default = concurrent junit.jupiter.execution.parallel.config.strategy = fixed <!-- Fix Failed to transform configuration parameter with key 'junit.jupiter.execution.parallel.config.fixed.parallelism' and initial value ' --> junit.jupiter.execution.parallel.config.fixed.parallelism = 1 junit.jupiter.execution.parallel.config.fixed.max-pool-size = 1 </configurationParameters>
Resource Leak
WebDriver instances are not properly managed with try-with-resources or @AfterEach cleanup, potentially causing resource leaks if tests fail before reaching quit() calls.
private WebDriver driver; @Test @Order(1) public void testWebDriverListener() { WebDriverListener listener = new CustomWebDriverListener(); driver = new EventFiringDecorator<>(listener).decorate(new ChromeDriver()); driver.get("https://www.selenium.dev/"); driver.manage().window().maximize(); WebElement documentation = driver.findElement(By.cssSelector("a[href='/documentation']")); documentation.click(); driver.quit(); } @Test @Order(2) public void testWebDriverListenerOnError() { WebDriverListener listener = new CustomWebDriverListener(); driver = new EventFiringDecorator<>(listener).decorate(new ChromeDriver()); try { driver.get(null); } catch (NullPointerException e) { e.printStackTrace(); } driver.quit(); }
| PR Code Suggestions ✨Explore these optional code suggestions: 
 | ||||||||||
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.
Hi Selenium teams, so pleas help me check first pr
Uh oh!
There was an error while loading. Please reload this page.
User description
Add WebDriverListener example with logging
WebDriverListenerwith logging beforefindElementandclick.junit-platform.propertiesfor Windows compatibility:PR Type
Tests, Enhancement
Description
Add WebDriverListener example with comprehensive logging functionality
Fix Maven Surefire configuration for Windows compatibility
Include screenshot capture on error for debugging
Update documentation with working code example
Diagram Walkthrough
File Walkthrough
pom.xml
Fix Maven Surefire Windows compatibility configurationexamples/java/pom.xml
forkCountto 0 to resolve fork startup errorsCustomWebDriverListener.java
Add comprehensive WebDriverListener with logging and screenshotsexamples/java/src/test/java/dev/selenium/listeners/CustomWebDriverListener.java
WebDriverListenerTest.java
Add WebDriverListener test examplesexamples/java/src/test/java/dev/selenium/listeners/WebDriverListenerTest.java
listeners.en.md
Update listeners documentation with code examplewebsite_and_docs/content/documentation/webdriver/support_features/listeners.en.md