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

[java]: add docs for retrieving logs in chrome and edge #2083

Merged
merged 5 commits into from
Nov 29, 2024

Conversation

navin772
Copy link
Contributor

@navin772 navin772 commented Nov 27, 2024

User description

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

Added docs for java to get the logs in chrome and edge.
Also, updated the python get_log example to use https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html

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

documentation, tests


Description

  • Added Java tests for retrieving browser logs in Chrome and Edge.
  • Updated Python tests for Chrome and Edge to use a new URL and log message.
  • Updated documentation to include references to the new Java code examples for retrieving logs.

Changes walkthrough 📝

Relevant files
Tests
4 files
test_chrome.py
Update Python Chrome test for browser logs retrieval         

examples/python/tests/browsers/test_chrome.py

  • Updated the URL in test_get_browser_logs.
  • Added a click action on an element with ID consoleError.
  • Modified the log assertion message.
  • +4/-4     
    test_edge.py
    Update Python Edge test for browser logs retrieval             

    examples/python/tests/browsers/test_edge.py

  • Updated the URL in test_get_browser_logs.
  • Added a click action on an element with ID consoleError.
  • Modified the log assertion message.
  • +4/-4     
    ChromeTest.java
    Add Java test for retrieving Chrome browser logs                 

    examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java

  • Added a new test method getBrowserLogs.
  • Implemented log retrieval and assertion for Chrome.
  • +25/-3   
    EdgeTest.java
    Add Java test for retrieving Edge browser logs                     

    examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java

  • Added a new test method getBrowserLogs.
  • Implemented log retrieval and assertion for Edge.
  • +25/-3   
    Documentation
    8 files
    chrome.en.md
    Update Chrome documentation with Java log example               

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

    • Updated Java code example reference for Chrome logs.
    +1/-1     
    chrome.ja.md
    Update Chrome documentation with Java log example (Japanese)

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

    • Updated Java code example reference for Chrome logs.
    +1/-1     
    chrome.pt-br.md
    Update Chrome documentation with Java log example (Portuguese)

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

    • Updated Java code example reference for Chrome logs.
    +1/-1     
    chrome.zh-cn.md
    Update Chrome documentation with Java log example (Chinese)

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

    • Updated Java code example reference for Chrome logs.
    +1/-1     
    edge.en.md
    Update Edge documentation with Java log example                   

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

    • Updated Java code example reference for Edge logs.
    +1/-1     
    edge.ja.md
    Update Edge documentation with Java log example (Japanese)

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

    • Updated Java code example reference for Edge logs.
    +1/-1     
    edge.pt-br.md
    Update Edge documentation with Java log example (Portuguese)

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

    • Updated Java code example reference for Edge logs.
    +1/-1     
    edge.zh-cn.md
    Update Edge documentation with Java log example (Chinese)

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

    • Updated Java code example reference for Edge logs.
    +1/-1     

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

    Copy link

    netlify bot commented Nov 27, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 0df07ac

    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

    Resource Leak
    The driver instance is not properly closed in case of assertion failure. Consider using try-finally or try-with-resources to ensure driver cleanup.

    Resource Leak
    The driver instance is not properly closed in case of assertion failure. Consider using try-finally or try-with-resources to ensure driver cleanup.

    Error Handling
    The test lacks proper error handling for cases where the log message might not be found or when the element click fails.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Ensure proper resource cleanup by using try-finally block for WebDriver management

    Add a try-finally block to ensure the WebDriver is properly closed even if an
    assertion fails or an exception occurs during test execution.

    examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java [241-260]

     @Test
     public void getBrowserLogs() {
       ChromeDriver driver = new ChromeDriver();
    -  driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
    -  WebElement consoleLogButton = driver.findElement(By.id("consoleError"));
    -  consoleLogButton.click();
    +  try {
    +    driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
    +    WebElement consoleLogButton = driver.findElement(By.id("consoleError"));
    +    consoleLogButton.click();
     
    -  LogEntries logs = driver.manage().logs().get(LogType.BROWSER);
    +    LogEntries logs = driver.manage().logs().get(LogType.BROWSER);
     
    -  // Assert that at least one log contains the expected message
    -  boolean logFound = false;
    -  for (LogEntry log : logs) {
    -    if (log.getMessage().contains("I am console error")) {
    -      logFound = true;
    -      break;
    +    // Assert that at least one log contains the expected message
    +    boolean logFound = false;
    +    for (LogEntry log : logs) {
    +      if (log.getMessage().contains("I am console error")) {
    +        logFound = true;
    +        break;
    +      }
         }
    +
    +    Assertions.assertTrue(logFound, "No matching log message found.");
    +  } finally {
    +    driver.quit();
       }
    -
    -  Assertions.assertTrue(logFound, "No matching log message found.");
    -  driver.quit();
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion improves code reliability by ensuring the WebDriver is properly closed even if an assertion fails or an exception occurs, preventing resource leaks. This is a critical best practice for WebDriver resource management.

    8

    💡 Need additional feedback ? start a PR chat

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

    @harsha509 harsha509 merged commit 33a0c76 into SeleniumHQ:trunk Nov 29, 2024
    15 checks passed
    @navin772 navin772 deleted the java-get_log branch November 29, 2024 15:24
    selenium-ci added a commit that referenced this pull request Nov 29, 2024
    …y site]
    
    * add docs for get_logs in java for chrome and edge
    
    * update python docs to use new site for `get_log`
    
    ---------
    
    Co-authored-by: Sri Harsha <[email protected]> 33a0c76
    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