Skip to content

Commit

Permalink
Merge pull request #229 from SonicCloudOrg/dev
Browse files Browse the repository at this point in the history
beta
  • Loading branch information
ZhouYixun authored Jun 22, 2022
2 parents ae72307 + 2d88158 commit ca32611
Show file tree
Hide file tree
Showing 29 changed files with 651 additions and 709 deletions.
21 changes: 6 additions & 15 deletions config/application-sonic-agent.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
sonic:
agent:
# 替换为部署Agent机器的ipv4
host: 192.168.1.2
host: 192.168.1.6
# 替换为Agent服务的端口,可以自行更改
port: 7777
# 替换为前端新增Agent生成的key
key: 29002272-4659-4808-a804-08ce3388b136
cabinet:
# 是否使用Sonic机柜,可以前往https://sonic-cloud.gitee.io/#/Cabinet了解更多
enable: false
# 机柜层数
storey: 1
# 机柜key值
key: e33cd65c-a40e-431f-9e65-4a91bac6f487
server:
# 改成server的SERVER_HOST
host: 192.168.1.2
# 改成server的SONIC_GATEWAY_PORT(一般不变)
port: 8094
# 改成server的SONIC_TRANSPORT_PORT(一般不变)
transport-port: 8095
host: 192.168.1.6
# 改成server的SERVER_PORT
port: 3000

modules:
android:
Expand All @@ -29,9 +20,9 @@ modules:
use-adbkit: true
ios:
# 如果不需要连接iOS设备,请将true改为false。开启的windows用户请确保本机已安装iTunes
enable: false
enable: true
# 替换为你自己使用的wda的bundleId,如果没有.xctrunner后缀会自动补全,建议使用公司的开发者证书
wda-bundle-id: com.facebook.WebDriverAgentRunner.xctrunner
wda-bundle-id: com.sonic.WebDriverAgentRunner.xctrunner
appium:
# 是否开启Appium功能
enable: true
Expand Down
Binary file modified plugins/sonic-android-apk.apk
Binary file not shown.
Binary file modified plugins/sonic-ios-bridge
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.cloud.sonic</groupId>
<artifactId>sonic-agent</artifactId>
<version>1.4.1-alpha1</version>
<version>1.4.1-beta</version>
<packaging>jar</packaging>

<properties>
Expand Down
13 changes: 2 additions & 11 deletions src/main/docker/config/application-sonic-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@ sonic:
port: ${AGENT_PORT:7777}
# 替换为前端新增Agent生成的key
key: ${AGENT_KEY:235a35fd-5d0d-4533-905d-30d32902a12b}
cabinet:
# 是否使用Sonic机柜,可以前往https://sonic-cloud.gitee.io/#/Cabinet了解更多
enable: ${CABINET_ENABLE:false}
# 机柜层数
storey: ${CABINET_STOREY:1}
# 机柜key值
key: ${CABINET_KEY:e33cd65c-a40e-431f-9e65-4a91bac6f487}
server:
# 改成server的SERVER_HOST
host: ${SERVER_HOST:192.168.1.1}
# 改成server的SONIC_GATEWAY_PORT(一般不变)
port: ${SONIC_GATEWAY_PORT:8094}
# 改成server的SONIC_TRANSPORT_PORT(一般不变)
transport-port: ${SONIC_TRANSPORT_PORT:8095}
# 改成server的SERVER_PORT
port: ${SERVER_PORT:3000}

modules:
android:
Expand Down
9 changes: 2 additions & 7 deletions src/main/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
version: '3'
services:
sonic-agent:
image: "registry.cn-hangzhou.aliyuncs.com/sonic-cloud/sonic-agent-linux:v1.4.1-alpha1"
image: "registry.cn-hangzhou.aliyuncs.com/sonic-cloud/sonic-agent-linux:v1.4.1-beta"
environment:
# 对应server的env配置,注意防火墙关闭对应端口
- SERVER_HOST=192.168.1.1
- SONIC_GATEWAY_PORT=8094
- SONIC_TRANSPORT_PORT=8095
- SERVER_PORT=3000
# 替换为部署Agent机器的ipv4
- AGENT_HOST=192.168.1.1
# 替换为Agent服务的端口,可以自行更改
- AGENT_PORT=7777
# 替换为前端新增Agent生成的key
- AGENT_KEY=29002272-4659-4808-a804-08ce3388b136
# 是否使用Sonic机柜,可以前往https://sonic-cloud.gitee.io/#/Cabinet了解更多
- CABINET_ENABLE=true
- CABINET_STOREY=1
- CABINET_KEY=e33cd65c-a40e-431f-9e65-4a91bac6f487
# 是否使用安卓模块
- ANDROID_ENABLE=true
# 是否开启远程adb调试功能
Expand Down
9 changes: 2 additions & 7 deletions src/main/docker/docker-compose2.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
version: '3'
services:
sonic-agent:
image: "sonicorg/sonic-agent-linux:v1.4.1-alpha1"
image: "sonicorg/sonic-agent-linux:v1.4.1-beta"
environment:
# 对应server的env配置,注意防火墙关闭对应端口
- SERVER_HOST=192.168.1.1
- SONIC_GATEWAY_PORT=8094
- SONIC_TRANSPORT_PORT=8095
- SERVER_PORT=3000
# 替换为部署Agent机器的ipv4
- AGENT_HOST=192.168.1.1
# 替换为Agent服务的端口,可以自行更改
- AGENT_PORT=7777
# 替换为前端新增Agent生成的key
- AGENT_KEY=29002272-4659-4808-a804-08ce3388b136
# 是否使用Sonic机柜,可以前往https://sonic-cloud.gitee.io/#/Cabinet了解更多
- CABINET_ENABLE=true
- CABINET_STOREY=1
- CABINET_KEY=e33cd65c-a40e-431f-9e65-4a91bac6f487
# 是否使用安卓模块
- ANDROID_ENABLE=true
# 是否开启远程adb调试功能
Expand Down
78 changes: 77 additions & 1 deletion src/main/java/org/cloud/sonic/agent/automation/AndroidStepHandler.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.jsoup.nodes.Document;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;
Expand Down Expand Up @@ -768,6 +769,18 @@ public void sendKeys(HandleDes handleDes, String des, String selector, String pa
}
}

public void sendKeysByActions(HandleDes handleDes, String des, String selector, String pathValue, String keys) {
keys = TextHandler.replaceTrans(keys, globalParams);
handleDes.setStepDes("对" + des + "输入内容");
handleDes.setDetail("对" + selector + ": " + pathValue + " 输入: " + keys);
try {
// 修复flutter应用输入框无法sendKey的问题
new Actions(androidDriver).sendKeys(findEle(selector, pathValue),keys).perform();
} catch (Exception e) {
handleDes.setE(e);
}
}

public void getTextAndAssert(HandleDes handleDes, String des, String selector, String pathValue, String expect) {
handleDes.setStepDes("获取" + des + "文本");
handleDes.setDetail("获取" + selector + ":" + pathValue + "文本");
Expand Down Expand Up @@ -935,6 +948,34 @@ public void getTitle(HandleDes handleDes, String expect) {
}
}

public void getActivity(HandleDes handleDes, String expect) {
expect = TextHandler.replaceTrans(expect, globalParams);
String currentActivity = getCurrentActivity();
handleDes.setStepDes("验证当前Activity");
handleDes.setDetail("activity:" + currentActivity + ",期望值:" + expect);
try {
assertEquals(currentActivity, expect);
} catch (AssertionError e) {
handleDes.setE(e);
}
}

public void getElementAttr(HandleDes handleDes, String des, String selector, String pathValue, String attr, String expect) {
handleDes.setStepDes("验证控件 " + des + " 属性");
handleDes.setDetail("属性:" + attr + ",期望值:" + expect);
try {
String attrValue = findEle(selector, pathValue).getAttribute(attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
} catch (AssertionError e) {
handleDes.setE(e);
}
} catch (Exception e) {
handleDes.setE(e);
}
}

public void clickByImg(HandleDes handleDes, String des, String pathValue) throws Exception {
handleDes.setStepDes("点击图片" + des);
handleDes.setDetail(pathValue);
Expand Down Expand Up @@ -1423,14 +1464,17 @@ public WebElement findEle(String selector, String pathValue) {
case "id":
we = androidDriver.findElementById(pathValue);
break;
case "accessibilityId":
we = androidDriver.findElementByAccessibilityId(pathValue);
break;
case "name":
we = androidDriver.findElementByName(pathValue);
break;
case "xpath":
we = androidDriver.findElementByXPath(pathValue);
break;
case "cssSelector":
we = androidDriver.findElementByCssSelector(pathValue);
we = androidDriver.findElement(By.cssSelector(pathValue));
break;
case "className":
we = androidDriver.findElementByClassName(pathValue);
Expand All @@ -1444,13 +1488,34 @@ public WebElement findEle(String selector, String pathValue) {
case "partialLinkText":
we = androidDriver.findElementByPartialLinkText(pathValue);
break;
case "cssSelectorAndText":
we = getWebElementByCssAndText(pathValue);
break;
default:
log.sendStepLog(StepType.ERROR, "查找控件元素失败", "这个控件元素类型: " + selector + " 不存在!!!");
break;
}
return we;
}

private WebElement getWebElementByCssAndText(String pathValue) {
// 新增H5页面通过className+text定位控件元素
// value格式:van-button--default,购物车
WebElement element = null;
List<String> values = new ArrayList<>(Arrays.asList(pathValue.split(",")));
if(values.size() >= 2) {
// findElementsByClassName在高版本的chromedriver有bug,只能用cssSelector才能找到控件元素
List<WebElement> els = androidDriver.findElements(By.cssSelector(values.get(0)));
for(WebElement el: els) {
if(el.getText().equals(values.get(1))) {
element = el;
break;
}
}
}
return element;
}

public void stepHold(HandleDes handleDes, int time) {
handleDes.setStepDes("设置全局步骤间隔");
handleDes.setDetail("间隔" + time + " ms");
Expand Down Expand Up @@ -1487,10 +1552,21 @@ public void runStep(JSONObject stepJSON, HandleDes handleDes) throws Throwable {
case "getTitle":
getTitle(handleDes, step.getString("content"));
break;
case "getActivity":
getActivity(handleDes, step.getString("content"));
break;
case "getElementAttr":
getElementAttr(handleDes, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"), step.getString("content"));
break;
case "sendKeys":
sendKeys(handleDes, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("content"));
break;
case "sendKeysByActions":
sendKeysByActions(handleDes, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("content"));
break;
case "getText":
getTextAndAssert(handleDes, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("content"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public void startIOSDriver(String udId, int wdaPort) throws InterruptedException
iosDriver = new IOSDriver(AppiumServer.serviceMap.get(udId).getUrl(), desiredCapabilities);
iosDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
iosDriver.setSetting(Setting.MJPEG_SERVER_FRAMERATE, 50);
iosDriver.setSetting(Setting.MJPEG_SCALING_FACTOR, 50);
iosDriver.setSetting(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY, 10);
iosDriver.setSetting("snapshotMaxDepth", 30);
log.sendStepLog(StepType.PASS, "连接设备驱动成功", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.android.ddmlib.*;
import org.cloud.sonic.agent.common.maps.GlobalProcessMap;
import org.cloud.sonic.agent.tests.android.AndroidBatteryThread;
import org.cloud.sonic.agent.tools.BytesTool;
import org.cloud.sonic.agent.tools.ScheduleTool;
import org.cloud.sonic.agent.tools.file.DownloadTool;
import org.cloud.sonic.agent.tools.file.UploadTools;
Expand Down Expand Up @@ -416,6 +417,13 @@ public static int getScreen(IDevice iDevice) {
}
}

public static int getOrientation(IDevice iDevice) {
String inputs = executeCommand(iDevice, "dumpsys input");
String orientationS = inputs.substring(inputs.indexOf("SurfaceOrientation")).trim();
int o = BytesTool.getInt(orientationS.substring(20, orientationS.indexOf("\n")));
return o;
}

public static void pushYadb(IDevice iDevice) {
executeCommand(iDevice, "rm -rf /data/local/tmp/yadb");
File yadbLocalFile = new File("plugins" + File.separator + "yadb");
Expand Down Expand Up @@ -450,7 +458,7 @@ public static void pushToCamera(IDevice iDevice, String url) {
}

public static void searchDevice(IDevice iDevice) {
executeCommand(iDevice, "am start -n org.cloud.sonic.android/.SearchActivity");
executeCommand(iDevice, "am start -n org.cloud.sonic.android/.plugin.activityPlugin.SearchActivity");
}

public static void controlBattery(IDevice iDevice, int type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void deviceConnected(IDevice device) {
logger.info("Android device: " + device.getSerialNumber() + " ONLINE!");
AndroidDeviceManagerMap.getMap().remove(device.getSerialNumber());
DevicesBatteryMap.getTempMap().remove(device.getSerialNumber());
DevicesBatteryMap.getGearMap().remove(device.getSerialNumber());
send(device);
}

Expand All @@ -72,7 +71,6 @@ public void deviceDisconnected(IDevice device) {
logger.info("Android device: " + device.getSerialNumber() + " OFFLINE!");
AndroidDeviceManagerMap.getMap().remove(device.getSerialNumber());
DevicesBatteryMap.getTempMap().remove(device.getSerialNumber());
DevicesBatteryMap.getGearMap().remove(device.getSerialNumber());
send(device);
}

Expand Down
Loading

0 comments on commit ca32611

Please sign in to comment.