From 3b131975c8996ae3b8d9a15a039fb5998fada4c6 Mon Sep 17 00:00:00 2001 From: tauqirsarwar1 Date: Wed, 8 May 2024 17:50:14 +0500 Subject: [PATCH 1/2] Added soucelabs integration --- env_configs/.local.env | 2 + env_configs/souce_labs/android_mobile_SL.json | 14 ++++++ env_configs/souce_labs/ios_mobile_SL.json | 14 ++++++ env_configs/souce_labs/win_chrome_SL.json | 12 +++++ main/frontend/frontend_plugin.py | 45 +++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 env_configs/souce_labs/android_mobile_SL.json create mode 100644 env_configs/souce_labs/ios_mobile_SL.json create mode 100644 env_configs/souce_labs/win_chrome_SL.json diff --git a/env_configs/.local.env b/env_configs/.local.env index 6e8b7576..803353c9 100644 --- a/env_configs/.local.env +++ b/env_configs/.local.env @@ -33,3 +33,5 @@ API_BASE_URL=https://jsonplaceholder.typicode.com #Open AI OPEN_KEY= USING_DOCKER= +# BROWSERSTACK , SAUCELABS +USING_ENV= diff --git a/env_configs/souce_labs/android_mobile_SL.json b/env_configs/souce_labs/android_mobile_SL.json new file mode 100644 index 00000000..5c664b11 --- /dev/null +++ b/env_configs/souce_labs/android_mobile_SL.json @@ -0,0 +1,14 @@ +{ + "capabilities": { + "platformVersion": "10", + "deviceName": "Samsung Galaxy S9", + "platformName": "Android", + "app": "storage:filename=Android-MyDemoAppRN.1.3.0.build-244.apk", + "appiumVersion": "latest", + "sauce:options": { + "build": "Pytest-Automation-Boilerplate", + "name": "Android App Tests", + "extendedDebugging": true + } + } +} diff --git a/env_configs/souce_labs/ios_mobile_SL.json b/env_configs/souce_labs/ios_mobile_SL.json new file mode 100644 index 00000000..dfeb695e --- /dev/null +++ b/env_configs/souce_labs/ios_mobile_SL.json @@ -0,0 +1,14 @@ +{ + "capabilities": { + "platformVersion": "16.7", + "deviceName": "iPhone 12", + "platformName": "iOS", + "app": "storage:filename=iOS-Real-Device-MyRNDemoApp.1.3.0-162.ipa", + "appiumVersion": "latest", + "sauce:options": { + "build": "Pytest-Automation-Boilerplate", + "name": "IOS App Tests", + "extendedDebugging": true + } + } +} diff --git a/env_configs/souce_labs/win_chrome_SL.json b/env_configs/souce_labs/win_chrome_SL.json new file mode 100644 index 00000000..58c26a26 --- /dev/null +++ b/env_configs/souce_labs/win_chrome_SL.json @@ -0,0 +1,12 @@ +{ + "capabilities": { + "browserName": "Chrome", + "browserVersion": "latest", + "platformName": "Windows 11", + "sauce:options": { + "build": "Pytest-Automation-Boilerplate", + "name": "Web UI Tests", + "extendedDebugging": true + } + } +} diff --git a/main/frontend/frontend_plugin.py b/main/frontend/frontend_plugin.py index 3868e536..8c5abbd9 100644 --- a/main/frontend/frontend_plugin.py +++ b/main/frontend/frontend_plugin.py @@ -256,6 +256,30 @@ def driver_kwargs(capabilities, host, **kwargs): # noqa appium.driver_kwargs = driver_kwargs remote.driver_kwargs = driver_kwargs + elif os.environ.get("USING_ENV", "") == 'SAUCELABS' and session_capabilities.get("platformName", "").lower() in ( + "android", "ios"): + value, options = driver_options_factory + + for k, v in session_capabilities.items(): + options.set_capability(k, v) + + def driver_kwargs(capabilities, host, port, **kwargs): # noqa + _ = capabilities + if value in ("chrome", "edge", "firefox"): + browser_options = kwargs.get(f"{value}_options", None) + browser_options_arguments = getattr(browser_options, "arguments", []) + browser_options_capabilities = getattr(browser_options, "capabilities", {}) + options.capabilities.update(browser_options_capabilities) + options.arguments.extend([x for x in browser_options_arguments if x not in options.arguments]) + + executor = f"https://{host}:443/wd/hub" + kwargs = {"command_executor": executor, "options": options} + + return kwargs + + remote.driver_kwargs = driver_kwargs + appium.driver_kwargs = driver_kwargs + # To pass options for local Android and iOS test executions elif session_capabilities.get("platformName", "").lower() in ("android", "ios"): value, options = driver_options_factory @@ -295,6 +319,27 @@ def driver_kwargs(capabilities, host, port, **kwargs): # noqa remote.driver_kwargs = driver_kwargs + elif os.environ.get("USING_ENV", "") == 'SAUCELABS': + value, options = driver_options_factory + + for k, v in session_capabilities.items(): + options.set_capability(k, v) + + def driver_kwargs(capabilities, host, port, **kwargs): # noqa + _ = capabilities + if value in ("chrome", "edge", "firefox"): + browser_options = kwargs.get(f"{value}_options", None) + browser_options_arguments = getattr(browser_options, "arguments", []) + browser_options_capabilities = getattr(browser_options, "capabilities", {}) + options.capabilities.update(browser_options_capabilities) + options.arguments.extend([x for x in browser_options_arguments if x not in options.arguments]) + + executor = f"https://{host}:443/wd/hub" + kwargs = {"command_executor": executor, "options": options} + + return kwargs + + remote.driver_kwargs = driver_kwargs # Define selenium generics as a fixture # This is UI specific implementation From e292c896d792596b9d9d6d7b32acba37e7d17ed2 Mon Sep 17 00:00:00 2001 From: tauqirsarwar1 Date: Wed, 8 May 2024 17:52:10 +0500 Subject: [PATCH 2/2] Repo url fixed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5fbafae..4abe2ffb 100755 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ This document assumes that user has: ```shell mkdir workspaces && cd workspaces - git clone https://github.com/modus/pytest-automation-boilerplate.git + git clone https://github.com/tweag/pytest-automation-boilerplate.git # alternatively, you could use ssh link if you have setup ssh in your work machine. ```