Merge pull request #274 from iqalab-cloud/feature-support-selenium-proxy-class

Feature: Support customised Selenium Proxy Class when use Appium
This commit is contained in:
Budi Utomo 2021-01-09 11:21:30 +01:00 committed by GitHub
commit 76617374c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -25,6 +25,7 @@ It is also possible to connect appium server that run inside docker-android with
- SELENIUM_HOST="\<host\_ip\_address>" - SELENIUM_HOST="\<host\_ip\_address>"
- SELENIUM_PORT=\<port\_number> - SELENIUM_PORT=\<port\_number>
- SELENIUM_TIMEOUT=\<timeout\_in\_seconds> - SELENIUM_TIMEOUT=\<timeout\_in\_seconds>
- SELENIUM_PROXY_CLASS=\<selenium\_proxy\_class\_name>
To run tests for mobile browser, following parameter can be passed: To run tests for mobile browser, following parameter can be passed:

View file

@ -149,9 +149,10 @@ def appium_run(avd_name: str):
selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1') selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1')
selenium_port = int(os.getenv('SELENIUM_PORT', 4444)) selenium_port = int(os.getenv('SELENIUM_PORT', 4444))
selenium_timeout = int(os.getenv('SELENIUM_TIMEOUT', 30)) selenium_timeout = int(os.getenv('SELENIUM_TIMEOUT', 30))
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' 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, 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) cmd += ' --nodeconfig {file}'.format(file=CONFIG_FILE)
except ValueError as v_err: except ValueError as v_err:
logger.error(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, 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. 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_host: Host where selenium server is running
:param selenium_port: Port number 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_timeout: Selenium session timeout in seconds
:param selenium_proxy_class: Selenium Proxy class created in Selenium hub
""" """
config = { config = {
'capabilities': [ 'capabilities': [
@ -185,7 +187,7 @@ def create_node_config(avd_name: str, browser_name: str, appium_host: str, appiu
'configuration': { 'configuration': {
'cleanUpCycle': 2000, 'cleanUpCycle': 2000,
'timeout': selenium_timeout, '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), 'url': 'http://{host}:{port}/wd/hub'.format(host=appium_host, port=appium_port),
'host': appium_host, 'host': appium_host,
'port': appium_port, 'port': appium_port,

View file

@ -58,7 +58,8 @@ class TestAppium(TestCase):
def test_config_creation(self): def test_config_creation(self):
from src import CONFIG_FILE from src import CONFIG_FILE
self.assertFalse(os.path.exists(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)) self.assertTrue(os.path.exists(CONFIG_FILE))
os.remove(CONFIG_FILE) os.remove(CONFIG_FILE)