You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace print() statements with proper test assertions to verify the cookie was correctly set. This ensures the test actually validates the functionality.
def test_get_named_cookie():
driver = webdriver.Chrome()
- driver.get("http://www.example.com")+ try:+ driver.get("http://www.example.com")++ # Adds the cookie into current browser context+ driver.add_cookie({"name": "foo", "value": "bar"})++ # Get cookie details with named cookie 'foo'+ cookie = driver.get_cookie("foo")+ assert cookie is not None+ assert cookie["value"] == "bar"+ finally:+ driver.quit()- # Adds the cookie into current browser context- driver.add_cookie({"name": "foo", "value": "bar"})-- # Get cookie details with named cookie 'foo'- print(driver.get_cookie("foo"))-
Apply this suggestion
Suggestion importance[1-10]: 9
__
Why: Converting print statements to proper assertions transforms this from a demonstration into an actual test that validates functionality. The suggestion also adds resource cleanup, making this a comprehensive improvement that significantly enhances test quality and reliability.
High
Add resource cleanup
Add a teardown step to close the WebDriver after the test completes to prevent resource leaks. WebDriver instances should always be properly closed.
def test_add_cookie():
driver = webdriver.Chrome()
- driver.get("http://www.example.com")+ try:+ driver.get("http://www.example.com")++ # Adds the cookie into current browser context+ driver.add_cookie({"name": "key", "value": "value"})+ finally:+ driver.quit()- # Adds the cookie into current browser context- driver.add_cookie({"name": "key", "value": "value"})-
Apply this suggestion
Suggestion importance[1-10]: 8
__
Why: Adding proper resource cleanup with driver.quit() in a finally block is an important practice to prevent resource leaks and zombie browser processes. This is a significant improvement for test reliability and system resource management.
Medium
More
cgoldberg
changed the title
[py] Fix naming in cookie examples
Fix naming in Python cookie examples
Apr 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
This PR fixes the function names in
./examples/python/tests/interactions/test_cookies.pyso they are valid names that PyTest will discover (test_*).I didn't change anything else, so the line numbers in the documentation should still point to the correct place.
Motivation and Context
These examples were getting skipped in test runs (CI and local) because of this.
Types of changes
Checklist
PR Type
Enhancement
Description
Renamed cookie example functions to start with
test_Ensured PyTest discovers and runs all cookie tests
No logic or documentation changes, only function names updated
Changes walkthrough 📝
test_cookies.py
Rename cookie example functions for PyTest compatibilityexamples/python/tests/interactions/test_cookies.py
test_