Skip to content

Commit

Permalink
fix review, extract locator_converter
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Nov 11, 2024
1 parent b458679 commit da595d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions appium/webdriver/appium_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
def _get_new_headers(key: str, headers: Dict[str, str]) -> Dict[str, str]:
"""Return a new dictionary of heafers without the given key.
The key match is case-insensitive."""
key = key.lower()
return {k: v for k, v in headers.items() if k.lower() != key}
lower_key = key.lower()
return {k: v for k, v in headers.items() if k.lower() != lower_key}


class AppiumConnection(RemoteConnection):
Expand Down
29 changes: 29 additions & 0 deletions appium/webdriver/locator_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Tuple

from selenium.webdriver.remote.locator_converter import LocatorConverter


class AppiumLocatorConverter(LocatorConverter):
"""A custom locator converter in Appium.
Appium supports locators which are not defined in W3C WebDriver,
so Appium Python client wants to keep the given locators
to the Appium server as-is.
"""

def convert(self, by: str, value: str) -> Tuple[str, str]:
return (by, value)
13 changes: 1 addition & 12 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,12 @@
from .extensions.screen_record import ScreenRecord
from .extensions.session import Session
from .extensions.settings import Settings
from .locator_converter import AppiumLocatorConverter
from .mobilecommand import MobileCommand as Command
from .switch_to import MobileSwitchTo
from .webelement import WebElement as MobileWebElement


class AppiumLocatorConverter:
"""A custom locator converter in Appium.
Appium supports locators which are not defined in W3C WebDriver,
so Appium Python client wants to keep the given locators
to the Appium server as-is.
"""

def convert(self, by: str, value: str) -> Tuple[str, str]:
return (by, value)


class ExtensionBase:
"""
Used to define an extension command as driver's methods.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
],
install_requires=['selenium ~= 4.26'],
install_requires=['selenium ~= 4.26, < 5.0'],
)

0 comments on commit da595d6

Please sign in to comment.