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
flowchart LR
A["Test Setup"] --> B["Navigate to Page"]
B --> C["Register Event Listener"]
C --> D["Execute history.pushState"]
D --> E["Verify Event Data"]
The test relies on receiving a HistoryUpdated event within 5 seconds after history.pushState; event timing could be flaky on slower environments. Consider increasing timeout or adding retry/wait for readiness to reduce flakiness.
The evaluateFunctionInBrowsingContext call uses "history.pushState({}, '', '/new-path')" without awaiting completion or verifying execution result; if execution is async or sandboxed, event may not fire. Consider checking evaluation result or ensuring user activation/context permissions if required.
// Use history.pushState to trigger history updated eventscript.evaluateFunctionInBrowsingContext(
context.getId(), "history.pushState({}, '', '/new-path')", false, Optional.empty());
HistoryUpdatedhistoryUpdated = future.get(5, TimeUnit.SECONDS);
assertThat(historyUpdated.getBrowsingContextId()).isEqualTo(context.getId());
assertThat(historyUpdated.getUrl()).contains("/new-path");
Avoid using try-with-resources for a type that does not implement AutoCloseable. Instantiate Script as a regular variable inside the block so the code compiles across Selenium versions.
-try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver);- Script script = new Script(driver)) {+try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {+ Script script = new Script(driver);
Apply / Chat
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies that Script does not implement AutoCloseable and therefore cannot be used in a try-with-resources statement, which would cause a compilation error.
High
Wrap expression in arrow function
evaluateFunctionInBrowsingContext expects a function declaration, not a raw expression. Wrap the call in an arrow function to prevent an "invalid functionDeclaration" error at runtime.
Why: The suggestion correctly points out that evaluateFunctionInBrowsingContext expects a function declaration, and the provided code passes a raw expression, which would cause a runtime error. The proposed fix is correct.
High
Learned best practice
Use precise URL path assertion
Parse the URL and assert on its path to validate precisely that the navigation updated the expected path segment.
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
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
🔗 Related Issues
💥 What does this PR do?
Adds test for
onHistoryUpdatedevent.🔧 Implementation Notes
💡 Additional Considerations
🔄 Types of changes
PR Type
Tests
Description
Add test for
onHistoryUpdatedBiDi eventTest uses
history.pushStateto trigger eventValidates browsing context ID and URL changes
Diagram Walkthrough
File Walkthrough
BrowsingContextInspectorTest.java
Add history updated event testjava/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java
OptionalandScriptmodulecanListenToHistoryUpdatedEventtest methodhistory.pushState