Skip to content

Add tested Java and Python examples for the Listeners page - #3000

Open
Mohsintl wants to merge 6 commits into
SeleniumHQ:trunkfrom
Mohsintl:listeners-examples
Open

Mohsintl wants to merge 6 commits into
SeleniumHQ:trunkfrom
Mohsintl:listeners-examples

Conversation

@Mohsintl

Copy link
Copy Markdown

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Description

Part of #2890. The Command Listeners page showed "add example" in every language, and ListenersTest.java and test_listener.py were empty stubs.

  • Python (examples/python/tests/support/test_listener.py): a RecordingListener(AbstractEventListener) with after_navigate_to and before_click, registered with EventFiringWebDriver.
  • Java (examples/java/src/test/java/dev/selenium/support/ListenersTest.java): the same listener as a WebDriverListener, registered with EventFiringDecorator.
  • Both tests open formPage.html, click a checkbox and assert the recorded events, so a broken example fails CI.
  • The page renders two blocks per language (the listener, then registering it) in the en, ja, pt-br and zh-cn files. C#, Ruby, JavaScript and Kotlin keep their placeholders.

One thing worth knowing for Java: EventFiringDecorator calls listener methods through reflection, so a listener class that is not public is skipped without any error (the events list stays empty). The example says so in a one-line comment, which shows on the page in every translation.

Motivation and Context

#2890 asks to complete the examples for the pages in llms.txt; the Listeners page is one of them.

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)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

I ran the tests locally (Selenium 4.52, Chrome): the Python test with pytest 4/4 and the Java test with Maven. With the click sent through the undecorated driver, both fail on the missing click event. I did not render the site with Hugo locally; I'll check the Netlify preview.

The Listeners page showed placeholders in every language, and the Java
and Python example files were empty stubs. Both now hold a listener that
records a navigation and a click, and a test that registers it on the
driver and checks the events. The page renders them in all translations.
@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit aa69e77

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@rpallavisharma
rpallavisharma requested review from AutomatedTester and diemol and a balanced review from Copilot and removed request for Copilot November 23, 2026 06:08
@rpallavisharma

Copy link
Copy Markdown
Member

@Mohsintl - please see error -
[ERROR] Tests run: 6, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 361.8 s <<< FAILURE! -- in dev.selenium.browsers.InternetExplorerTest
[ERROR] dev.selenium.browsers.InternetExplorerTest.basicOptionsWin11 -- Time elapsed: 190.1 s <<< ERROR!
org.openqa.selenium.SessionNotCreatedException:
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. null
Host info: host: 'runnervmbpeip', ip: '10.1.0.103'
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:726)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:311)
at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:123)
at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:93)
at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:89)
at dev.selenium.browsers.InternetExplorerTest.basicOptionsWin11(InternetExplorerTest.java:47)
Suppressed: java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.ie.InternetExplorerDriver.quit()" because "this.driver" is null
at dev.selenium.browsers.InternetExplorerTest.quit(InternetExplorerTest.java:33)
Caused by: org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException

@Mohsintl

Copy link
Copy Markdown
Author

Thanks! Both failures are in tests this PR doesn't change: InternetExplorerTest.basicOptionsWin11 couldn't start an IE session on the Windows runner, and NetworkCommandsTest.canContinueWithoutAuthCredentials also fails on trunk (run). ListenersTest passed on every job. Could you re-run the failed jobs?

@AutomatedTester AutomatedTester left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Mohsintl, this looks good. I checked it against .github/pr_review.md:

  • The gh-codeblock ranges are right in all four translations: Java #L16-L29 is the listener class (with the public comment) and #L33-L37 is the registration; Python #L5-L13 and #L17-L21 match the same two parts. No lines are indented and the tabpane keeps text=true.
  • Both tests assert the recorded events, so a broken example will fail CI, and they use formPage.html from the Selenium test pages.

Minor (not blocking): ListenersTest.java line 27 uses element.getAttribute("id"), which is deprecated in Selenium Java since 4.27. Because that line is shown on the page, readers will copy it. element.getDomAttribute("id") returns the same value here and keeps the example on the current API.

About the red tests (windows, stable) job: it is not caused by this PR. InternetExplorerTest.basicOptionsWin11 timed out starting IE on the first try, then passed on the retry, so Surefire lists it under "Flakes". The job failed because NetworkCommandsTest.canContinueWithoutAuthCredentials failed all 4 attempts with a null page source; the same test fails on trunk (run 45135567526 and recent scheduled runs) and on other open PRs. ListenersTest passed on every job.


Generated by Claude Code

getAttribute is deprecated in Selenium Java since 4.27, and this line is shown on the Listeners page.
@Mohsintl

Copy link
Copy Markdown
Author

Thanks for the review and the getAttribute tip, and the update about deprecation! Switched to getDomAttribute("id") in 2d1d4b3, same line, so the page range is unchanged and the test still passes.

@rpallavisharma

Copy link
Copy Markdown
Member

@SeleniumHQ/selenium-tlc please see.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants