|
@@ -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();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|