From feeecd2be928c5d18b276dbdf2f322a2109a17ba Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 21 Jun 2022 08:32:04 +0200 Subject: [PATCH 1/5] refactor: Make system_port and system_host options common --- .../mac2 => common}/system_host_option.py | 4 -- .../mac2 => common}/system_port_option.py | 1 - appium/options/mac/mac2/base.py | 45 ++++++++++++++++++- appium/options/windows/windows/base.py | 12 ++++- .../windows/windows/system_port_option.py | 41 ----------------- 5 files changed, 54 insertions(+), 49 deletions(-) rename appium/options/{mac/mac2 => common}/system_host_option.py (83%) rename appium/options/{mac/mac2 => common}/system_port_option.py (94%) delete mode 100644 appium/options/windows/windows/system_port_option.py diff --git a/appium/options/mac/mac2/system_host_option.py b/appium/options/common/system_host_option.py similarity index 83% rename from appium/options/mac/mac2/system_host_option.py rename to appium/options/common/system_host_option.py index 78e7ff4d9..0544de5ca 100644 --- a/appium/options/mac/mac2/system_host_option.py +++ b/appium/options/common/system_host_option.py @@ -34,9 +34,5 @@ def system_host(self) -> Optional[str]: def system_host(self, value: str) -> None: """ Set the name of the host for the internal server to listen on. - If not provided then Mac2Driver will use the default host - address 127.0.0.1. You could set it to 0.0.0.0 to make the - server listening on all available network interfaces. - It is also possible to set the particular interface name, for example en1. """ self.set_capability(SYSTEM_HOST, value) diff --git a/appium/options/mac/mac2/system_port_option.py b/appium/options/common/system_port_option.py similarity index 94% rename from appium/options/mac/mac2/system_port_option.py rename to appium/options/common/system_port_option.py index 805856bff..e11f3b59d 100644 --- a/appium/options/mac/mac2/system_port_option.py +++ b/appium/options/common/system_port_option.py @@ -34,6 +34,5 @@ def system_port(self) -> Optional[int]: def system_port(self, value: int) -> None: """ Set the number of the port for the internal server to listen on. - If not provided then Mac2Driver will use the default port 10100. """ self.set_capability(SYSTEM_PORT, value) diff --git a/appium/options/mac/mac2/base.py b/appium/options/mac/mac2/base.py index 84641449a..74b57c423 100644 --- a/appium/options/mac/mac2/base.py +++ b/appium/options/mac/mac2/base.py @@ -21,6 +21,8 @@ from appium.options.common.base import PLATFORM_NAME, AppiumOptions from appium.options.common.postrun_option import PostrunOption from appium.options.common.prerun_option import PrerunOption +from appium.options.common.system_host_option import SystemHostOption +from appium.options.common.system_port_option import SystemPortOption from .arguments_option import ArgumentsOption from .bootstrap_root_option import BootstrapRootOption @@ -29,8 +31,6 @@ from .server_startup_timeout_option import ServerStartupTimeoutOption from .show_server_logs_option import ShowServerLogsOption from .skip_app_kill_option import SkipAppKillOption -from .system_host_option import SystemHostOption -from .system_port_option import SystemPortOption from .web_driver_agent_mac_url_option import WebDriverAgentMacUrlOption @@ -49,6 +49,47 @@ class Mac2Options( SystemPortOption, WebDriverAgentMacUrlOption, ): + @PrerunOption.prerun.setter # type: ignore + def prerun(self, value: Dict[str, str]) -> None: + """ + A mapping containing either 'script' or 'command' key. The value of + each key must be a valid AppleScript script or command to be + executed after before Mac2Driver session is started. See + https://github.com/appium/appium-mac2-driver#applescript-commands-execution + for more details. + """ + PrerunOption.prerun.fset(self, value) # type: ignore + + @PostrunOption.postrun.setter # type: ignore + def postrun(self, value: Dict[str, str]) -> None: + """ + A mapping containing either script or command key. The value of + each key must be a valid AppleScript script or command to be + executed after Mac2Driver session is stopped. See + https://github.com/appium/appium-mac2-driver#applescript-commands-execution + for more details. + """ + PostrunOption.postrun.fset(self, value) # type: ignore + + @SystemPortOption.system_port.setter + def system_port(self, value: int) -> None: + """ + Set the number of the port for the internal server to listen on. + If not provided then Mac2Driver will use the default port 10100. + """ + SystemPortOption.system_port.fset(self, value) + + @SystemHostOption.system_host.setter + def system_host(self, value: str) -> None: + """ + Set the number of the port for the internal server to listen on. + If not provided then Mac2Driver will use the default host + address 127.0.0.1. You could set it to 0.0.0.0 to make the + server listening on all available network interfaces. + It is also possible to set the particular interface name, for example en1. + """ + SystemHostOption.system_host.fset(self, value) + @property def default_capabilities(self) -> Dict: return { diff --git a/appium/options/windows/windows/base.py b/appium/options/windows/windows/base.py index f0f6ee3a4..21cf43f28 100644 --- a/appium/options/windows/windows/base.py +++ b/appium/options/windows/windows/base.py @@ -22,12 +22,12 @@ from appium.options.common.base import PLATFORM_NAME, AppiumOptions from appium.options.common.postrun_option import PostrunOption from appium.options.common.prerun_option import PrerunOption +from appium.options.common.system_port_option import SystemPortOption from .app_top_level_window_option import AppTopLevelWindowOption from .app_working_dir_option import AppWorkingDirOption from .create_session_timeout_option import CreateSessionTimeoutOption from .expreimental_web_driver_option import ExperimentalWebDriverOption -from .system_port_option import SystemPortOption from .wait_for_app_launch_option import WaitForAppLaunchOption @@ -77,6 +77,16 @@ def postrun(self, value: Dict[str, str]) -> None: """ PostrunOption.postrun.fset(self, value) # type: ignore + @SystemPortOption.system_port.setter # type: ignore + def system_port(self, value: int) -> None: + """ + The port number to execute Appium Windows Driver server listener on, + for example 5556. The port must not be occupied. The default starting port + number for a new Appium Windows Driver session is 4724. If this port is + already busy then the next free port will be automatically selected. + """ + SystemPortOption.system_port.fset(self, value) # type: ignore + @property def default_capabilities(self) -> Dict: return { diff --git a/appium/options/windows/windows/system_port_option.py b/appium/options/windows/windows/system_port_option.py deleted file mode 100644 index 30ac556af..000000000 --- a/appium/options/windows/windows/system_port_option.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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 typing import Optional - -from appium.options.common.supports_capabilities import SupportsCapabilities - -SYSTEM_PORT = 'systemPort' - - -class SystemPortOption(SupportsCapabilities): - @property - def system_port(self) -> Optional[int]: - """ - Port number to execute Appium Windows Driver server listener on. - """ - return self.get_capability(SYSTEM_PORT) - - @system_port.setter - def system_port(self, value: int) -> None: - """ - The port number to execute Appium Windows Driver server listener on, - for example 5556. The port must not be occupied. The default starting port - number for a new Appium Windows Driver session is 4724. If this port is - already busy then the next free port will be automatically selected. - """ - self.set_capability(SYSTEM_PORT, value) From b147e697194932407bded7a057e38243bcc006ef Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 21 Jun 2022 08:34:06 +0200 Subject: [PATCH 2/5] Add quotes --- appium/options/mac/mac2/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appium/options/mac/mac2/base.py b/appium/options/mac/mac2/base.py index 74b57c423..fbfa7beae 100644 --- a/appium/options/mac/mac2/base.py +++ b/appium/options/mac/mac2/base.py @@ -63,7 +63,7 @@ def prerun(self, value: Dict[str, str]) -> None: @PostrunOption.postrun.setter # type: ignore def postrun(self, value: Dict[str, str]) -> None: """ - A mapping containing either script or command key. The value of + A mapping containing either 'script' or 'command' key. The value of each key must be a valid AppleScript script or command to be executed after Mac2Driver session is stopped. See https://github.com/appium/appium-mac2-driver#applescript-commands-execution From 13d0f604dff3beb701e805dc3d614519eebbc688 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 21 Jun 2022 19:54:01 +0200 Subject: [PATCH 3/5] Rerun tests --- ci-jobs/functional/setup_appium.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci-jobs/functional/setup_appium.yml b/ci-jobs/functional/setup_appium.yml index 6a220ef5a..05931e40b 100644 --- a/ci-jobs/functional/setup_appium.yml +++ b/ci-jobs/functional/setup_appium.yml @@ -24,4 +24,5 @@ steps: ffmpeg -version appium --version node --version + npm --version displayName: Check versions From 6b700af7e340f4e25f6ff14e3c30a67522492f9f Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 21 Jun 2022 20:00:26 +0200 Subject: [PATCH 4/5] Update server startup --- ci-jobs/functional/run_android_test.yml | 6 ++---- ci-jobs/functional/run_ios_test.yml | 6 ++---- ci-jobs/scripts/start_server.sh | 12 ++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 ci-jobs/scripts/start_server.sh diff --git a/ci-jobs/functional/run_android_test.yml b/ci-jobs/functional/run_android_test.yml index 7fa99a198..08b70a653 100644 --- a/ci-jobs/functional/run_android_test.yml +++ b/ci-jobs/functional/run_android_test.yml @@ -13,10 +13,8 @@ jobs: - script: bash ci-jobs/functional/start-emulator.sh displayName: Create and run Emulator - script: | - if [[ '${{ parameters.dontRunAppium }}' != true ]]; then - appium --relaxed-security > appium_log.txt 2>&1 & - sleep 2 - fi + bash ci-jobs/scripts/start_server.sh + pushd "$(pwd)" cd test/functional/android python -m pytest ${{ parameters.testFiles}} ${{ parameters.pytestOpt }} diff --git a/ci-jobs/functional/run_ios_test.yml b/ci-jobs/functional/run_ios_test.yml index 122dca1d8..79f046444 100644 --- a/ci-jobs/functional/run_ios_test.yml +++ b/ci-jobs/functional/run_ios_test.yml @@ -12,10 +12,8 @@ jobs: - script: appium driver install xcuitest displayName: Install XCUITest driver - script: | - if [[ '${{ parameters.dontRunAppium }}' != true ]]; then - appium --relaxed-security > appium_log.txt 2>&1 & - sleep 2 - fi + bash ci-jobs/scripts/start_server.sh + pushd "$(pwd)" cd test/functional/ios python -m pytest ${{ parameters.testFiles}} ${{ parameters.pytestOpt }} diff --git a/ci-jobs/scripts/start_server.sh b/ci-jobs/scripts/start_server.sh new file mode 100644 index 000000000..f1b8918af --- /dev/null +++ b/ci-jobs/scripts/start_server.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +appium server --relaxed-security > appium_log.txt 2>&1 & +secondsStarted=$(date +%s) +while ! nc -z 127.0.0.1 4723; do + sleep 0.1 + secondsElapsed=$(( $(date +%s) - secondsStarted )) + if [[ $secondsElapsed -gt 30 ]]; then + echo "Appium server was unable to start within 30 seconds timeout" + exit 1 + fi +done From d435f62b16f028948df53abdd18ebfe46fd14060 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 21 Jun 2022 21:10:30 +0200 Subject: [PATCH 5/5] tune mypy --- appium/options/mac/mac2/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appium/options/mac/mac2/base.py b/appium/options/mac/mac2/base.py index fbfa7beae..3b44aa91b 100644 --- a/appium/options/mac/mac2/base.py +++ b/appium/options/mac/mac2/base.py @@ -71,15 +71,15 @@ def postrun(self, value: Dict[str, str]) -> None: """ PostrunOption.postrun.fset(self, value) # type: ignore - @SystemPortOption.system_port.setter + @SystemPortOption.system_port.setter # type: ignore def system_port(self, value: int) -> None: """ Set the number of the port for the internal server to listen on. If not provided then Mac2Driver will use the default port 10100. """ - SystemPortOption.system_port.fset(self, value) + SystemPortOption.system_port.fset(self, value) # type: ignore - @SystemHostOption.system_host.setter + @SystemHostOption.system_host.setter # type: ignore def system_host(self, value: str) -> None: """ Set the number of the port for the internal server to listen on. @@ -88,7 +88,7 @@ def system_host(self, value: str) -> None: server listening on all available network interfaces. It is also possible to set the particular interface name, for example en1. """ - SystemHostOption.system_host.fset(self, value) + SystemHostOption.system_host.fset(self, value) # type: ignore @property def default_capabilities(self) -> Dict: