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

[py] move interactions code to code examples #2085

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

Delta456
Copy link
Contributor

@Delta456 Delta456 commented Nov 28, 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

Moved python interactions example to code files

Motivation and Context

Easier navigation and better UI/UX

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 Python test file for Selenium interactions, demonstrating how to interact with web elements using WebDriver.
  • Updated documentation in multiple languages (English, Japanese, Portuguese, Chinese) to reference the new Python test file instead of inline code.
  • Improved the organization and clarity of the documentation by linking to a centralized code example.

Changes walkthrough 📝

Relevant files
Tests
test_interaction.py
Add Python test for Selenium interactions                               

examples/python/tests/elements/test_interaction.py

  • Added a new test for interactions using Selenium WebDriver.
  • Included steps to navigate, interact with elements, and verify
    actions.
  • Utilized pytest for test execution.
  • +37/-0   
    Documentation
    interactions.en.md
    Update English documentation with Python code reference   

    website_and_docs/content/documentation/webdriver/elements/interactions.en.md

  • Replaced inline Python code with a reference to the new code example.
  • Improved documentation by linking to the Python test file.
  • +3/-26   
    interactions.ja.md
    Update Japanese documentation with Python code reference 

    website_and_docs/content/documentation/webdriver/elements/interactions.ja.md

  • Replaced inline Python code with a reference to the new code example.
  • Enhanced Japanese documentation by linking to the Python test file.
  • +3/-26   
    interactions.pt-br.md
    Update Portuguese documentation with Python code reference

    website_and_docs/content/documentation/webdriver/elements/interactions.pt-br.md

  • Replaced inline Python code with a reference to the new code example.
  • Improved Portuguese documentation by linking to the Python test file.
  • +3/-26   
    interactions.zh-cn.md
    Update Chinese documentation with Python code reference   

    website_and_docs/content/documentation/webdriver/elements/interactions.zh-cn.md

  • Replaced inline Python code with a reference to the new code example.
  • Enhanced Chinese documentation by linking to the Python test file.
  • +3/-26   

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

    Copy link

    netlify bot commented Nov 28, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 110618a

    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

    Assertion Logic
    The checkbox assertion logic appears incorrect - asserting False after clicking a checkbox may not be the expected behavior

    Resource Management
    The WebDriver instance should be managed using a context manager or try-finally block to ensure proper cleanup

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Fix incorrect assertion logic for checkbox state verification

    The assertion logic for the checkbox state is incorrect. After clicking a checkbox,
    its selected state should be True, not False.

    examples/python/tests/elements/test_interaction.py [16-20]

     check_input = driver.find_element(By.NAME, "checkbox_input")
     check_input.click()
     
     is_checked = check_input.is_selected()
    -assert is_checked == False
    +assert is_checked == True
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: The current assertion is logically incorrect as it expects the checkbox to be unselected after clicking it. This is a critical bug that would cause the test to fail incorrectly.

    10
    General
    Ensure proper cleanup of browser resources by using try-finally blocks for WebDriver management

    Add a try-finally block to ensure the WebDriver is properly closed even if the test
    fails. This prevents resource leaks and browser processes from hanging.

    examples/python/tests/elements/test_interaction.py [8-13]

     # Initialize WebDriver
     driver = webdriver.Chrome()
    -driver.implicitly_wait(0.5)
    +try:
    +    driver.implicitly_wait(0.5)
    +    
    +    # Navigate to URL
    +    driver.get("https://www.selenium.dev/selenium/web/inputs.html")
     
    -# Navigate to URL
    -driver.get("https://www.selenium.dev/selenium/web/inputs.html")
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a try-finally block is crucial for proper resource management, ensuring the browser is closed even if the test fails. This prevents memory leaks and orphaned browser processes.

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

    @harsha509 harsha509 merged commit 34cc4d9 into SeleniumHQ:trunk Nov 29, 2024
    9 checks passed
    @Delta456 Delta456 deleted the py_interactions branch November 29, 2024 19:06
    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