Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appium/saucetestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import sys
import unittest
from typing import Any, Callable, List
from typing import Callable, List

from sauceclient import SauceClient

Expand Down
10 changes: 4 additions & 6 deletions appium/webdriver/appium_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def poll_url(host: str, port: int, path: str, timeout_ms: int) -> bool:
while time.time() < time_started_sec + timeout_ms / 1000.0:
try:
conn = urllib3.PoolManager(timeout=1.0)
resp = conn.request('HEAD', 'http://{host}:{port}{path}'.format(
host=host, port=port, path=path))
resp = conn.request('HEAD', f'http://{host}:{port}{path}')
if resp.status < 400:
return True
except Exception:
Expand All @@ -67,7 +66,7 @@ class AppiumServiceError(RuntimeError):
T = TypeVar('T', bound='AppiumService')


class AppiumService(object):
class AppiumService:
def __init__(self) -> None:
self._process: Optional[sp.Popen] = None
self._cmd: Optional[List] = None
Expand Down Expand Up @@ -169,13 +168,12 @@ def start(self, **kwargs: Any) -> sp.Popen:
port = self._parse_port(args)
error_msg: Optional[str] = None
if not self.is_running or (timeout_ms > 0 and not poll_url(host, port, STATUS_URL, timeout_ms)):
error_msg = 'Appium has failed to start on {}:{} within {}ms timeout'\
.format(host, port, timeout_ms)
error_msg = f'Appium has failed to start on {host}:{port} within {timeout_ms}ms timeout'
if error_msg is not None:
if stderr == sp.PIPE:
err_output = self._process.stderr.read()
if err_output:
error_msg += '\nOriginal error: {}'.format(str(err_output))
error_msg += f'\nOriginal error: {str(err_output)}'
self.stop()
raise AppiumServiceError(error_msg)
return self._process
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/applicationstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


class ApplicationState(object):
class ApplicationState:
NOT_INSTALLED = 0
NOT_RUNNING = 1
RUNNING_IN_BACKGROUND_SUSPENDED = 2
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/clipboard_content_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


class ClipboardContentType(object):
class ClipboardContentType:
PLAINTEXT = 'plaintext'
IMAGE = 'image'
URL = 'url'
2 changes: 1 addition & 1 deletion appium/webdriver/common/multi_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
T = TypeVar('T', bound='MultiAction')


class MultiAction(object):
class MultiAction:
def __init__(self, driver: 'WebDriver', element: Optional['WebElement'] = None) -> None:
self._driver = driver
self._element = element
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/common/touch_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
T = TypeVar('T', bound='TouchAction')


class TouchAction(object):
class TouchAction:

def __init__(self, driver: Optional['WebDriver'] = None):
self._driver = driver
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/connectiontype.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""


class ConnectionType(object):
class ConnectionType:
Copy link
Collaborator Author

@ki4070ma ki4070ma Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Notes]
Couldn't use enum such like here since ConnectionType(Enum) will be different type from below return value.

return self.execute(Command.SET_NETWORK_CONNECTION, data)['value']

Need to change to such like return CoonectionType(self.execute(Command.SET_NETWORK_CONNECTION, data)['value']), but this breaks backward compatibility.

NO_CONNECTION = 0
AIRPLANE_MODE = 1
WIFI_ONLY = 2
Expand Down
2 changes: 0 additions & 2 deletions appium/webdriver/extensions/android/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TypeVar

from selenium import webdriver

from appium.webdriver.mobilecommand import MobileCommand as Command
Expand Down
18 changes: 9 additions & 9 deletions appium/webdriver/extensions/android/gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
from appium.webdriver.mobilecommand import MobileCommand as Command


class GsmCallActions(object):
class GsmCallActions:
CALL = 'call'
ACCEPT = 'accept'
CANCEL = 'cancel'
HOLD = 'hold'


class GsmSignalStrength(object):
class GsmSignalStrength:
NONE_OR_UNKNOWN = 0
POOR = 1
MODERATE = 2
GOOD = 3
GREAT = 4


class GsmVoiceState(object):
class GsmVoiceState:
UNREGISTERED = 'unregistered'
HOME = 'home'
ROAMING = 'roaming'
Expand Down Expand Up @@ -66,8 +66,8 @@ def make_gsm_call(self, phone_number: str, action: str) -> T:
"""
constants = extract_const_attributes(GsmCallActions)
if action not in constants.values():
logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.CALL)'.format(
action, list(constants.keys()), GsmCallActions.__name__))
logger.warning(
f'{action} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmCallActions.__name__}.CALL)')
self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action})
return self

Expand All @@ -85,8 +85,8 @@ def set_gsm_signal(self, strength: int) -> T:
"""
constants = extract_const_attributes(GsmSignalStrength)
if strength not in constants.values():
logger.warning('{} is out of range. Consider using one of {} constants. (e.g. {}.GOOD)'.format(
strength, list(constants.keys()), GsmSignalStrength.__name__))
logger.warning(
f'{strength} is out of range. Consider using one of {list(constants.keys())} constants. (e.g. {GsmSignalStrength.__name__}.GOOD)')
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
return self

Expand All @@ -104,8 +104,8 @@ def set_gsm_voice(self, state: str) -> T:
"""
constants = extract_const_attributes(GsmVoiceState)
if state not in constants.values():
logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.HOME)'.format(
state, list(constants.keys()), GsmVoiceState.__name__))
logger.warning(
f'{state} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmVoiceState.__name__}.HOME)')
self.execute(Command.SET_GSM_VOICE, {'state': state})
return self

Expand Down
8 changes: 4 additions & 4 deletions appium/webdriver/extensions/android/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, TypeVar
from typing import TypeVar

from selenium import webdriver

Expand All @@ -23,7 +23,7 @@
T = TypeVar('T', bound='Network')


class NetSpeed(object):
class NetSpeed:
GSM = 'gsm' # GSM/CSD (up: 14.4(kbps), down: 14.4(kbps))
SCSD = 'scsd' # HSCSD (up: 14.4, down: 57.6)
GPRS = 'gprs' # GPRS (up: 28.8, down: 57.6)
Expand Down Expand Up @@ -98,8 +98,8 @@ def set_network_speed(self, speed_type: str) -> T:
"""
constants = extract_const_attributes(NetSpeed)
if speed_type not in constants.values():
logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.LTE)'.format(
speed_type, list(constants.keys()), NetSpeed.__name__))
logger.warning(
f'{speed_type} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {NetSpeed.__name__}.LTE)')

self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type})
return self
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/extensions/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import base64
from typing import Any, Dict, Optional, TypeVar
from typing import Optional, TypeVar

from selenium import webdriver

Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/extensions/execute_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def execute_driver(self, script: str, script_type: str = 'webdriverio', timeout_
WebDriverException: If something error happenes in the script. The message has the original error message.
"""

class Result(object):
class Result:

def __init__(self, response: Dict):
self.result = response['result']
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/extensions/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Optional, TypeVar, Union
from typing import Dict, TypeVar, Union

from selenium import webdriver

Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/extensions/remote_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def push_file(self, destination_path: str,
with open(source_path, 'rb') as f:
file_data = f.read()
except IOError:
message = 'source_path {} could not be found. Are you sure the file exists?'.format(source_path)
message = f'source_path "{source_path}" could not be found. Are you sure the file exists?'
raise InvalidArgumentException(message)
base64data = base64.b64encode(file_data).decode('utf-8')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

# pylint: disable=abstract-method

from typing import TYPE_CHECKING, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Dict, List, Union

if TYPE_CHECKING:
from appium.webdriver.webelement import WebElement


class BaseSearchContext(object):
class BaseSearchContext:
"""Used by each search context. Dummy find_element/s are for preventing pylint error"""

def find_element(self, by: str, value: Union[str, Dict] = None) -> 'WebElement':
Expand Down
2 changes: 1 addition & 1 deletion appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


class MobileCommand(object):
class MobileCommand:
# Common
GET_SESSION = 'getSession'
GET_ALL_SESSIONS = 'getAllSessions'
Expand Down
7 changes: 1 addition & 6 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ def _update_command_executor(self, keep_alive: bool) -> None:
hostname = self.capabilities[direct_host]
port = self.capabilities[direct_port]
path = self.capabilities[direct_path]
executor = '{scheme}://{hostname}:{port}{path}'.format(
scheme=protocol,
hostname=hostname,
port=port,
path=path
)
executor = f'{protocol}://{hostname}:{port}{path}'

logger.info('Updated request endpoint to %s', executor)
# Override command executor
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_open_notifications(self):
self.skipTest('Need to fix flaky test during running on CI.')
for word in ['App', 'Notification', 'Status Bar', ':-|']:
wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR,
'new UiSelector().text("{}")'.format(word)).click()
f'new UiSelector().text("{word}")').click()

self.driver.open_notifications()
sleep(1)
Expand Down
1 change: 0 additions & 1 deletion test/functional/android/ime_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_active_ime_engine(self):

def test_activate_ime_engine(self):
engines = self.driver.available_ime_engines
active_engine = self.driver.active_ime_engine

self.driver.activate_ime_engine(engines[-1])
self.assertEqual(self.driver.active_ime_engine, engines[-1])
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/log_event_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_log_event(self):
vendor = 'appium'
event = 'funEvent'
self.driver.log_event(vendor, event)
assert '{}:{}'.format(vendor, event) in self.driver.get_events().keys()
assert f'{vendor}:{event}' in self.driver.get_events().keys()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/webelement_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_set_text(self):
def test_send_keys(self):
for text in ['App', 'Activity', 'Custom Title']:
wait_for_element(self.driver, MobileBy.XPATH,
"//android.widget.TextView[@text='{}']".format(text)).click()
f"//android.widget.TextView[@text='{text}']").click()

el = wait_for_element(self.driver, MobileBy.ID, '{}:id/left_text_edit'.format(APIDEMO_PKG_NAME))
el.send_keys(' text')
Expand Down
4 changes: 2 additions & 2 deletions test/functional/ios/helper/desired_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_desired_capabilities(app=None):
return desired_caps


class PytestXdistWorker(object):
class PytestXdistWorker:
NUMBER = os.getenv('PYTEST_XDIST_WORKER')
COUNT = os.getenv('PYTEST_XDIST_WORKER_COUNT') # Return 2 if `-n 2` is passed

Expand All @@ -53,7 +53,7 @@ def gw(number):
if number >= PytestXdistWorker.COUNT:
return 'gw0'

return 'gw{}'.format(number)
return f'gw{number}'

# If you run tests with pytest-xdist, you can run tests in parallel.

Expand Down
2 changes: 1 addition & 1 deletion test/functional/ios/webdriver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_all_sessions(self):
desired_caps['deviceName'] = 'iPhone Xs Max'
desired_caps['wdaLocalPort'] = port

class session_counts_is_two(object):
class session_counts_is_two:
TIMEOUT = 10

def __call__(self, driver):
Expand Down
3 changes: 1 addition & 2 deletions test/functional/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def get_available_from_port_range(from_port, to_port):
finally:
sock.close()

raise NoAvailablePortError('No available port between {} and {}'.format(
from_port, to_port))
raise NoAvailablePortError(f'No available port between {from_port} and {to_port}')


def is_ci():
Expand Down
2 changes: 1 addition & 1 deletion test/unit/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def appium_command(command):
Returns:
str: A string of command URL
"""
return '{}{}'.format(SERVER_URL_BASE, command)
return f'{SERVER_URL_BASE}{command}'


def android_w3c_driver():
Expand Down