Browse Source

测试wda ,测试打开钉钉,差点击功能

caner 8 months ago
parent
commit
3d544b7de5
1 changed files with 35 additions and 24 deletions
  1. 35 24
      main.py

+ 35 - 24
main.py

@@ -4,7 +4,27 @@ from pymobiledevice3.services.dvt.instruments.process_control import ProcessCont
 from pymobiledevice3.services.installation_proxy import InstallationProxyService
 from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
 
-BUNDLE_ID = 'com.laiwang.DingTalk'
+DD_BUNDLE_ID = 'com.laiwang.DingTalk' # 钉钉包名
+WDA_BUNDLE_ID = 'com.caner.test.xctrunner' #个人包名
+
+# 启动app
+def launchApp(lockdown,installer,BUNDLE_ID,Name):
+    if(BUNDLE_ID and lockdown and installer):
+        Apps = [app for app in installer.get_apps() if Name in app]
+        if len(Apps):
+            if Apps[0] == BUNDLE_ID:
+                with DvtSecureSocketProxyService(lockdown) as dvt:
+                    process_control = ProcessControl(dvt)
+                    pid = process_control.launch(BUNDLE_ID)
+                    print("启动app",pid,BUNDLE_ID)
+                    sleep(3)
+                    return True
+            else:
+                return False
+        else:
+            return False
+    else:
+        return False
 
 def main():
     try:
@@ -12,29 +32,20 @@ def main():
         lockdown = create_using_usbmux()
         print("开发者模式",lockdown.developer_mode_status)
         
-        # 获取钉钉-app
-        # with InstallationProxyService(lockdown) as installer:
-        #     apps = installer.get_apps()
-        #     for app in apps.values():
-        #         print(f"{app['CFBundleIdentifier']}: {app.get('CFBundleDisplayName', '无名应用')}")
-            # 查找特定应用
-            # ddApp = [app for app in installer.get_apps() if 'DingTalk' in app]
-            # if len(ddApp):
-            #     print("找到包",ddApp[0])
-            #     if ddApp[0] == BUNDLE_ID:
-            #         # 打开app
-            #         with DvtSecureSocketProxyService(lockdown) as dvt:
-            #             process_control = ProcessControl(dvt)
-            #             pid = process_control.launch(BUNDLE_ID)
-            #             print("启动app",pid)
-            #             # 点击工作台
-            #             sleep(5)
-                       
-            #     else:
-            #         print("包名不匹配")
-            # else:
-            #     print("没找到包,请安装钉钉")
-
+        # 获取app
+        with InstallationProxyService(lockdown) as installer:
+            # 启动WDA
+            wda_start = launchApp(lockdown,installer,WDA_BUNDLE_ID,'xctrunner')
+            if(wda_start):
+                print('已启动wda')
+                # 启动钉钉
+                dd_start = launchApp(lockdown,installer,DD_BUNDLE_ID,'DingTalk')
+                if(dd_start):
+                    print('已启动钉钉')
+                else:
+                    print("没找到钉钉安装包")
+            else:
+                print("没找到WDA安装包")
     except ConnectionError as e:
         print(f"连接失败")