Skip to content
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

refactor: optimised options by moving all getters and setters to custom descriptors #882

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4b38580
optimized options
sandeepsuryaprasad Jun 21, 2023
08ca706
more files optimized
sandeepsuryaprasad Jun 21, 2023
1c09f67
added docstrings and typehints
sandeepsuryaprasad Jun 23, 2023
562b3be
added docstrings and typehints to more options
sandeepsuryaprasad Jun 23, 2023
1aff112
fixed review comments
sandeepsuryaprasad Jun 24, 2023
30e9355
fixed typo
sandeepsuryaprasad Jun 24, 2023
76419d5
added Generic type for descriptor classes and removed redundant getat…
sandeepsuryaprasad Jun 26, 2023
4d7e75b
added docstrings and incorporated review comments
sandeepsuryaprasad Jun 30, 2023
2ff177e
modified descriptor to accept transformation functions
sandeepsuryaprasad Jul 1, 2023
7f9ab58
incorporated all review comments
sandeepsuryaprasad Jul 1, 2023
ba6afdd
incorporated review comments
sandeepsuryaprasad Jul 2, 2023
719e23a
removed un-used imports
sandeepsuryaprasad Jul 2, 2023
8979a12
added type hints for all optionsDescriptors
sandeepsuryaprasad Jul 2, 2023
5537eaa
applied isort and black formatting
sandeepsuryaprasad Jul 3, 2023
6d49c51
fixed all review comments
sandeepsuryaprasad Jul 3, 2023
d73688d
fixed review comments
sandeepsuryaprasad Jul 3, 2023
8390d46
moved all uianimator2 options to uianimator2_options.py
sandeepsuryaprasad Jul 3, 2023
a92fc4f
fixed imports in uianimator2/base.py
sandeepsuryaprasad Jul 3, 2023
664c9f2
fixed isort formatting issue
sandeepsuryaprasad Jul 3, 2023
d87a0c4
moved all espresso options to espresso_options.py
sandeepsuryaprasad Jul 3, 2023
aac90f4
moved all xcuitest/general options to general_options.py
sandeepsuryaprasad Jul 3, 2023
56ac68e
moved locale_script_options to descriptor
sandeepsuryaprasad Jul 4, 2023
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
43 changes: 0 additions & 43 deletions appium/options/android/common/adb/adb_exec_timeout_option.py

This file was deleted.

227 changes: 227 additions & 0 deletions appium/options/android/common/adb/adb_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you 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 datetime import timedelta
from typing import Any, TypeVar

from appium.options.common.supports_capabilities import SupportsCapabilities

C = TypeVar("C", bound="SupportsCapabilities")


class AdbOptionsDescriptor:
def __init__(self, name: str) -> None:
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
self.name = name

def __get__(self, obj: C, cls: type[C]) -> Any:
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
if self.name == 'ADB_EXEC_TIMEOUT':
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
value = getattr(obj, 'get_capability')(self.name)
return None if value is None else timedelta(milliseconds=value)
return getattr(obj, 'get_capability')(self.name)
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved

def __set__(self, obj:C, value: C) -> C:
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
if self.name == 'ADB_EXEC_TIMEOUT':
return getattr(obj, 'set_capability')(self.name, int(value.total_seconds() * 1000) if isinstance(value, timedelta) else value)
return getattr(obj, 'set_capability')(self.name, value)


class AdbExecTimeoutOption(SupportsCapabilities):
ADB_EXEC_TIMEOUT = 'adbExecTimeout'
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
adb_exec_timeout = AdbOptionsDescriptor("ADB_EXEC_TIMEOUT")
"""
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
Gets and Sets Maximum time to wait until single ADB command is executed.
20000 ms by default.

Usage
-----
- `self.adb_exec_timeout`
- `self.adb_exec_timeout` = `value`
"""


class AdbPortOption(SupportsCapabilities):
ADB_PORT = 'adbPort'
adb_port = AdbOptionsDescriptor("ADB_PORT")
"""
Set number of the port where ADB is running. 5037 by default

Usage
-----
- `self.adb_port`
- `self.adb_port` = `value`
"""


class AllowDelayAdbOption(SupportsCapabilities):
ALLOW_DELAY_ADB = 'allowDelayAdb'
allow_delay_adb = AdbOptionsDescriptor("ALLOW_DELAY_ADB")
"""
Gets and Sets whether to prevent the emulator to use -delay-adb feature.
Being set to false prevents emulator to use -delay-adb feature to detect its startup.
See https://github.com/appium/appium/issues/14773 for more details.

Usage
----
- `self.allow_delay_adb`
- `self.allow_delay_adb` = `value`
"""


class BuildToolsVersionOption(SupportsCapabilities):
BUILD_TOOLS_VERSION = 'buildToolsVersion'
build_tools_version = AdbOptionsDescriptor("BUILD_TOOLS_VERSION")
"""
Gets and Sets Version of Android build tools to use.
The version of Android build tools to use. By default, UiAutomator2
driver uses the most recent version of build tools installed on
the machine, but sometimes it might be necessary to give it a hint
(let say if there is a known bug in the most recent tools version).
Example: 28.0.3

Usage
-----
- `self.build_tools_version`
- `self.build_tools_version` = `value`
"""


class ClearDeviceLogsOnStartOption(SupportsCapabilities):
CLEAR_DEVICE_LOGS_ON_START = 'clearDeviceLogsOnStart'
clear_device_logs_on_start = AdbOptionsDescriptor("CLEAR_DEVICE_LOGS_ON_START")
""""
Gets and Sets if the driver to delete all the existing logs in the
device buffer before starting a new test.
If set to true then the driver deletes all the existing logs in the
device buffer before starting a new test.

Usage
----
- `self.clear_device_logs_on_start`
- `self.clear_device_logs_on_start` = `value`
"""


class IgnoreHiddenApiPolicyErrorOption(SupportsCapabilities):
IGNORE_HIDDEN_API_POLICY_ERROR = 'ignoreHiddenApiPolicyError'
ignore_hidden_api_policy_error = AdbOptionsDescriptor("IGNORE_HIDDEN_API_POLICY_ERROR")
"""
Gets and Sets Whether to ignore a failure while changing hidden API access policies.
Being set to true ignores a failure while changing hidden API access policies.
Could be useful on some devices, where access to these policies has been locked by its vendor.
false by default.

Usage
-----
- `self.ignore_hidden_api_ploicy_error`
- `self.ignore_hidden_api_ploicy_error` = `value`
"""


class LogcatFilterSpecsOption(SupportsCapabilities):
LOGCAT_FILTER_SPECS = 'logcatFilterSpecs'
logcat_filter_specs = AdbOptionsDescriptor("LOGCAT_FILTER_SPECS")
"""
Gets and Sets Logcat filter format.
Series of tag[:priority] where tag is a log component tag (or * for all)
and priority is: V Verbose, D Debug, I Info, W Warn, E Error, F Fatal,
S Silent (supress all output). '' means ':d' and tag by itself means tag:v.
If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
If no filterspec is found, filter defaults to '*:I'.

Usage
-----
- `self.logcat_filter_specs`
- `self.logcat_filter_specs` = `value`
"""


class LogcatFormatOption(SupportsCapabilities):
LOGCAT_FORMAT = 'logcatFormat'
logcat_format = AdbOptionsDescriptor("LOGCAT_FORMAT")
"""
Gets and Sets Log print format.
The log print format, where format is one of: brief process tag thread raw time
threadtime long. threadtime is the default value.

Usage
----
- `self.logcat_format`
- `self.logcat_format` = `value`
"""


class MockLocationAppOption(SupportsCapabilities):
MOCK_LOCATION_APP = 'mockLocationApp'
mock_location_app = AdbOptionsDescriptor("MOCK_LOCATION_APP")
"""
Gets and Sets Identifier of the app, which is used as a system mock location provider.

This capability has no effect on emulators.
If the value is set to null or an empty string, then Appium will skip the mocked
location provider setup procedure. Defaults to Appium Setting package
identifier (io.appium.settings).

Usage
----
- `self.mock_location_app`
- `self.mock_location_app` = `value`
"""


class RemoteAdbHostOption(SupportsCapabilities):
REMOTE_ADB_HOST = 'remoteAdbHost'
remote_adb_host = AdbOptionsDescriptor("REMOTE_ADB_HOST")
"""
Gets and Sets Address of the host where ADB is running.
(the value of -H ADB command line option).Localhost by default.

Usage
----
- `self.remote_adb_host`
- `self.remote_adb_host` = `value`
"""


class SkipLogcatCaptureOption(SupportsCapabilities):
SKIP_LOGCAT_CAPTURE = 'skipLogcatCapture'
skip_logcat_capture = AdbOptionsDescriptor("SKIP_LOGCAT_CAPTURE")
"""
Whether to delete all the existing logs in the
device buffer before starting a new test.
Being set to true disables automatic logcat output collection during the test run.
false by default

Usage
-----
- `self.skip_logcat_capture`
- `self.skip_logcat_capture` = `value`
"""


class SuppressKillServerOption(SupportsCapabilities):
SUPPRESS_KILL_SERVER = 'suppressKillServer'
suppress_kill_server = AdbOptionsDescriptor("SUPPRESS_KILL_SERVER")
"""
Prevents the driver from ever killing the ADB server explicitly.
Being set to true prevents the driver from ever killing the ADB server explicitly.
Could be useful if ADB is connected wirelessly. false by default.

Usage
-----
- `self.suppress_kill_server`
- `self.suppress_kill_server` = `value`
"""
38 changes: 0 additions & 38 deletions appium/options/android/common/adb/adb_port_option.py

This file was deleted.

39 changes: 0 additions & 39 deletions appium/options/android/common/adb/allow_delay_adb_option.py

This file was deleted.

42 changes: 0 additions & 42 deletions appium/options/android/common/adb/build_tools_version_option.py

This file was deleted.

Loading