wda保留日志

master
yineng.huang 2024-07-16 20:29:05 +08:00
parent cd09e7e35f
commit ac729d46c1
3 changed files with 28 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Calendar;
import java.util.LinkedHashMap;
/**
@ -85,5 +86,10 @@ public abstract class IosDeviceInitThread extends Thread {
public abstract void exitWdaAndProxy();
protected String getLogFileNameDateTime() {
Calendar calendar = Calendar.getInstance();
return String.format("%s%d%d_%d-%d-%d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
}
}

View File

@ -122,7 +122,6 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
if (logOutput != null) {
logOutput.write(line.getBytes());
logOutput.write(10);
logOutput.write(13);
}
if (outputLineCallback != null) {
try {
@ -193,11 +192,6 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
}).start();
}
private String getLogFileNameDateTime() {
Calendar calendar = Calendar.getInstance();
return String.format("%s%d%d_%d-%d-%d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
}
public NKAgent getNkAgent() {
return nkAgent;
}

View File

@ -14,12 +14,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.util.StringUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
@ -77,19 +75,29 @@ public class WindowsAndLinuxIosDeviceInitThread extends IosDeviceInitThread {
cmds.add("tidevice");
cmds.add("-u");
cmds.add(phone.getUdid());
cmds.add("xctest");
cmds.add("xcuitest");
cmds.add("-B");
cmds.add(appPackage);
cmds.add("--debug");
ProcessBuilder processBuilder = new ProcessBuilder().command(cmds);
processBuilder.redirectErrorStream(true);
LineNumberReader input = null;
File wdaLogPath = new File(UpperComputerManager.getInstance().getApplicationPath() + "/wdaLog");
if (!wdaLogPath.exists()) {
wdaLogPath.mkdirs();
}
while (!isInterrupted()) {
File wdaLogFile = new File(wdaLogPath.getAbsolutePath() + "/WDA-" + appleDevice.getConnectionDetail().serialNumber + "-" + getLogFileNameDateTime() + ".log");
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(wdaLogFile);
this.wdaProcess = processBuilder.start();
input = new LineNumberReader(new InputStreamReader(this.wdaProcess.getInputStream()));
String line = null;
while (null != (line = input.readLine())) {
logger.debug("设备【{}】wda程序打印{}", phone.getUdid(), line);
// logger.debug("设备【{}】wda程序打印{}", phone.getUdid(), line);
fileOutputStream.write(line.getBytes(StandardCharsets.UTF_8));
fileOutputStream.write(10);
if (line.contains(SUCCESS_FLAG)) {
logger.info("设备【{}】的wda程序启动成功开启nkAgent。。。。。。。。。", phone.getUdid());
createNKAgent();
@ -100,6 +108,14 @@ public class WindowsAndLinuxIosDeviceInitThread extends IosDeviceInitThread {
}
} catch (IOException e) {
logger.error("启动wda程序出错", e);
}finally {
if (null != fileOutputStream) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
int code = 0;
try {