Skip to content

Log examples added for Ruby using Chrome #1730

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 2 commits into from
May 19, 2024

Conversation

aguspe
Copy link
Contributor

@aguspe aguspe commented May 17, 2024

User description

Description

This is a continuation of the previous updates on special features for Chrome, now adding an example of how to get logs using ruby

Motivation and Context

It's important to keep the documentation and examples up to date for the selenium community to have good references

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.

PR Type

enhancement, documentation


Description

  • Added a new test in Ruby to demonstrate how to retrieve browser logs in Chrome.
  • Updated documentation in English, Japanese, Portuguese, and Chinese to include a link to the new Ruby example.

Changes walkthrough 📝

Relevant files
Enhancement
chrome_spec.rb
Add Ruby Test for Retrieving Chrome Browser Logs                 

examples/ruby/spec/browsers/chrome_spec.rb

  • Added a new test case to get browser logs using Ruby with Chrome.
  • The test navigates to a URL and retrieves the browser logs, checking
    for a specific log message.
  • +9/-0     
    Documentation
    chrome.en.md
    Update English Chrome Documentation with Ruby Example Link

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

  • Updated the Ruby tab to link to the new browser log example in the
    Ruby code.
  • +1/-1     
    chrome.ja.md
    Update Japanese Chrome Documentation with Ruby Example Link

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

  • Updated the Ruby tab to link to the new browser log example in the
    Ruby code.
  • +1/-1     
    chrome.pt-br.md
    Update Portuguese Chrome Documentation with Ruby Example Link

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

  • Updated the Ruby tab to link to the new browser log example in the
    Ruby code.
  • +1/-1     
    chrome.zh-cn.md
    Update Chinese Chrome Documentation with Ruby Example Link

    website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md

  • Updated the Ruby tab to link to the new browser log example in the
    Ruby code.
  • +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Sorry, something went wrong.

    Copy link

    netlify bot commented May 17, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit b279a98

    @qodo-merge-pro qodo-merge-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels May 17, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (9c30e7b)

    Sorry, something went wrong.

    Copy link
    Contributor

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the PR primarily involves adding a new test example and updating documentation. The changes are straightforward and localized, making it relatively easy to review.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Possible Flakiness: The use of sleep 1 in the test code could lead to flakiness in test execution. It's generally better to use explicit waits or other synchronization mechanisms.

    🔒 Security concerns

    No

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Replace sleep with explicit waits to enhance test reliability

    Replace the sleep method with a more reliable waiting mechanism to ensure that the browser
    logs are ready to be fetched. Using sleep can lead to flaky tests due to varying load
    times. Consider using explicit waits provided by Selenium WebDriver.

    examples/ruby/spec/browsers/chrome_spec.rb [141]

    -sleep 1
    +Selenium::WebDriver::Wait.new(timeout: 10).until { @driver.execute_script('return document.readyState') == 'complete' }
     
    Suggestion importance[1-10]: 8

    Why: Replacing sleep with explicit waits is a significant improvement for test reliability and accuracy, addressing potential flakiness.

    8
    Improve the robustness of log message checking

    Use a more specific assertion to check for the presence of the error message in the
    browser logs. This ensures that the test is more robust and less likely to fail due to
    unexpected log messages.

    examples/ruby/spec/browsers/chrome_spec.rb [144]

    -expect(logs.first.message).to include 'Failed to load resource'
    +expect(logs.any? { |log| log.message.include?('Failed to load resource') }).to be true
     
    Suggestion importance[1-10]: 6

    Why: Improving the specificity of assertions enhances test robustness, but the impact is moderate as it refines existing functionality rather than addressing a major flaw.

    6
    Best practice
    Add cleanup code to quit WebDriver after tests

    Ensure proper cleanup by adding an after block to quit the WebDriver session. This helps
    in preventing resource leakage and ensures that each test is isolated.

    examples/ruby/spec/browsers/chrome_spec.rb [138-145]

     it 'gets the browser logs' do
       @driver = Selenium::WebDriver.for :chrome
       @driver.navigate.to 'https://www.selenium.dev/selenium/web/'
       sleep 1
       logs = @driver.logs.get(:browser)
       expect(logs.first.message).to include 'Failed to load resource'
     end
     
    +after do
    +  @driver.quit
    +end
    +
    Suggestion importance[1-10]: 7

    Why: Adding an after block for cleanup is a good practice to prevent resource leakage and ensure test isolation, although it's a common practice rather than a critical fix.

    7
    Maintainability
    Manage WebDriver instances more safely to prevent resource leaks

    Initialize the WebDriver instance using a context manager or ensure it's properly handled
    to avoid starting multiple sessions or leaving sessions open, which can affect subsequent
    tests or system resources.

    examples/ruby/spec/browsers/chrome_spec.rb [139]

    -@driver = Selenium::WebDriver.for :chrome
    +begin
    +  @driver = Selenium::WebDriver.for :chrome
    +  # rest of the code
    +ensure
    +  @driver.quit
    +end
     
    Suggestion importance[1-10]: 7

    Why: Managing WebDriver instances properly is crucial for resource management and test reliability, making this a valuable suggestion for maintainability.

    7

    Copy link
    Member

    @harsha509 harsha509 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 @aguspe !

    @harsha509 harsha509 merged commit fc1ed22 into SeleniumHQ:trunk May 19, 2024
    9 checks passed
    selenium-ci added a commit that referenced this pull request May 19, 2024
    Add logs examples in ruby
    
    Co-authored-by: aguspe <[email protected]> fc1ed22
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants