Skip to content

Conversation

@nirtal85
Copy link
Owner

@nirtal85 nirtal85 commented Feb 27, 2025

Description

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Tests
    • Enhanced error reporting by capturing browser console messages and JavaScript errors during testing.
    • Improved logging by attaching collected console messages and JavaScript errors to the allure report for better insights when tests encounter issues.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Warning

Rate limit exceeded

@nirtal85 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f75fc3c and 87ee815.

📒 Files selected for processing (1)
  • tests/conftest.py (4 hunks)

Walkthrough

The changes update the test configuration in tests/conftest.py to capture browser console messages and JavaScript errors during test runs. A new global state is established using the variables console_messages and javascript_errors. Additionally, the Firefox driver is configured with modified options to enable the Bidirectional (Bidi) protocol. The logic now collects logs during test setup and, upon encountering an exception, attaches these logs to the Allure report instead of the previous browser logs.

Changes

File Changes Summary
tests/conftest.py - Added global variables console_messages and javascript_errors in pytest_runtest_setup
- Configured firefox_options to enable the Bidi protocol for Firefox
- Modified log handling: captures console messages and JavaScript errors during setup and attaches them in pytest_exception_interact

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant S as pytest_runtest_setup
    participant B as Firefox Browser
    participant E as pytest_exception_interact
    participant A as Allure Report

    T->>S: Begin test setup
    S->>B: Launch Firefox with firefox_options (Bidi enabled)
    B-->>S: Stream console messages & JS errors
    S-->>S: Store logs in global variables
    T->>E: Test error occurs
    E->>A: Attach console messages & JS errors (if browser is not "remote")
Loading

Suggested reviewers

  • elias-shoursoh

Poem

I hopped through lines of code so bright,
Collecting logs throughout the night,
Firefox dances with Bidi flair,
Errors and messages fill the air,
A bunny cheers this new delight! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0fb855 and a1b1da3.

📒 Files selected for processing (1)
  • tests/conftest.py (4 hunks)
🔇 Additional comments (3)
tests/conftest.py (3)

187-189: Good implementation of Bidi protocol for Firefox.

Enabling Bidirectional protocol for Firefox matches the Chrome implementation at line 161, providing consistent browser communication capabilities across both browsers. This is a good practice for test stability.


222-226: LGTM! Well-structured initialization of console event handlers.

Good approach to initialize the console message and JavaScript error handlers conditionally when not using remote browsers. Using append method provides a clean way to collect logs during test execution.


346-364:

❓ Verification inconclusive

Verify that console messages are captured correctly.

This implementation replaces the previous browser logs collection with more specific console and JavaScript error logging. Make sure all important information from the previous implementation is still being captured.


🌐 Web query:

What's the difference between Selenium's browser logs and the new WebDriver BiDi console messages?

💡 Result:

Selenium's traditional browser logs and WebDriver BiDi's console message handling differ fundamentally in their communication models, real-time capabilities, and integration with modern browser automation needs. Here's a breakdown of key differences:

Communication Architecture

  • Browser Logs (Classic):
    Relied on unidirectional HTTP requests where clients had to manually poll for log data[5][6]. This created latency and made real-time monitoring impractical.

  • WebDriver BiDi:
    Uses WebSockets for bidirectional communication[2][5], allowing browsers to push events like console messages directly to test scripts as they occur.

Real-Time Capabilities

  • Browser Logs:
    Required post-facto retrieval after page loads/actions[1][4], making it impossible to react to errors during test execution.

  • WebDriver BiDi:
    Enables immediate response to events through handlers like:

    driver.script.add_console_message_handler(log_entries.append)  # [8][10]

    This allows assertions on live console output during test execution[1][4].

Event Granularity

  • Browser Logs:
    Typically provided aggregated log data without context about specific user actions triggering them[6].

  • WebDriver BiDi:
    Captures rich metadata including:

    • Message types (log/warn/error)[1]
    • Timestamps[8]
    • Source line numbers[8]
    • Associated browsing contexts[9]

Integration with Testing Workflows

  • Browser Logs:
    Required separate log collection mechanisms that weren't natively integrated with test assertions[6].

  • WebDriver BiDi:
    Directly integrates with test scripts through event listeners:

    page.on('console', (message) => {
      console.log(`[${message.type()}] ${message.text()}`);  // [1][3]
    });

    Enables real-time validation of application behavior during complex user flows[2][10].

Cross-Browser Consistency

  • Browser Logs:
    Implementation varied significantly between browsers due to lack of standardization[3][5].

  • WebDriver BiDi:
    W3C-standardized protocol ensures consistent console message handling across Chrome, Firefox, and Edge[3][9].

The shift to WebDriver BiDi represents a paradigm change from passive log collection to active event monitoring, particularly valuable for modern web apps with dynamic content and client-side error handling. While traditional logs remain useful for post-mortem analysis, BiDi's real-time capabilities enable proactive error detection during test execution[1][3][6].

Citations:


Ensure Comprehensive Validation of Console & JavaScript Error Logging

The updated logging strategy in tests/conftest.py (lines 346-364) now leverages WebDriver BiDi to capture console messages and JavaScript errors. As confirmed by the web query, this modern approach allows for real-time and metadata-rich logging compared to the traditional Selenium browser logs—which were based on HTTP polling and often lacked detailed context (e.g., timestamps, log levels, source information).

  • Confirm that all essential log details previously available via browser logs are either captured by the new event-driven mechanism or are no longer required.
  • Verify that the log collections (both for console messages and JavaScript errors) are properly formatted and attached to Allure, ensuring that critical debugging information isn’t inadvertently lost.
  • Consider running tests under various scenarios to ensure that the real-time logging accurately reflects the necessary details for troubleshooting.

nirtal85 and others added 2 commits February 28, 2025 01:26
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/conftest.py (2)

137-137: Consider reducing the use of global variables.

Adding global variables for console_messages and javascript_errors works, but global state can make testing and debugging harder. Consider refactoring to use a class or context manager to manage this state.


222-226: Add a comment explaining why remote browsers are excluded.

The code correctly sets up handlers for console messages and JavaScript errors, but it would be helpful to add a brief comment explaining why remote browsers are excluded from this functionality.

 if browser != "remote":
+    # Bidi protocol handlers not compatible with remote WebDriver
     console_messages = []
     driver.script.add_console_message_handler(console_messages.append)
     javascript_errors = []
     driver.script.add_javascript_error_handler(javascript_errors.append)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1b1da3 and f75fc3c.

📒 Files selected for processing (1)
  • tests/conftest.py (4 hunks)
🔇 Additional comments (2)
tests/conftest.py (2)

187-189: LGTM! Bidi support for Firefox properly enabled.

The implementation correctly enables the Bidirectional protocol for Firefox, which is needed to capture console messages and JavaScript errors.


349-363: Properly implemented console and error logging.

The code correctly formats and attaches console messages and JavaScript errors to the Allure report. The previous issue with JavaScript error attachment has been fixed.

I notice that you've implemented the suggested fix from the previous review by correctly joining and converting the JavaScript errors to strings before attaching them to the report.

@nirtal85 nirtal85 merged commit dc32e62 into main Feb 28, 2025
3 checks passed
@nirtal85 nirtal85 deleted the bidi-console-events branch February 28, 2025 06:13
This was referenced Feb 28, 2025
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.

2 participants