更改ios、harmony自动化截图
parent
28be3a4f12
commit
b1e29fd073
|
@ -41,4 +41,9 @@ public class UpperComputerConstant {
|
||||||
*/
|
*/
|
||||||
public static final String IOS = "1";
|
public static final String IOS = "1";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* harmony类型常量
|
||||||
|
*/
|
||||||
|
public static final String HARMONY = "2";
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ public class EngineController {
|
||||||
@Resource(name = "iosService")
|
@Resource(name = "iosService")
|
||||||
private DebuggerService iosService;
|
private DebuggerService iosService;
|
||||||
|
|
||||||
|
@Resource(name = "harmonyService")
|
||||||
|
private DebuggerService harmonyService;
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "获取设备驱动")
|
@ApiOperation(value = "获取设备驱动")
|
||||||
@PostMapping("/getDriver")
|
@PostMapping("/getDriver")
|
||||||
|
@ -83,8 +86,10 @@ public class EngineController {
|
||||||
logger.info("screen shot in device[{}]...............",info.getDeviceId());
|
logger.info("screen shot in device[{}]...............",info.getDeviceId());
|
||||||
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
||||||
result = iosService.getScreenShot(info);
|
result = iosService.getScreenShot(info);
|
||||||
} else {
|
} else if (UpperComputerConstant.ANDROID.equals(info.getPlatform())){
|
||||||
result = androidService.getScreenShot(info);
|
result = androidService.getScreenShot(info);
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
result = harmonyService.getScreenShot(info);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -146,17 +151,31 @@ public class EngineController {
|
||||||
@ApiOperation(value = "android清除数据")
|
@ApiOperation(value = "android清除数据")
|
||||||
@PostMapping("/cleanData")
|
@PostMapping("/cleanData")
|
||||||
public boolean cleanData(@RequestBody DebuggerDeviceInfo info){
|
public boolean cleanData(@RequestBody DebuggerDeviceInfo info){
|
||||||
return androidService.cleanData(info.getDeviceId(), info.getAppPackage());
|
boolean success = true;
|
||||||
|
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
|
success = androidService.cleanData(info.getDeviceId(),info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(info.getPlatform())){
|
||||||
|
success = iosService.cleanData(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
success = harmonyService.cleanData(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在获取应用版本的时候设备的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "获取包版本")
|
@ApiOperation(value = "获取包版本")
|
||||||
@PostMapping("/getPackageVersion")
|
@PostMapping("/getPackageVersion")
|
||||||
public String getPackageVersion(@RequestBody DebuggerDeviceInfo info){
|
public String getPackageVersion(@RequestBody DebuggerDeviceInfo info){
|
||||||
String version = "";
|
String version = "";
|
||||||
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
|
version = androidService.getPackageVersion(info.getDeviceId(),info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(info.getPlatform())){
|
||||||
version = iosService.getPackageVersion(info.getDeviceId(), info.getAppPackage());
|
version = iosService.getPackageVersion(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
version = harmonyService.getPackageVersion(info.getDeviceId(), info.getAppPackage());
|
||||||
} else {
|
} else {
|
||||||
version = androidService.getPackageVersion(info.getDeviceId(), info.getAppPackage());
|
logger.warn("设备【{}】在获取应用版本的时候设备的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
@ -173,8 +192,12 @@ public class EngineController {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
||||||
result = iosService.startRecord(info);
|
result = iosService.startRecord(info);
|
||||||
} else {
|
} else if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
result = androidService.startRecord(info);
|
result = androidService.startRecord(info);
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())){
|
||||||
|
result = harmonyService.startRecord(info);
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在开启录屏的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -183,11 +206,14 @@ public class EngineController {
|
||||||
@PostMapping("/endRecord")
|
@PostMapping("/endRecord")
|
||||||
public String endRecord(@RequestBody DebuggerDeviceInfo info){
|
public String endRecord(@RequestBody DebuggerDeviceInfo info){
|
||||||
String result = null;
|
String result = null;
|
||||||
logger.info("收到引擎结束记录的入参:{}", JSONObject.toJSONString(info));
|
|
||||||
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
||||||
result = iosService.endRecord(info);
|
result = iosService.endRecord(info);
|
||||||
} else {
|
} else if (UpperComputerConstant.ANDROID.equals(info.getPlatform())){
|
||||||
result = androidService.endRecord(info);
|
result = androidService.endRecord(info);
|
||||||
|
}else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())){
|
||||||
|
result = harmonyService.endRecord(info);
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在结束录屏的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +226,18 @@ public class EngineController {
|
||||||
@ApiOperation(value = "ios是否安装某一个包")
|
@ApiOperation(value = "ios是否安装某一个包")
|
||||||
@PostMapping("/isAppInstalled")
|
@PostMapping("/isAppInstalled")
|
||||||
public boolean isAppInstalled(@RequestBody DebuggerDeviceInfo info){
|
public boolean isAppInstalled(@RequestBody DebuggerDeviceInfo info){
|
||||||
return iosService.isAppInstalled(info.getDeviceId(), info.getAppPackage());
|
String platform = info.getPlatform();
|
||||||
|
boolean isInstalled = false;
|
||||||
|
if (UpperComputerConstant.ANDROID.equals(platform)) {
|
||||||
|
isInstalled = androidService.isAppInstalled(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(platform)) {
|
||||||
|
isInstalled = iosService.isAppInstalled(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(platform)) {
|
||||||
|
isInstalled = harmonyService.isAppInstalled(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在判断应用是否安装的类型未定义,类型:{}", info.getDeviceId(), platform);
|
||||||
|
}
|
||||||
|
return isInstalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +248,18 @@ public class EngineController {
|
||||||
@ApiOperation(value = "移除ios某一个包")
|
@ApiOperation(value = "移除ios某一个包")
|
||||||
@PostMapping("/removeApp")
|
@PostMapping("/removeApp")
|
||||||
public boolean removeApp(@RequestBody DebuggerDeviceInfo info){
|
public boolean removeApp(@RequestBody DebuggerDeviceInfo info){
|
||||||
return iosService.removeApp(info.getDeviceId(), info.getAppPackage());
|
String platform = info.getPlatform();
|
||||||
|
boolean remove = false;
|
||||||
|
if (UpperComputerConstant.ANDROID.equals(platform)) {
|
||||||
|
remove = androidService.removeApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(platform)) {
|
||||||
|
remove = iosService.removeApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(platform)) {
|
||||||
|
remove = harmonyService.removeApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在移除应用的类型未定义,类型:{}", info.getDeviceId(), platform);
|
||||||
|
}
|
||||||
|
return remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,10 +273,14 @@ public class EngineController {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int times = 0;
|
int times = 0;
|
||||||
while (times < 3) {
|
while (times < 3) {
|
||||||
if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
result = iosService.installApp(info.getDeviceId(), info.getAppPath(), info.getAppPackage());
|
result = androidService.installApp(info.getDeviceId(), info.getAppPath(),info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(info.getPlatform())) {
|
||||||
|
result = iosService.installApp(info.getDeviceId(), info.getAppPath(),info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
result = harmonyService.installApp(info.getDeviceId(), info.getAppPath(),info.getAppPackage());
|
||||||
} else {
|
} else {
|
||||||
result = androidService.installApp(info.getDeviceId(), info.getAppPath(), info.getAppPackage());
|
logger.warn("设备【{}】在安装应用的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
break;
|
break;
|
||||||
|
@ -247,8 +299,12 @@ public class EngineController {
|
||||||
}
|
}
|
||||||
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
success = androidService.activeApp(info.getDeviceId(),info.getAppPackage());
|
success = androidService.activeApp(info.getDeviceId(),info.getAppPackage());
|
||||||
} else {
|
} else if (UpperComputerConstant.IOS.equals(info.getPlatform())){
|
||||||
success = iosService.activeApp(info.getDeviceId(), info.getAppPackage());
|
success = iosService.activeApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
success = harmonyService.activeApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在启动应用的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +368,17 @@ public class EngineController {
|
||||||
@ApiOperation(value = "关闭App")
|
@ApiOperation(value = "关闭App")
|
||||||
@PostMapping("/terminateApp")
|
@PostMapping("/terminateApp")
|
||||||
public boolean terminateApp(@RequestBody DebuggerDeviceInfo info){
|
public boolean terminateApp(@RequestBody DebuggerDeviceInfo info){
|
||||||
return iosService.terminateApp(info.getDeviceId(), info.getAppPackage());
|
boolean success = false;
|
||||||
|
if (UpperComputerConstant.ANDROID.equals(info.getPlatform())) {
|
||||||
|
success = androidService.terminateApp(info.getDeviceId(),info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.IOS.equals(info.getPlatform())){
|
||||||
|
success = iosService.terminateApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else if (UpperComputerConstant.HARMONY.equals(info.getPlatform())) {
|
||||||
|
success = harmonyService.terminateApp(info.getDeviceId(), info.getAppPackage());
|
||||||
|
} else {
|
||||||
|
logger.warn("设备【{}】在关闭应用的时候设备的类型未定义,类型:{}", info.getDeviceId(), info.getPlatform());
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/releaseAdbForwardPort")
|
@PostMapping("/releaseAdbForwardPort")
|
||||||
|
|
|
@ -199,4 +199,9 @@ public abstract class AbstractDeviceManager extends Thread implements DeviceMana
|
||||||
public void setScreenInfo(String deviceId, ScreenInfo screenInfo) {
|
public void setScreenInfo(String deviceId, ScreenInfo screenInfo) {
|
||||||
this.screenInfoMap.put(deviceId, screenInfo);
|
this.screenInfoMap.put(deviceId, screenInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScreenInfo getScreenInfo(String deviceId) {
|
||||||
|
return screenInfoMap.get(deviceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public interface DeviceManager {
|
||||||
|
|
||||||
public boolean checkMobileIsOnline(String serial);
|
public boolean checkMobileIsOnline(String serial);
|
||||||
|
|
||||||
|
public ScreenInfo getScreenInfo(String deviceId);
|
||||||
|
|
||||||
public void setScreenInfo(String deviceId, ScreenInfo screenInfo);
|
public void setScreenInfo(String deviceId, ScreenInfo screenInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.northking.cctp.upperComputer.deviceManager.thread;
|
package net.northking.cctp.upperComputer.deviceManager.thread;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import net.northking.cctp.upperComputer.automation.entity.ScreenInfo;
|
||||||
import net.northking.cctp.upperComputer.config.BuildWdaConfig;
|
import net.northking.cctp.upperComputer.config.BuildWdaConfig;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
||||||
|
@ -200,6 +201,18 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
logger.debug("注册设备信息:{}", JSON.toJSONString(deviceInfo));
|
logger.debug("注册设备信息:{}", JSON.toJSONString(deviceInfo));
|
||||||
|
phone.setStatus(true);
|
||||||
|
ScreenInfoData screenInfoData = nkAgent.screenInfo();
|
||||||
|
logger.debug("获取设备【{}】的初始屏幕参数:{}",phone.getUdid(),JSON.toJSONString(screenInfoData));
|
||||||
|
ScreenInfo screenInfo = new ScreenInfo();
|
||||||
|
Double width = screenInfoData.getWidth() * screenInfoData.getScale();
|
||||||
|
Double height = screenInfoData.getHeight() * screenInfoData.getScale();
|
||||||
|
Double scale = screenInfoData.getScale();
|
||||||
|
screenInfo.setWidth(width.intValue());
|
||||||
|
screenInfo.setHeight(height.intValue());
|
||||||
|
screenInfo.setScale(scale.intValue());
|
||||||
|
screenInfo.setRotation((Integer) deviceInfo.get("rotation"));
|
||||||
|
IOSDeviceManager.getInstance().setScreenInfo(phone.getUdid(),screenInfo);
|
||||||
IOSDeviceManager.getInstance().registerDeviceToDeviceManager(deviceInfo);
|
IOSDeviceManager.getInstance().registerDeviceToDeviceManager(deviceInfo);
|
||||||
phone.setStatus(true);
|
phone.setStatus(true);
|
||||||
IOSDeviceManager.getInstance().publishDeviceAgentAlready(phone.getUdid());
|
IOSDeviceManager.getInstance().publishDeviceAgentAlready(phone.getUdid());
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.northking.cctp.upperComputer.deviceManager.thread;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import net.northking.cctp.upperComputer.automation.entity.ScreenInfo;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
||||||
import net.northking.cctp.upperComputer.driver.usbmuxd.AppleDevice;
|
import net.northking.cctp.upperComputer.driver.usbmuxd.AppleDevice;
|
||||||
|
@ -194,6 +195,12 @@ public class WindowsAndLinuxIosDeviceInitThread extends IosDeviceInitThread {
|
||||||
logger.warn("设备【{}】请求创建session时出错,待会再试", phone.getUdid());
|
logger.warn("设备【{}】请求创建session时出错,待会再试", phone.getUdid());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ScreenInfo screenInfo = new ScreenInfo();
|
||||||
|
screenInfo.setWidth(width*scale);
|
||||||
|
screenInfo.setHeight(height*scale);
|
||||||
|
screenInfo.setScale(scale);
|
||||||
|
screenInfo.setRotation((Integer) deviceInfo.get("rotation"));
|
||||||
|
IOSDeviceManager.getInstance().setScreenInfo(phone.getUdid(),screenInfo);
|
||||||
IOSDeviceManager.getInstance().publishDeviceAgentAlready(phone.getUdid());
|
IOSDeviceManager.getInstance().publishDeviceAgentAlready(phone.getUdid());
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package net.northking.cctp.upperComputer.service;
|
package net.northking.cctp.upperComputer.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import net.northking.cctp.upperComputer.config.MobileProperty;
|
import net.northking.cctp.upperComputer.config.MobileProperty;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
||||||
import net.northking.cctp.upperComputer.entity.DebuggerDeviceInfo;
|
import net.northking.cctp.upperComputer.entity.DebuggerDeviceInfo;
|
||||||
import net.northking.cctp.upperComputer.utils.ios.IosDeviceHandleHelper;
|
import net.northking.cctp.upperComputer.exception.ExecuteException;
|
||||||
import net.northking.cctp.upperComputer.utils.ios.LinuxAndWindowsIosHandleHelper;
|
import net.northking.cctp.upperComputer.utils.HttpUtils;
|
||||||
import net.northking.cctp.upperComputer.utils.ios.MacIosHandleHelper;
|
import net.northking.cctp.upperComputer.utils.deviceHepler.DeviceHelper;
|
||||||
|
import net.northking.cctp.upperComputer.utils.deviceHepler.ios.LinuxAndWindowsIosHandleHelper;
|
||||||
|
import net.northking.cctp.upperComputer.utils.deviceHepler.ios.MacIosHandleHelper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -21,7 +25,7 @@ public abstract class AbstractDebuggerService implements DebuggerService {
|
||||||
|
|
||||||
protected MobileProperty mobileProperty;
|
protected MobileProperty mobileProperty;
|
||||||
|
|
||||||
protected IosDeviceHandleHelper deviceHandleHelper;
|
protected DeviceHelper deviceHandleHelper;
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(AbstractDebuggerService.class);
|
private final Logger logger = LoggerFactory.getLogger(AbstractDebuggerService.class);
|
||||||
|
|
||||||
|
@ -43,10 +47,6 @@ public abstract class AbstractDebuggerService implements DebuggerService {
|
||||||
this.mobileProperty = mobileProperty;
|
this.mobileProperty = mobileProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAppInstalled(String deviceId, String appPackage) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeApp(String deviceId, String appPackage) {
|
public boolean removeApp(String deviceId, String appPackage) {
|
||||||
|
@ -134,4 +134,57 @@ public abstract class AbstractDebuggerService implements DebuggerService {
|
||||||
public boolean releaseAdbForwardPort(String deviceId) {
|
public boolean releaseAdbForwardPort(String deviceId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getScreenShot(DebuggerDeviceInfo info,int width,int height) {
|
||||||
|
File shotFile = deviceHandleHelper.getScreenShotFile(info.getDeviceId(),info.getX(),info.getY(),info.getLength(),info.getWidth(),info.getScreenLength(),info.getScreenWidth(),width,height);
|
||||||
|
String path = uploadScreenToServer(shotFile,info);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String uploadScreenToServer(File file, DebuggerDeviceInfo info){
|
||||||
|
String path = null;
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", "Bearer " + info.getUserToken());
|
||||||
|
path = HttpUtils.doUpload(mobileProperty.getServerAddr()+mobileProperty.getFileUploadAddr(), file,headers);
|
||||||
|
logger.info("上传截图完成:{}",path);
|
||||||
|
Map map = JSON.parseObject(path, Map.class);
|
||||||
|
if ((boolean) map.get("success")) {
|
||||||
|
path = (String) map.get("data");
|
||||||
|
}
|
||||||
|
} catch (ExecuteException e) {
|
||||||
|
logger.error("截图失败",e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("截图失败",e);
|
||||||
|
throw new ExecuteException("截取图片失败");
|
||||||
|
}finally {
|
||||||
|
// if (file.exists()) {
|
||||||
|
// boolean delete = file.delete();
|
||||||
|
// if (!delete) {
|
||||||
|
// logger.warn("临时文件【{}】删除失败",file.getAbsolutePath());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean cleanData(String deviceId, String packageName) {
|
||||||
|
return deviceHandleHelper.cleanData(deviceId,packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAppInstalled(String deviceId, String appPackage) {
|
||||||
|
return deviceHandleHelper.isAppInstalled(deviceId, appPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageVersion(String deviceId, String packageName) {
|
||||||
|
return deviceHandleHelper.getOldPackageCode(deviceId,packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean terminateApp(String deviceId, String appPackage) {
|
||||||
|
return deviceHandleHelper.terminateApp(deviceId,appPackage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package net.northking.cctp.upperComputer.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.appium.java_client.AppiumDriver;
|
||||||
|
import net.northking.cctp.upperComputer.automation.entity.ScreenInfo;
|
||||||
|
import net.northking.cctp.upperComputer.deviceManager.HarmonyDeviceManager;
|
||||||
|
import net.northking.cctp.upperComputer.deviceManager.screen.HarmonyScreenResponseThread;
|
||||||
|
import net.northking.cctp.upperComputer.deviceManager.thread.HarmonyProvider;
|
||||||
|
import net.northking.cctp.upperComputer.driver.harmony.HarmonyDevice;
|
||||||
|
import net.northking.cctp.upperComputer.entity.DebuggerDeviceInfo;
|
||||||
|
import net.northking.cctp.upperComputer.utils.deviceHepler.harmony.HarmonyHandlerHelper;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : yineng.huang
|
||||||
|
* @date : 2024/10/31 16:54
|
||||||
|
*/
|
||||||
|
@Service("harmonyService")
|
||||||
|
public class HarmonyDebuggerServiceImpl extends AbstractDebuggerService {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(HarmonyDebuggerServiceImpl.class);
|
||||||
|
|
||||||
|
public HarmonyDebuggerServiceImpl() {
|
||||||
|
this.deviceHandleHelper = new HarmonyHandlerHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getUiTree(String deviceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AppiumDriver<WebElement> getDriver(DebuggerDeviceInfo info) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean initApp(DebuggerDeviceInfo info) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getScreenShot(DebuggerDeviceInfo info) {
|
||||||
|
ScreenInfo screenInfo = HarmonyDeviceManager.getInstance().getScreenInfo(info.getDeviceId());
|
||||||
|
String path = getScreenShot(info, screenInfo.getWidth(), screenInfo.getHeight());
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyDriver(String deviceId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getScreenShotToBase64(DebuggerDeviceInfo info) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String shotAllScreen(DebuggerDeviceInfo info) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadShotAllScreen(DebuggerDeviceInfo info) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean startRecord(DebuggerDeviceInfo info) {
|
||||||
|
logger.info("收到设备【{}】在任务【{}】开启录屏的请求............",info.getDeviceId(),info.getTaskId());
|
||||||
|
HarmonyScreenResponseThread screenThread = HarmonyDeviceManager.getInstance().getScreenThread(info.getDeviceId());
|
||||||
|
if (null == screenThread) {
|
||||||
|
HarmonyProvider provider = HarmonyDeviceManager.getInstance().getCurrentDeviceProvider(info.getDeviceId());
|
||||||
|
if (null == provider) {
|
||||||
|
logger.error("当前设备【{}】不在线,无法开启录频",info.getDeviceId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
HarmonyDevice currentDevice = HarmonyDeviceManager.getInstance().getCurrentDevice(info.getDeviceId());
|
||||||
|
if (null == currentDevice) {
|
||||||
|
logger.error("当前设备【{}】不在线,无法开启录频",info.getDeviceId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
screenThread = new HarmonyScreenResponseThread(currentDevice);
|
||||||
|
HarmonyDeviceManager.getInstance().saveScreenThread(info.getDeviceId(), screenThread);
|
||||||
|
//开启手机端的屏幕
|
||||||
|
boolean success = provider.startCaptureScreenImageStream(0.5f, screenThread);
|
||||||
|
logger.info("开始拉取设备【{}】的屏幕,结果:{}",info.getDeviceId(),success);
|
||||||
|
if (!success) {
|
||||||
|
logger.error("拉取设备【{}】的屏幕失败",info.getDeviceId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String taskId = info.getTaskId();
|
||||||
|
String tenantId = info.getTenantId();
|
||||||
|
String resolution = info.getResolution();
|
||||||
|
String[] split = resolution.split("\\*");
|
||||||
|
int width = Integer.parseInt(split[0]);
|
||||||
|
int height = Integer.parseInt(split[1]);
|
||||||
|
int isBigger = height - width;
|
||||||
|
if (isBigger < 0) { //高比宽小,换一下
|
||||||
|
int temp = width;
|
||||||
|
width = height;
|
||||||
|
height = temp;
|
||||||
|
}
|
||||||
|
screenThread.startRecordScreen(tenantId, width, height,taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String endRecord(DebuggerDeviceInfo info) {
|
||||||
|
String videoUrl = null;
|
||||||
|
logger.info("收到设备【{}】在任务【{}】关闭录屏的请求............",info.getDeviceId(),info.getTaskId());
|
||||||
|
HarmonyScreenResponseThread screenThread = HarmonyDeviceManager.getInstance().getScreenThread(info.getDeviceId());
|
||||||
|
if (null != screenThread) {
|
||||||
|
String result = screenThread.stopRecord(info);
|
||||||
|
JSONObject jsonObject = JSON.parseObject(result, JSONObject.class);
|
||||||
|
videoUrl = jsonObject.getString("videoUrl");
|
||||||
|
} else {
|
||||||
|
logger.info("设备【{}】在任务【{}】录屏不存在............",info.getDeviceId(),info.getTaskId());
|
||||||
|
}
|
||||||
|
logger.info("设备【{}】在任务【{}】录屏保存的地址:{}............",info.getDeviceId(),info.getTaskId(),videoUrl);
|
||||||
|
return videoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCurrentMessage(String deviceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.appium.java_client.AppiumDriver;
|
import io.appium.java_client.AppiumDriver;
|
||||||
|
import net.northking.cctp.upperComputer.automation.entity.ScreenInfo;
|
||||||
import net.northking.cctp.upperComputer.config.MobileProperty;
|
import net.northking.cctp.upperComputer.config.MobileProperty;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.common.PyMobileDevice;
|
import net.northking.cctp.upperComputer.deviceManager.common.PyMobileDevice;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.screen.IosScreenResponseThread;
|
import net.northking.cctp.upperComputer.deviceManager.screen.IosScreenResponseThread;
|
||||||
|
@ -21,7 +22,7 @@ import net.northking.cctp.upperComputer.service.thread.IOSDeviceInfoByPackageThr
|
||||||
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
||||||
import net.northking.cctp.upperComputer.utils.HttpUtils;
|
import net.northking.cctp.upperComputer.utils.HttpUtils;
|
||||||
import net.northking.cctp.upperComputer.utils.ScreenShotUtils;
|
import net.northking.cctp.upperComputer.utils.ScreenShotUtils;
|
||||||
import net.northking.cctp.upperComputer.utils.ios.MacIosHandleHelper;
|
import net.northking.cctp.upperComputer.utils.deviceHepler.ios.MacIosHandleHelper;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -102,7 +103,8 @@ public class IosDebuggerServiceImpl extends AbstractDebuggerService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getScreenShot(DebuggerDeviceInfo info) {
|
public String getScreenShot(DebuggerDeviceInfo info) {
|
||||||
File shotFile = deviceHandleHelper.getScreenShotFile(info.getDeviceId(),info.getX(),info.getY(),info.getLength(),info.getWidth(),info.getScreenLength(),info.getScreenWidth());
|
ScreenInfo screenInfo = IOSDeviceManager.getInstance().getScreenInfo(info.getDeviceId());
|
||||||
|
File shotFile = deviceHandleHelper.getScreenShotFile(info.getDeviceId(),info.getX(),info.getY(),info.getLength(),info.getWidth(),info.getScreenLength(),info.getScreenWidth(),screenInfo.getWidth(), screenInfo.getHeight());
|
||||||
String path = null;
|
String path = null;
|
||||||
try {
|
try {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
@ -155,7 +157,8 @@ public class IosDebuggerServiceImpl extends AbstractDebuggerService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getScreenShotToBase64(DebuggerDeviceInfo info) {
|
public String getScreenShotToBase64(DebuggerDeviceInfo info) {
|
||||||
File screenShotFile = deviceHandleHelper.getScreenShotFile(info.getDeviceId(),info.getX(),info.getY(),info.getLength(),info.getWidth(),info.getScreenLength(),info.getScreenWidth());
|
ScreenInfo screenInfo = IOSDeviceManager.getInstance().getScreenInfo(info.getDeviceId());
|
||||||
|
File screenShotFile = deviceHandleHelper.getScreenShotFile(info.getDeviceId(),info.getX(),info.getY(),info.getLength(),info.getWidth(),info.getScreenLength(),info.getScreenWidth(),screenInfo.getWidth(), screenInfo.getHeight());
|
||||||
String imgBase64 = null;
|
String imgBase64 = null;
|
||||||
try {
|
try {
|
||||||
imgBase64 = Base64.encode(screenShotFile);
|
imgBase64 = Base64.encode(screenShotFile);
|
||||||
|
|
|
@ -587,12 +587,12 @@ public class CommonTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>在控件中输入文本</p>
|
* * <p>在控件中输入文本</p>
|
||||||
*
|
* *
|
||||||
* @param text 输入的文本
|
* * @param text 输入的文本
|
||||||
* @param cleanStr 是否清空文本框0-否,1-是
|
* * @param cleanStr 是否清空文本框0-否,1-是
|
||||||
* @param deviceDriver 设备连接驱动
|
* * @param deviceDriver 设备连接驱动
|
||||||
* @param targets 定位控件参数
|
* * @param targets 定位控件参数
|
||||||
* @param waitTimeout 超时时间
|
* @param waitTimeout 超时时间
|
||||||
* @param waitStatusStr 是否等待屏幕稳定
|
* @param waitStatusStr 是否等待屏幕稳定
|
||||||
* @param swipe 是否滑屏查找控件0-否,up-上滑,down-下滑,left-左滑,right-右滑
|
* @param swipe 是否滑屏查找控件0-否,up-上滑,down-下滑,left-左滑,right-右滑
|
||||||
|
@ -600,8 +600,8 @@ public class CommonTools {
|
||||||
* @param preExecuteWait 执行前等待
|
* @param preExecuteWait 执行前等待
|
||||||
* @param sufExecuteWait 执行后等待
|
* @param sufExecuteWait 执行后等待
|
||||||
* @return
|
* @return
|
||||||
*/
|
* */
|
||||||
/*@Keyword(alias = "输入文本", category = "0", attributes = "45", commonlyUse = true)
|
@Keyword(alias = "输入文本", category = "0", attributes = "45", commonlyUse = true)
|
||||||
@Return(name = "result", comment = "输入的结果", type = DataType.BOOLEAN)
|
@Return(name = "result", comment = "输入的结果", type = DataType.BOOLEAN)
|
||||||
public boolean inputText(IExecuteContext context,
|
public boolean inputText(IExecuteContext context,
|
||||||
@Argument(name = "text", scope = ParamScope.VARIABLES, comment = "输入的文本", type = DataType.STRING) String text,
|
@Argument(name = "text", scope = ParamScope.VARIABLES, comment = "输入的文本", type = DataType.STRING) String text,
|
||||||
|
@ -654,7 +654,7 @@ public class CommonTools {
|
||||||
throw new ExecuteException("用户取消,执行失败");
|
throw new ExecuteException("用户取消,执行失败");
|
||||||
}
|
}
|
||||||
return aBoolean;
|
return aBoolean;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>在控件中输入文本</p>
|
* <p>在控件中输入文本</p>
|
||||||
|
|
Loading…
Reference in New Issue