Skip to content

[java][bidi]: add browsingContext event onNavigationCommitted #15560

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

Merged
merged 8 commits into from
Apr 22, 2025

Conversation

navin772
Copy link
Member

@navin772 navin772 commented Apr 3, 2025

User description

🔗 Related Issues

💥 What does this PR do?

Implements the onNavigationCommitted bidi event in browsingContext for the java bindings - https://w3c.github.io/webdriver-bidi/#event-browsingContext-navigationCommitted.

Currently, for stable browsers only Chrome supports this as per the WPT tests

This PR also adds a test for onNavigationCommitted event for Chrome.
I have also changed the other methods from private to public.

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

PR Type

Enhancement, Tests


Description

  • Added onNavigationCommitted event support in BrowsingContextInspector.

  • Changed visibility of several methods from private to public.

  • Introduced a test for onNavigationCommitted event in Chrome.

  • Marked the test as not yet implemented for Edge and Firefox.


Changes walkthrough 📝

Relevant files
Enhancement
BrowsingContextInspector.java
Added `onNavigationCommitted` and updated method visibility

java/src/org/openqa/selenium/bidi/module/BrowsingContextInspector.java

  • Added onNavigationCommitted event listener method.
  • Changed visibility of onDownloadWillBegin, onNavigationAborted, and
    onNavigationFailed methods from private to public.
  • +7/-3     
    Tests
    BrowsingContextInspectorTest.java
    Added test for `onNavigationCommitted` event                         

    java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java

  • Added a test for onNavigationCommitted event.
  • Marked the test as not yet implemented for Edge and Firefox.
  • Imported additional dependencies for browser-specific annotations.
  • +21/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @titusfortner titusfortner added C-java Java Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Apr 3, 2025
    Copy link
    Contributor

    qodo-merge-pro bot commented Apr 3, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ❌

    5678 - Not compliant

    Non-compliant requirements:

    • Fix "Error: ConnectFailure (Connection refused)" when instantiating ChromeDriver multiple times

    Requires further human verification:

    • Need to verify if the PR's BiDi implementation has any impact on the ChromeDriver connection issue

    1234 - Not compliant

    Non-compliant requirements:

    • Fix issue where JavaScript in link's href is not triggered on click() in Firefox 42.0

    Requires further human verification:

    • Need to verify if the BiDi implementation affects JavaScript execution in Firefox

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Test Coverage

    The test only verifies that the event is received and basic properties are correct. Consider adding tests for edge cases or different navigation scenarios.

    @Test
    @NeedsFreshDriver
    @NotYetImplemented(EDGE)
    @NotYetImplemented(FIREFOX)
    void canListenToNavigationCommittedEvent()
        throws ExecutionException, InterruptedException, TimeoutException {
      try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
        CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
    
        BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
        inspector.onNavigationCommitted(future::complete);
        context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
    
        NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
        assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
        assertThat(navigationInfo.getUrl()).contains("/bidi/logEntryAdded.html");
      }
    }

    Copy link
    Contributor

    qodo-merge-pro bot commented Apr 3, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Learned
    best practice
    Add null validation for method parameters to prevent potential NullPointerExceptions

    The consumer parameter should be validated for null before use to prevent
    potential NullPointerExceptions. Add a null check using
    ArgumentNullException.ThrowIfNull() or a similar validation method at the
    beginning of the method.

    java/src/org/openqa/selenium/bidi/module/BrowsingContextInspector.java [155-157]

     public void onNavigationCommitted(Consumer<NavigationInfo> consumer) {
    +  Objects.requireNonNull(consumer, "Consumer cannot be null");
       addNavigationEventListener("browsingContext.navigationCommitted", consumer);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • Update

    @navin772 navin772 requested a review from pujagani April 3, 2025 13:37
    @navin772 navin772 requested a review from Copilot April 4, 2025 10:05
    Copy link

    @Copilot Copilot AI left a comment

    Choose a reason for hiding this comment

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

    Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

    @navin772
    Copy link
    Member Author

    Hi @pujagani, can you review this?

    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! @navin772

    @pujagani pujagani merged commit 1eba709 into SeleniumHQ:trunk Apr 22, 2025
    33 checks passed
    @navin772 navin772 deleted the java-bidi-onNavigationCommitted branch April 22, 2025 10:49
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    B-devtools Includes everything BiDi or Chrome DevTools related C-java Java Bindings Review effort 2/5
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants