|  | 
| 11 | 11 | #                       # | 
| 12 | 12 | ######################### | 
| 13 | 13 | 
 | 
|  | 14 | + | 
| 14 | 15 | from appium import webdriver | 
| 15 |  | -from appium.options.android import UiAutomator2Options | 
| 16 |  | -from appium.options.ios import XCUITestOptions | 
| 17 |  | -from appium.options.mac import Mac2Options | 
|  | 16 | +# from appium.options.android import UiAutomator2Options | 
|  | 17 | +# from appium.options.ios import XCUITestOptions | 
|  | 18 | +# from appium.options.mac import Mac2Options | 
|  | 19 | +from appium.options.android.uiautomator2.base import UiAutomator2Options | 
|  | 20 | +from appium.options.ios.xcuitest.base import XCUITestOptions | 
|  | 21 | +from appium.options.mac.mac2.base import Mac2Options | 
| 18 | 22 | import traceback | 
| 19 | 23 | import socket | 
| 20 | 24 | import os, sys, datetime, time, inspect, subprocess, re, signal, _thread, requests, copy | 
| @@ -448,6 +452,96 @@ def unlock_android_app(data_set): | 
| 448 | 452 |         ) | 
| 449 | 453 | 
 | 
| 450 | 454 | 
 | 
|  | 455 | +def remote_launch(data_set): | 
|  | 456 | +    """ | 
|  | 457 | +    Launch the application on a Kobiton remote device using direct user input. | 
|  | 458 | +    Handles commented desired capabilities. | 
|  | 459 | +    """ | 
|  | 460 | +     | 
|  | 461 | +    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME | 
|  | 462 | + | 
|  | 463 | +    remote_url = "" | 
|  | 464 | +    desired_caps = {} | 
|  | 465 | + | 
|  | 466 | +    try: | 
|  | 467 | +        for entry in data_set: | 
|  | 468 | +            key = entry[0].strip() | 
|  | 469 | +            value = entry[2].strip() | 
|  | 470 | +            if key == "remote_url": | 
|  | 471 | +                remote_url = value | 
|  | 472 | +            elif key == "desired_caps": | 
|  | 473 | +                desired_caps = CommonUtil.parse_value_into_object(value) | 
|  | 474 | + | 
|  | 475 | +        if not remote_url: | 
|  | 476 | +            CommonUtil.ExecLog(sModuleInfo, "Remote URL not provided", 3) | 
|  | 477 | +            return "zeuz_failed" | 
|  | 478 | +        if not desired_caps: | 
|  | 479 | +            CommonUtil.ExecLog(sModuleInfo, "Desired capabilities not provided", 3) | 
|  | 480 | +            return "zeuz_failed" | 
|  | 481 | + | 
|  | 482 | +        CommonUtil.ExecLog( | 
|  | 483 | +            sModuleInfo, | 
|  | 484 | +            f"Launching Kobiton session with capabilities: {desired_caps}", | 
|  | 485 | +            1, | 
|  | 486 | +        ) | 
|  | 487 | + | 
|  | 488 | +        global appium_driver, appium_details, device_id, device_serial | 
|  | 489 | + | 
|  | 490 | +        platform = desired_caps["platformName"].lower() | 
|  | 491 | +         | 
|  | 492 | +        if platform == "android": | 
|  | 493 | +            from appium.options.android import UiAutomator2Options | 
|  | 494 | +            options = UiAutomator2Options().load_capabilities(desired_caps) | 
|  | 495 | +        elif platform == "ios": | 
|  | 496 | +            from appium.options.ios import XCUITestOptions | 
|  | 497 | +            options = XCUITestOptions().load_capabilities(desired_caps) | 
|  | 498 | +        else: | 
|  | 499 | +            CommonUtil.ExecLog(sModuleInfo, "Platform must be either 'Android' or 'iOS'", 3) | 
|  | 500 | +            return "zeuz_failed" | 
|  | 501 | + | 
|  | 502 | +        appium_driver = webdriver.Remote( | 
|  | 503 | +            command_executor=remote_url, | 
|  | 504 | +            options=options | 
|  | 505 | +        ) | 
|  | 506 | + | 
|  | 507 | +        time.sleep(5) | 
|  | 508 | +     | 
|  | 509 | +        session_id = appium_driver.session_id | 
|  | 510 | +        device_name = desired_caps.get('appium:deviceName', 'Unknown Device') | 
|  | 511 | + | 
|  | 512 | +        device_id = f"Kobiton_{device_name}_{session_id[:8]}" | 
|  | 513 | +        device_serial = f"kobiton_{session_id}" | 
|  | 514 | +         | 
|  | 515 | +        appium_details[device_id] = { | 
|  | 516 | +            "driver": appium_driver, | 
|  | 517 | +            "serial": device_serial, | 
|  | 518 | +            "type": platform, | 
|  | 519 | +            "kobiton_session": session_id | 
|  | 520 | +        } | 
|  | 521 | + | 
|  | 522 | +        Shared_Resources.Set_Shared_Variables("appium_details", appium_details) | 
|  | 523 | +        Shared_Resources.Set_Shared_Variables("device_id", device_id, protected=True) | 
|  | 524 | +        Shared_Resources.Set_Shared_Variables("device_serial", device_serial, protected=True) | 
|  | 525 | + | 
|  | 526 | +        portal_url = f"https://portal.kobiton.com/sessions/{session_id}" | 
|  | 527 | +        CommonUtil.ExecLog( | 
|  | 528 | +            sModuleInfo,  | 
|  | 529 | +            f"Kobiton session created successfully. View session at: {portal_url}",  | 
|  | 530 | +            1 | 
|  | 531 | +        ) | 
|  | 532 | +         | 
|  | 533 | +        return "passed" | 
|  | 534 | + | 
|  | 535 | +    except Exception: | 
|  | 536 | +        error_msg = CommonUtil.Exception_Handler(sys.exc_info()) | 
|  | 537 | +        CommonUtil.ExecLog( | 
|  | 538 | +            sModuleInfo, | 
|  | 539 | +            f"Failed to create Kobiton Appium driver: {error_msg}", | 
|  | 540 | +            3 | 
|  | 541 | +        ) | 
|  | 542 | +        return "zeuz_failed" | 
|  | 543 | + | 
|  | 544 | + | 
| 451 | 545 | @logger | 
| 452 | 546 | def launch_application(data_set): | 
| 453 | 547 |     """ Launch the application the appium instance was created with, and create the instance if necessary """ | 
|  | 
0 commit comments