Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added python tests for alert interactions #1688

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
diemol merged 4 commits into SeleniumHQ:trunk from Arpan3323:move_code_alerts_py
Apr 26, 2024

Conversation

@Arpan3323
Copy link
Contributor

@Arpan3323 Arpan3323 commented Apr 24, 2024
edited by qodo-merge-pro bot
Loading

User description

Description

added tests for Alert, Confirm, and Prompt popup

Motivation and Context

Missing tests in examples\python\tests\interactions\test_alerts.py

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.

Type

Tests


Description

  • Added three new test functions to test_alerts.py for handling different types of browser popups.
  • test_alert_popup checks the functionality of alert popups.
  • test_confirm_popup tests the confirm popup interactions.
  • test_prompt_popup verifies prompt popup interactions and input handling.

Changes walkthrough

Relevant files
Tests
test_alerts.py
Add Tests for Alert, Confirm, and Prompt Popups

examples/python/tests/interactions/test_alerts.py

  • Added a test function test_alert_popup to handle and verify alert
    popups.
  • Implemented test_confirm_popup to interact with and validate confirm
    popups.
  • Created test_prompt_popup to interact with and check prompt popups.
  • +48/-0

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

    Copy link

    netlify bot commented Apr 24, 2024
    edited
    Loading

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit d7b00a7

    Copy link

    CLAassistant commented Apr 24, 2024
    edited
    Loading

    CLA assistant check
    All committers have signed the CLA.

    Copy link
    Contributor

    PR Description updated to latest commit (e20cdc8)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the PR involves adding straightforward test cases for alert interactions in a Python script. The changes are localized to a single file and focus on testing basic functionalities, which makes the review process relatively quick and easy.

    🧪 Relevant tests

    Yes

    🔍 Possible issues

    Possible Bug: The tests might not clean up properly if an assertion fails, leading to browsers not being closed. Consider using a setup and teardown method or a context manager to ensure resources are always released.

    Hardcoded URL: The URL for the test is hardcoded, which could make the tests less flexible and harder to run in different environments. Consider parameterizing the URL.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    PR Code Suggestions

    CategorySuggestions
    Maintainability
    Refactor repeated code into a helper function for initializing the driver and navigating to the URL.

    To avoid code duplication and improve maintainability, create a helper function to
    initialize the webdriver.Chrome() and navigate to the URL. This function can be reused in
    all test functions.

    examples/python/tests/interactions/test_alerts.py [10-11]

    -driver = webdriver.Chrome()
    -driver.get(url)
    +driver = setup_driver_and_navigate(url)
     
    Use a constant for timeout values to facilitate easier adjustments and maintainability.

    Instead of hardcoding the timeout value in each WebDriverWait, define a constant at the
    beginning of your test module. This makes it easier to adjust timeouts globally for all
    tests.

    examples/python/tests/interactions/test_alerts.py [15]

    -wait = WebDriverWait(driver, timeout=2)
    +TIMEOUT = 2
    +wait = WebDriverWait(driver, timeout=TIMEOUT)
     
    Best practice
    Manage the WebDriver's lifecycle with a context manager to ensure proper resource handling.

    Use a context manager to handle the driver's lifecycle to ensure that the driver is
    properly closed even if an error occurs during the test execution.

    examples/python/tests/interactions/test_alerts.py [10-21]

    -driver = webdriver.Chrome()
    -driver.get(url)
    -# test steps...
    -driver.quit()
    +with webdriver.Chrome() as driver:
    + driver.get(url)
    + # test steps...
     
    Use standard click methods to better simulate real user interactions.

    Avoid using execute_script for clicks when possible, as it bypasses user interaction
    models and can lead to issues not caught by tests simulating real user interactions.

    examples/python/tests/interactions/test_alerts.py [26-27]

     element = driver.find_element(By.LINK_TEXT, "See a sample confirm")
    -driver.execute_script("arguments[0].click();", element)
    +element.click()
     
    Reliability
    Improve element interaction reliability by ensuring elements are visible before interacting.

    Replace direct interaction methods with safer alternatives that check for element presence
    and visibility, reducing the risk of ElementNotVisibleException.

    examples/python/tests/interactions/test_alerts.py [12-13]

    -element = driver.find_element(By.LINK_TEXT, "See an example alert")
    +element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "See an example alert")))
     element.click()
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor Author

    @diemol I would greatly appreciate it if you could let me know whether I need to make any additional changes to my pull request so it is acceptable for merging. I have not yet updated the relevant markdown files associated with these tests as I wanted to do it after the tests have been added so I can verify if markdown references to the added tests work correctly. Thanks

    Copy link
    Member

    @diemol diemol 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, @Arpan3323!

    Arpan3323 reacted with thumbs up emoji
    @diemol diemol merged commit 821c428 into SeleniumHQ:trunk Apr 26, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Reviewers

    @diemol diemol diemol approved these changes

    Assignees

    No one assigned

    Projects

    None yet

    Milestone

    No milestone

    Development

    Successfully merging this pull request may close these issues.

    AltStyle によって変換されたページ (->オリジナル) /