Browse Source

使用airtest库

caner 7 months ago
parent
commit
8271ab1419
11 changed files with 113 additions and 42 deletions
  1. BIN
      .DS_Store
  2. 11 2
      README.md
  3. BIN
      img/checking_black.png
  4. BIN
      img/gzt_black.png
  5. BIN
      img/gzt_white.png
  6. 25 40
      main.py
  7. BIN
      test.png
  8. 77 0
      test.py
  9. BIN
      test2.png
  10. BIN
      test3.png
  11. BIN
      test4.png

BIN
.DS_Store


+ 11 - 2
README.md

@@ -21,6 +21,15 @@ WDA:
         $ mkdir Payload && cp -r *.app Payload
         $ zip -r WDA.ipa Payload
         # 打开ipa 删除所有XC开头的文件
+        #重签名软件:https://dantheman827.github.io/ios-app-signer/
+        #wda:https://zhuanlan.zhihu.com/p/673319266
     ```
-    重签名软件:https://dantheman827.github.io/ios-app-signer/
-    wda:https://zhuanlan.zhihu.com/p/673319266
+
+    xcode-test:
+    ```
+        # 打开WebDriverAgent.xcodeproj文件
+        # 修改webDriverAgentLib 和 webDriverAgentRunner 的证书team
+        # 修改包名
+        # prodocut->test 
+        # 出现 automation running 即可
+    ```

BIN
img/checking_black.png


BIN
img/gzt_black.png


BIN
img/gzt_white.png


+ 25 - 40
main.py

@@ -1,51 +1,36 @@
+from airtest.core.api import init_device,assert_exists,Template,touch
 from time import sleep
-from pymobiledevice3.lockdown import create_using_usbmux
-from pymobiledevice3.services.dvt.instruments.process_control import ProcessControl
-from pymobiledevice3.services.installation_proxy import InstallationProxyService
-from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
 
 DD_BUNDLE_ID = 'com.laiwang.DingTalk' # 钉钉包名
 WDA_BUNDLE_ID = 'com.caner.test.xctrunner' #个人包名
+UDID = '00008030-000415D614E0402E' # pymobiledevice3 usbmux list 查看手机id
 
-# 启动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 offDuty():
+    # 下班工作台
+    touch(Template('./img/gzt_black.png'))
+    sleep(1)
+    # 点击考勤
+    touch(Template('./img/checking_black.png'))
+    
+def onDuty():
+    # 上班工作台
+    touch(Template('./img/gzt_white.png'))
 
 def main():
     try:
-        # 连接手机
-        lockdown = create_using_usbmux()
-        # 获取已安装的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("连接失败")    
+        # 连接手机->自动启动wda
+        wda = init_device("IOS",UDID)
+        try:
+            # 打开d钉钉
+            wda.start_app(DD_BUNDLE_ID)
+            sleep(1)
+            offDuty()
+            wda.snapshot('test4.png')
+
+        except Exception as es:
+            print('操作错误',es)
+    except EnvironmentError as e:
+        print('连接错误',e)
 
 
 if __name__ == '__main__':

BIN
test.png


+ 77 - 0
test.py

@@ -0,0 +1,77 @@
+from time import sleep
+from pymobiledevice3.lockdown import create_using_usbmux
+from pymobiledevice3.services.dvt.instruments.process_control import ProcessControl
+from pymobiledevice3.services.installation_proxy import InstallationProxyService
+from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
+import wda
+
+DD_BUNDLE_ID = 'com.laiwang.DingTalk' # 钉钉包名
+WDA_BUNDLE_ID = 'com.caner.test.xctrunner' #个人包名
+UDID = '00008030-000415D614E0402E' # pymobiledevice3 usbmux list 查看手机id
+
+# 启动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:
+        # 连接手机
+        lockdown = create_using_usbmux()
+        print("是否已连接手机",lockdown.developer_mode_status)
+        # 获取已安装的app
+        with InstallationProxyService(lockdown) as installer:
+            # 启动WDA
+            wda_start = launchApp(lockdown,installer,WDA_BUNDLE_ID,'xctrunner')
+            if(wda_start):
+                print('已启动wda')
+                # 连接WDA客户端
+                wdaClient = wda.USBClient(UDID)
+                if(wdaClient):
+                    # 启动钉钉
+                    dd_start = launchApp(lockdown,installer,DD_BUNDLE_ID,'DingTalk')
+                    if(dd_start):
+                        gzt = wdaClient(name="工作台, ",label="工作台, ")
+                        if(gzt.exists):
+                            print('找到工作台按钮') 
+                            gzt.click()
+    
+                            
+                        else:
+                            print('未找到工作台,需要重启app')
+                        # # 点击工作台
+                        # wdaClient.tap(207,837)
+                        # sleep(3)
+                        # # 点击考勤打卡
+                        # wdaClient.tap(41,420)
+                        # sleep(3)
+                        # # 打卡
+                        # # wdaClient.tap(206,555)
+                        # a = wdaClient.xpath
+                        # print('啥意思',a)
+                    else:
+                        print("没找到钉钉安装包")
+                else:
+                    print("连失败")
+            else:
+                print("没找到WDA安装包")
+    except ConnectionError as e:
+        print("连接失败",e)    
+
+
+if __name__ == '__main__':
+    main()

BIN
test2.png


BIN
test3.png


BIN
test4.png