from helpers.appium.driver_utils import get_device_name def get_coordinate(driver, mapping): device_name = get_device_name(driver) # First, try to match device name exactly (case-insensitive). for name, coord in mapping.items(): if name.lower() == device_name.lower(): return coord # If no exact match, fall back to substring matching, but prefer # more specific (longer) keys to avoid false matches. device_name_lower = device_name.lower() for name, coord in sorted(mapping.items(), key=lambda kv: len(kv[0]), reverse=True): if name.lower() in device_name_lower: return coord raise ValueError(f"No coordinate found for device: {device_name}")