فهرست منبع

修改截屏线程退出的逻辑

LiHaoyu 4 سال پیش
والد
کامیت
e310c7958e
1فایلهای تغییر یافته به همراه41 افزوده شده و 36 حذف شده
  1. 41 36
      src/main/java/net/mooctest/www/android_auto_test/Obversers/ScreenShotThread.java

+ 41 - 36
src/main/java/net/mooctest/www/android_auto_test/Obversers/ScreenShotThread.java

@@ -45,48 +45,53 @@ public class ScreenShotThread extends Thread {
         }
     }
     private void takeScreenShot(AppiumDriver driver,String udid) throws NoSuchSessionException{
-        while(!isEnd){
-            try {
-                File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
+        try {
+            while(!isEnd){
                 try {
-                    String deviceTimestamp = DeviceUtil.getDeviceTimeStamp(udid);
-                    // 解析timestamp防止返回的不是数字
-                    long ignored = Long.parseLong(deviceTimestamp);
-                    String path = AddressUtil.getScreenShotFilePath(traceId, udid, deviceTimestamp);
-                    FileUtils.copyFile(screenShotFile, new File(path));
-                } catch (IOException | NumberFormatException e) {
-                    e.printStackTrace();
-                }
-                FileReader fr;
-                try{
-                    fr = new FileReader(screenShotFile);
-                    if(fr.read() == -1){
-                        screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
-                        try {
-                            String deviceTimestamp = DeviceUtil.getDeviceTimeStamp(udid);
-                            // 解析timestamp防止返回的不是数字
-                            long ignored = Long.parseLong(deviceTimestamp);
-                            String path = AddressUtil.getScreenShotFilePath(traceId, udid, deviceTimestamp);
-                            FileUtils.copyFile(screenShotFile, new File(path));
-                        } catch (IOException | NumberFormatException e) {
-                            e.printStackTrace();
-                        }
+                    File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
+                    try {
+                        String deviceTimestamp = DeviceUtil.getDeviceTimeStamp(udid);
+                        // 解析timestamp防止返回的不是数字
+                        long ignored = Long.parseLong(deviceTimestamp);
+                        String path = AddressUtil.getScreenShotFilePath(traceId, udid, deviceTimestamp);
+                        FileUtils.copyFile(screenShotFile, new File(path));
+                    } catch (IOException | NumberFormatException e) {
+                        e.printStackTrace();
+                    }
+                    FileReader fr;
+                    try{
+                        fr = new FileReader(screenShotFile);
                         if(fr.read() == -1){
-                            screenShotFile.delete();
+                            screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
+                            try {
+                                String deviceTimestamp = DeviceUtil.getDeviceTimeStamp(udid);
+                                // 解析timestamp防止返回的不是数字
+                                long ignored = Long.parseLong(deviceTimestamp);
+                                String path = AddressUtil.getScreenShotFilePath(traceId, udid, deviceTimestamp);
+                                FileUtils.copyFile(screenShotFile, new File(path));
+                            } catch (IOException | NumberFormatException e) {
+                                e.printStackTrace();
+                            }
+                            if(fr.read() == -1){
+                                screenShotFile.delete();
+                            }
                         }
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                } catch (WebDriverException e){
+                    PrintUtil.print("Cannot take screenshot", TAG, udid);
+                } finally {
+                    try {
+                        Thread.sleep(2000);
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
                     }
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            } catch (WebDriverException e){
-                PrintUtil.print("Cannot take screenshot", TAG, udid);
-            } finally {
-                try {
-                    Thread.sleep(2000);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
                 }
             }
+        }catch (Exception e){
+            e.printStackTrace();
         }
+
     }
 }