Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ def start_appium_driver(
if str(appium_details[device_id]["type"]).lower() == "android":
# All Desired caps = https://appium.io/docs/en/writing-running-appium/caps/
desired_caps["platformName"] = appium_details[device_id]["type"] # Set platform name
desired_caps["udid"] = appium_details[device_id]["serial"]
desired_caps["autoLaunch"] = "false" # Do not launch application
desired_caps["fullReset"] = "false" # Do not reinstall application
if no_reset:
Expand Down
1 change: 1 addition & 0 deletions Framework/MainDriverApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ def send_dom_variables():
def set_device_info_according_to_user_order(device_order, device_dict, test_case_no, test_case_name, user_info_object, Userid, **kwargs):
# Need to set device_info for browserstack here
global device_info
device_order = [[i, i] for i in range(1, len(device_dict) + 1)] # overriding zsvc return device order. zsvc only returns [[1,1]] without considering the number of devices available
shared.Set_Shared_Variables("device_order", device_order)
if isinstance(device_order, list):
try:
Expand Down
45 changes: 28 additions & 17 deletions server/mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import subprocess
import base64
import time
from typing import Literal
import asyncio

Expand Down Expand Up @@ -32,6 +31,7 @@
"""Model for device information."""
serial: str
status: str
name: str | None = None
# model: str | None = None
# product: str | None = None

Expand All @@ -42,33 +42,34 @@
# Get list of devices
devices_output = run_adb_command(f"{ADB_PATH} devices -l")
devices = []

# Parse adb devices output
for line in devices_output.split('\n')[1:]: # Skip first line (header)
index = 1
for line in devices_output.split("\n")[1:]: # Skip first line (header)
if line.strip():
parts = line.split()
if len(parts) >= 2:
serial = parts[0]
status = parts[1]
name = f"device {index}"
index += 1
# model = run_adb_command(f"{ADB_PATH} -s {serial} shell getprop ro.product.model")
# product = run_adb_command(f"{ADB_PATH} -s {serial} shell getprop ro.product.name")

devices.append(DeviceInfo(
serial=serial,
status=status
))

devices.append(DeviceInfo(serial=serial, status=status, name=name))

return devices
except Exception as e:
return []


@router.get("/inspect")
def inspect():
def inspect(device_serial: str | None = None):
"""Get the Mobile DOM and screenshot."""
try:
# Capture UI and screenshot
capture_ui_dump()
capture_screenshot()
capture_ui_dump(device_serial=device_serial)
capture_screenshot(device_serial=device_serial)

# Read XML file
with open(UI_XML_PATH, 'r') as xml_file:
Expand Down Expand Up @@ -102,15 +103,18 @@
def run_adb_command(command):
"""Run an ADB command and return the output."""
try:
result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

Check failure

Code scanning / CodeQL

Uncontrolled command line Critical

This command line depends on a
user-provided value
.
return result.stdout.strip()
except subprocess.CalledProcessError as e:
return f"Error: {e.stderr.strip()}"


def capture_ui_dump():
def capture_ui_dump(device_serial: str | None = None):
"""Capture the current UI hierarchy from the device"""
out = run_adb_command(f"{ADB_PATH} shell uiautomator dump /sdcard/ui.xml")
device_flag = f"-s {device_serial}" if device_serial else ""
out = run_adb_command(
f"{ADB_PATH} {device_flag} shell uiautomator dump /sdcard/ui.xml".strip()
)
if out.startswith("Error:"):
from Framework.Built_In_Automation.Mobile.CrossPlatform.Appium.BuiltInFunctions import appium_driver
if appium_driver is None:
Expand All @@ -119,22 +123,29 @@
with open(UI_XML_PATH, 'w') as xml_file:
xml_file.write(page_src)
else:
out = run_adb_command(f"{ADB_PATH} pull /sdcard/ui.xml {UI_XML_PATH}")
out = run_adb_command(
f"{ADB_PATH} {device_flag} pull /sdcard/ui.xml {UI_XML_PATH}"
)
if out.startswith("Error:"):
return


def capture_screenshot():
def capture_screenshot(device_serial: str | None = None):
"""Capture the current UI hierarchy from the device"""
out = run_adb_command(f"{ADB_PATH} shell screencap -p /sdcard/screen.png")
device_flag = f"-s {device_serial}" if device_serial else ""
out = run_adb_command(
f"{ADB_PATH} {device_flag} shell screencap -p /sdcard/screen.png".strip()
)
if out.startswith("Error:"):
from Framework.Built_In_Automation.Mobile.CrossPlatform.Appium.BuiltInFunctions import appium_driver
if appium_driver is None:
return
full_screenshot_path = os.path.join(os.getcwd(), SCREENSHOT_PATH)
appium_driver.save_screenshot(full_screenshot_path)
else:
out = run_adb_command(f"{ADB_PATH} pull /sdcard/screen.png {SCREENSHOT_PATH}")
out = run_adb_command(
f"{ADB_PATH} {device_flag} pull /sdcard/screen.png {SCREENSHOT_PATH}"
)
if out.startswith("Error:"):
return

Expand Down
Loading