Skip to content
Open
Changes from 1 commit
Commits
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
73 changes: 58 additions & 15 deletions optics_framework/engines/drivers/appium.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def appium_find_element(self, element: str) -> Optional[Any]:
return None

def _is_deeplink(self, value: str) -> bool:
return isinstance(value, str) and "://" in value
return isinstance(value, str) and "://" in value.strip()

def _open_deeplink(
self,
Expand All @@ -1098,6 +1098,7 @@ def _open_deeplink(
self.capabilities.get(self.CAP_PLATFORM_NAME)
or self.capabilities.get(self.CAP_APPIUM_PLATFORM_NAME)
)
platform = str(platform).lower() if platform else None

if not platform:
raise OpticsError(
Expand Down Expand Up @@ -1127,36 +1128,78 @@ def _open_android_deeplink(
) -> None:

try:
package = (
self.capabilities.get(self.CAP_APP_PACKAGE)
or self.capabilities.get(self.CAP_APP_PACKAGE_LEGACY)
)

driver.execute_script(
"mobile: deepLink",
{"url": deeplink},
{
"url": deeplink,
"package": package,
},
)
internal_logger.debug(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be added to the end of the function, like in ios deep link implementation

f"Android deep link launched: {deeplink}"
)
return

except Exception:
internal_logger.debug(
"mobile:deepLink failed, using adb fallback"

except Exception as exc:
internal_logger.debug(f"mobile:deepLink failed, using adb fallback: {exc}")

device_id = (driver.capabilities or {}).get("udid")

cmd = ["adb", "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", deeplink]

if device_id:
cmd.insert(1, "-s")
cmd.insert(2, device_id)

try:
result = subprocess.run(
cmd,
check=True,
capture_output=True,
text=True,
)

# nosec B603 - adb command executed with static trusted arguments for Android deeplink fallback
subprocess.run(["adb","shell","am","start","-a","android.intent.action.VIEW","-d",deeplink,],check=True,)
internal_logger.debug(f"ADB stdout: {result.stdout}")
internal_logger.debug(f"ADB stderr: {result.stderr}")

except subprocess.CalledProcessError as exc:
raise OpticsError(
Code.E0401,
message=f"ADB deeplink failed: {deeplink}",
cause=exc,
) from exc

def _open_ios_deeplink(
self,
driver: WebDriver,
deeplink: str,
) -> None:

driver.execute_script(
"mobile: launchApp",
{"bundleId": "com.apple.mobilesafari"},
)
try:
driver.execute_script(
"mobile: openUrl",
{"url": deeplink},
)

driver.get(deeplink)
except Exception as exc:
internal_logger.debug(
f"mobile:openUrl failed, launching Safari fallback: {exc}"
)

internal_logger.debug(
f"iOS deep link launched: {deeplink}"
)
driver.execute_script(
"mobile: launchApp",
{"bundleId": "com.apple.mobilesafari"},
)

driver.execute_script(
"mobile: openUrl",
{"url": deeplink},
)

internal_logger.debug(f"iOS deep link launched: {deeplink}")
Loading