Skip to content
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

Add test for enabling Safari browser logging in JavaScript #2127

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

yvsvarma
Copy link
Contributor

@yvsvarma yvsvarma commented Jan 13, 2025

User description

This PR introduces a new JavaScript test to validate the functionality of enabling browser-level logging in Safari. Key updates include:

  • Added a test using setLoggingPrefs to enable logging for the Safari browser.
  • Updated the Selenium documentation by including the example on this page: Safari-Logging-JavaScript

This enhancement ensures proper validation of Safari's logging capabilities and improves test coverage for Safari-specific features.

Tests are passing locally.


PR Type

Tests, Documentation


Description

  • Added a new JavaScript test for enabling Safari browser logging.

  • Updated Safari documentation with a JavaScript example for logging.

  • Enhanced test coverage for Safari-specific features.

  • Improved multilingual documentation for Safari logging in JavaScript.


Changes walkthrough 📝

Relevant files
Tests
safariSpecificCap.spec.js
Add Safari logging test in JavaScript                                       

examples/javascript/test/browser/safariSpecificCap.spec.js

  • Added a new test to enable Safari browser logging.
  • Configured setLoggingPrefs for browser-level logging.
  • Ensured the test runs conditionally on macOS.
  • +19/-0   
    Documentation
    safari.en.md
    Update Safari documentation with JavaScript example           

    website_and_docs/content/documentation/webdriver/browsers/safari.en.md

  • Updated JavaScript example link for Safari logging.
  • Replaced placeholder with a specific code reference.
  • +1/-1     
    safari.ja.md
    Update Japanese Safari documentation with JavaScript example

    website_and_docs/content/documentation/webdriver/browsers/safari.ja.md

  • Updated JavaScript example link for Safari logging.
  • Replaced placeholder with a specific code reference.
  • +1/-1     
    safari.pt-br.md
    Update Portuguese Safari documentation with JavaScript example

    website_and_docs/content/documentation/webdriver/browsers/safari.pt-br.md

  • Updated JavaScript example link for Safari logging.
  • Replaced placeholder with a specific code reference.
  • +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    netlify bot commented Jan 13, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit e8e22a5

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Error Handling

    The test enables browser logging but doesn't verify if logs were actually captured or check their content. Consider adding log verification after the page load.

    try {
      await driver.get('https://www.selenium.dev/');
    } finally {
    Test Timeout

    The timeout is set to 15 seconds but there's no clear justification for this specific duration. Consider documenting why this timeout value was chosen.

    this.timeout(15000); 

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Add verification step to ensure browser logging is properly configured and accessible

    Add error handling to verify that the logging preferences were set correctly. Check
    the browser logs after navigation to ensure logging is working as expected.

    examples/javascript/test/browser/safariSpecificCap.spec.js [29-33]

     try {
       await driver.get('https://www.selenium.dev/');
    +  const logs = await driver.manage().logs().get('browser');
    +  assert(logs.length >= 0, 'Browser logs should be accessible');
     } finally {
       await driver.quit();
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion adds crucial validation to verify that the logging functionality is working as expected, which is essential given this is a test specifically for Safari logging capabilities.

    8
    Increase test timeout duration to accommodate varying network conditions

    The timeout value of 15000ms might be too short for slower connections. Consider
    increasing it or making it configurable.

    examples/javascript/test/browser/safariSpecificCap.spec.js [19]

    -this.timeout(15000);
    +this.timeout(process.env.TEST_TIMEOUT || 30000);
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Making the timeout configurable via environment variable is a good practice for test reliability across different environments, though the current timeout might be sufficient for most cases.

    5
    Possible issue
    Add defensive initialization check for browser options to prevent runtime errors

    Initialize Safari options before the test to avoid potential undefined variable
    issues.

    examples/javascript/test/browser/safariSpecificCap.spec.js [21-22]

    -const options = new safari.Options()
    -  .setLoggingPrefs({ browser: 'ALL' });
    +const options = new safari.Options();
    +if (!options) {
    +  throw new Error('Failed to initialize Safari options');
    +}
    +options.setLoggingPrefs({ browser: 'ALL' });
    • Apply this suggestion
    Suggestion importance[1-10]: 2

    Why: The suggestion is unnecessary as the safari.Options() constructor will throw if it fails, and the additional check adds complexity without meaningful benefit.

    2

    });

    describe('Should be able to enable Safari logging', function () {
    this.timeout(15000);
    Copy link
    Member

    Choose a reason for hiding this comment

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

    why we need timeout in here ?

    Copy link
    Member

    Choose a reason for hiding this comment

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

    And i don't think this is the right example , Can you check again!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants