Repository navigation
Conversation
`WebDriver.__init__` installed each extension method with `setattr(WebDriver, ...)`, so the method lived on the class and was bound to the extension instance of the most recently created driver: - with two drivers created with the same extension, calling the method on the first driver sent the request to the second driver's session; - a driver created without extensions still had the method; - `delete_extensions()` removed the method for every driver, and permanently removed any built-in method that an extension overrode (for example `get_status`). Set the extension methods on the driver instance instead, and make `delete_extensions()` remove only the attributes this driver set, so the class methods stay untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
WebDriver.__init__installs each extension method withsetattr(WebDriver, ...). The method lives on the class and is bound to the most recently created driver:An extension can also override a built-in method, such as
get_status. Then every driver uses the override, anddelete_extensions()deletesWebDriver.get_statusitself. After that,driver.get_status()raisesAttributeErroron every driver until the process restarts.Fix
setattr(self, ...)), not on the class.delete_extensions()removes only the attributes this driver set (those inself.__dict__), so methods defined on the class stay untouched.ExtensionBasedocstring comment, which said the commands "remain in the module".Behaviour change: a driver created without an extension no longer gets that extension's methods from another driver. Code that relied on this has to pass
extensions=to each driver that needs them. An extension can also no longer replace a driver property, such ascontextsororientation. Creating the driver then raisesAttributeError, because properties can't be overridden on an instance.Tests
test_add_command_per_driver: two drivers with the same extension each call their own session. A third driver without extensions doesn't have the method. Afterdelete_extensions()on the first driver, the second one still works. Without the fix,driver_a.test_command()returns'session-b'.test_delete_extensions_keeps_overridden_method: an extension overridesget_statuson one driver only. Afterdelete_extensions(), both drivers use the built-inget_statusagain. Without the fix, the other driver gets'custom status'instead of the server status.delete_extensions()calls still remove the method from that driver.ruff check,ruff format --check,mypy appiumand the full unit test suite pass.🤖 Generated with Claude Code