From 5e7ce8ce66379b1333ae172a4c59527cbbefec29 Mon Sep 17 00:00:00 2001 From: Zhaopeng XUAN Date: Fri, 8 Jan 2021 11:44:56 +0100 Subject: [PATCH 1/2] Feature: Support Selenium Proxy Class when use Appium --- README_APPIUM_AND_SELENIUM.md | 1 + src/app.py | 8 +++++--- src/tests/unit/test_appium.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README_APPIUM_AND_SELENIUM.md b/README_APPIUM_AND_SELENIUM.md index b8a191b..0d60993 100644 --- a/README_APPIUM_AND_SELENIUM.md +++ b/README_APPIUM_AND_SELENIUM.md @@ -25,6 +25,7 @@ It is also possible to connect appium server that run inside docker-android with - SELENIUM_HOST="\" - SELENIUM_PORT=\ - SELENIUM_TIMEOUT=\ +- SELENIUM_PROXY_CLASS=\ To run tests for mobile browser, following parameter can be passed: diff --git a/src/app.py b/src/app.py index a517ea2..9b81883 100644 --- a/src/app.py +++ b/src/app.py @@ -149,9 +149,10 @@ def appium_run(avd_name: str): selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1') selenium_port = int(os.getenv('SELENIUM_PORT', 4444)) selenium_timeout = int(os.getenv('SELENIUM_TIMEOUT', 30)) + selenium_proxy_class = int(os.getenv('SELENIUM_PROXY_CLASS', 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy')) browser_name = default_web_browser if mobile_web_test else 'android' create_node_config(avd_name, browser_name, appium_host, appium_port, selenium_host, selenium_port, - selenium_timeout) + selenium_timeout, selenium_proxy_class) cmd += ' --nodeconfig {file}'.format(file=CONFIG_FILE) except ValueError as v_err: logger.error(v_err) @@ -160,7 +161,7 @@ def appium_run(avd_name: str): def create_node_config(avd_name: str, browser_name: str, appium_host: str, appium_port: int, selenium_host: str, - selenium_port: int, selenium_timeout: int): + selenium_port: int, selenium_timeout: int, selenium_proxy_class: str): """ Create custom node config file in json format to be able to connect with selenium server. @@ -170,6 +171,7 @@ def create_node_config(avd_name: str, browser_name: str, appium_host: str, appiu :param selenium_host: Host where selenium server is running :param selenium_port: Port number where selenium server is running :param selenium_timeout: Selenium session timeout in seconds + :param selenium_proxy_class: Selenium Proxy class created in Selenium hub """ config = { 'capabilities': [ @@ -185,7 +187,7 @@ def create_node_config(avd_name: str, browser_name: str, appium_host: str, appiu 'configuration': { 'cleanUpCycle': 2000, 'timeout': selenium_timeout, - 'proxy': 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy', + 'proxy': selenium_proxy_class, 'url': 'http://{host}:{port}/wd/hub'.format(host=appium_host, port=appium_port), 'host': appium_host, 'port': appium_port, diff --git a/src/tests/unit/test_appium.py b/src/tests/unit/test_appium.py index ed7ed1d..cd2b101 100644 --- a/src/tests/unit/test_appium.py +++ b/src/tests/unit/test_appium.py @@ -58,7 +58,8 @@ class TestAppium(TestCase): def test_config_creation(self): from src import CONFIG_FILE self.assertFalse(os.path.exists(CONFIG_FILE)) - app.create_node_config('test', 'android', '127.0.0.1', 4723, '127.0.0.1', 4444, 30) + app.create_node_config('test', 'android', '127.0.0.1', 4723, '127.0.0.1', 4444, 30, + 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy') self.assertTrue(os.path.exists(CONFIG_FILE)) os.remove(CONFIG_FILE) From 70fc3b411c64730dbdead3f1b013f962237bcd88 Mon Sep 17 00:00:00 2001 From: Zhaopeng XUAN Date: Fri, 8 Jan 2021 12:05:34 +0100 Subject: [PATCH 2/2] Fix the issue --- src/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.py b/src/app.py index 9b81883..d05f7bc 100644 --- a/src/app.py +++ b/src/app.py @@ -149,7 +149,7 @@ def appium_run(avd_name: str): selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1') selenium_port = int(os.getenv('SELENIUM_PORT', 4444)) selenium_timeout = int(os.getenv('SELENIUM_TIMEOUT', 30)) - selenium_proxy_class = int(os.getenv('SELENIUM_PROXY_CLASS', 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy')) + selenium_proxy_class = os.getenv('SELENIUM_PROXY_CLASS', 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy') browser_name = default_web_browser if mobile_web_test else 'android' create_node_config(avd_name, browser_name, appium_host, appium_port, selenium_host, selenium_port, selenium_timeout, selenium_proxy_class)