Skip to content

Commit

Permalink
Merge pull request #280 from SonicCloudOrg/feat/2.0.0-release
Browse files Browse the repository at this point in the history
feat 2.0.0 release
  • Loading branch information
ZhouYixun authored Nov 4, 2022
2 parents fd4c874 + f159637 commit 1dfa29f
Show file tree
Hide file tree
Showing 9 changed files with 482 additions and 64 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>io.github.soniccloudorg</groupId>
<artifactId>sonic-driver-core</artifactId>
<version>1.1.9</version>
<version>1.1.10</version>
</dependency>
<!-- 压缩图片 -->
<dependency>
Expand Down Expand Up @@ -98,7 +98,7 @@
<dependency>
<groupId>io.github.soniccloudorg</groupId>
<artifactId>sonic-vision-core</artifactId>
<version>1.0.5-${platform}</version>
<version>1.0.6-${platform}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.cloud.sonic.agent.automation;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.android.ddmlib.IDevice;
Expand Down Expand Up @@ -152,6 +153,7 @@ public void closeAndroidDriver() {
}
if (pocoDriver != null) {
pocoDriver.closeDriver();
AndroidDeviceBridgeTool.removeForward(iDevice, pocoPort, targetPort);
pocoDriver = null;
}
if (androidDriver != null) {
Expand Down Expand Up @@ -960,8 +962,8 @@ public void runMonkey(HandleDes handleDes, JSONObject content, List<JSONObject>
boolean isOpenActivityListener = false;
boolean isOpenNetworkListener = false;
if (!options.isEmpty()) {
for (int i = options.size() - 1; i >= 0; i--) {
JSONObject jsonOption = (JSONObject) options.get(i);
for (Object j : options) {
JSONObject jsonOption = JSON.parseObject(j.toString());
if (jsonOption.getString("name").equals("sleepTime")) {
sleepTime = jsonOption.getInteger("value");
}
Expand Down Expand Up @@ -992,7 +994,6 @@ public void runMonkey(HandleDes handleDes, JSONObject content, List<JSONObject>
if (jsonOption.getString("name").equals("isOpenNetworkListener")) {
isOpenNetworkListener = jsonOption.getBoolean("value");
}
options.remove(options.get(i));
}
}
int finalSleepTime = sleepTime;
Expand Down Expand Up @@ -1104,7 +1105,6 @@ public void runMonkey(HandleDes handleDes, JSONObject content, List<JSONObject>
h5Time = 0;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Expand Down Expand Up @@ -1224,27 +1224,59 @@ public void startPocoDriver(HandleDes handleDes, String engine, int port) {
pocoDriver = new PocoDriver(PocoEngine.valueOf(engine), pocoPort);
}

private int intervalInit = 3000;
private int retryInit = 3;

public void setDefaultFindPocoElementInterval(HandleDes handleDes, Integer retry, Integer interval) {
handleDes.setStepDes("Set Global Find Poco Element Interval");
handleDes.setDetail(String.format("Retry count: %d, retry interval: %d ms", retry, interval));
if (retry != null) {
retryInit = retry;
}
if (interval != null) {
intervalInit = interval;
}
}

public PocoElement findPocoEle(String selector, String pathValue) throws Throwable {
PocoElement pocoElement = null;
pathValue = TextHandler.replaceTrans(pathValue, globalParams);
pocoDriver.getPageSourceForXmlElement();
try {
switch (selector) {
case "poco":
pocoElement = pocoDriver.findElement(PocoSelector.POCO, pathValue);
break;
case "xpath":
pocoElement = pocoDriver.findElement(PocoSelector.XPATH, pathValue);
break;
case "cssSelector":
pocoElement = pocoDriver.findElement(PocoSelector.CSS_SELECTOR, pathValue);
break;
default:
log.sendStepLog(StepType.ERROR, "查找控件元素失败", "这个控件元素类型: " + selector + " 不存在!!!");
int wait = 0;
String errMsg = "";
while (wait < retryInit) {
wait++;
pocoDriver.getPageSourceForXmlElement();
try {
switch (selector) {
case "poco":
pocoElement = pocoDriver.findElement(PocoSelector.POCO, pathValue);
break;
case "xpath":
pocoElement = pocoDriver.findElement(PocoSelector.XPATH, pathValue);
break;
case "cssSelector":
pocoElement = pocoDriver.findElement(PocoSelector.CSS_SELECTOR, pathValue);
break;
default:
log.sendStepLog(StepType.ERROR, "查找控件元素失败", "这个控件元素类型: " + selector + " 不存在!!!");
break;
}
if (pocoElement != null) {
break;
}
} catch (Throwable e) {
errMsg = e.getMessage();
}
if (wait < retryInit) {
try {
Thread.sleep(intervalInit);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Throwable e) {
throw e;
}
if (pocoElement == null) {
throw new SonicRespException(errMsg);
}
return pocoElement;
}
Expand Down Expand Up @@ -1457,7 +1489,7 @@ public AndroidElement findEle(String selector, String pathValue) throws SonicRes
}

public void setFindElementInterval(HandleDes handleDes, int retry, int interval) {
handleDes.setStepDes("Set Global Find Element Interval");
handleDes.setStepDes("Set Global Find Android Element Interval");
handleDes.setDetail(String.format("Retry count: %d, retry interval: %d ms", retry, interval));
androidDriver.setDefaultFindElementInterval(retry, interval);
}
Expand Down Expand Up @@ -1801,6 +1833,9 @@ public void runStep(JSONObject stepJSON, HandleDes handleDes) throws Throwable {
case "runScript":
runScript(handleDes, step.getString("content"), step.getString("text"));
break;
case "setDefaultFindPocoElementInterval":
setDefaultFindPocoElementInterval(handleDes, step.getInteger("content"), step.getInteger("text"));
break;
case "startPocoDriver":
startPocoDriver(handleDes, step.getString("content"), step.getInteger("text"));
break;
Expand Down
Loading

0 comments on commit 1dfa29f

Please sign in to comment.