diff --git a/README.md b/README.md
index 2cbecb5..8c0f686 100644
--- a/README.md
+++ b/README.md
@@ -58,14 +58,14 @@ sonic-driver-core can be separated from appium and interact directly with webdri
io.github.soniccloudorg
sonic-driver-core
- 1.0.5
+ 1.0.6
```
#### Gradle
```
-implementation 'io.github.soniccloudorg:sonic-driver-core:1.0.5'
+implementation 'io.github.soniccloudorg:sonic-driver-core:1.0.6'
```
### Code
diff --git a/README_CN.md b/README_CN.md
index 7ab1d99..2a238d9 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -53,12 +53,12 @@ sonic-driver-core可以脱离Appium,直接与WebDriverAgent或UIautomator2交
io.github.soniccloudorg
sonic-driver-core
- 1.0.5
+ 1.0.6
```
#### Gradle
```
-implementation 'io.github.soniccloudorg:sonic-driver-core:1.0.5'
+implementation 'io.github.soniccloudorg:sonic-driver-core:1.0.6'
```
### 代码
diff --git a/pom.xml b/pom.xml
index a3fc125..11170a3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.github.soniccloudorg
sonic-driver-core
- 1.0.5
+ 1.0.6
sonic-driver-core
The Sonic Project UIAutomation Driver Core for Android, iOS, Windows, Mac and so on.
diff --git a/src/main/java/org/cloud/sonic/core/ios/IOSDriver.java b/src/main/java/org/cloud/sonic/core/ios/IOSDriver.java
index b799a3b..0acba52 100644
--- a/src/main/java/org/cloud/sonic/core/ios/IOSDriver.java
+++ b/src/main/java/org/cloud/sonic/core/ios/IOSDriver.java
@@ -24,6 +24,8 @@
import org.cloud.sonic.core.ios.service.impl.WdaClientImpl;
import org.cloud.sonic.core.tool.SonicRespException;
+import java.util.List;
+
/**
* @author Eason
* ios driver
@@ -459,4 +461,118 @@ public WebElement findElement(XCUIElementType xcuiElementType, Integer retry, In
public WebElement findElement(String selector, String value, Integer retry, Integer interval) throws SonicRespException {
return wdaClient.findElement(selector, value, retry, interval);
}
+
+ /**
+ * find element list in device.
+ *
+ * @param iosSelector
+ * @param value
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(IOSSelector iosSelector, String value) throws SonicRespException {
+ return findElementList(iosSelector, value, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param xcuiElementType
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(XCUIElementType xcuiElementType) throws SonicRespException {
+ return findElementList(xcuiElementType, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param selector
+ * @param value
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(String selector, String value) throws SonicRespException {
+ return findElementList(selector, value, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param iosSelector
+ * @param value
+ * @param retry
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(IOSSelector iosSelector, String value, Integer retry) throws SonicRespException {
+ return findElementList(iosSelector, value, retry, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param xcuiElementType
+ * @param retry
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(XCUIElementType xcuiElementType, Integer retry) throws SonicRespException {
+ return findElementList(xcuiElementType, retry, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param selector
+ * @param value
+ * @param retry
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(String selector, String value, Integer retry) throws SonicRespException {
+ return findElementList(selector, value, retry, null);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param iosSelector
+ * @param value
+ * @param retry
+ * @param interval
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(IOSSelector iosSelector, String value, Integer retry, Integer interval) throws SonicRespException {
+ return findElementList(iosSelector.getSelector(), value, retry, interval);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param xcuiElementType
+ * @param retry
+ * @param interval
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(XCUIElementType xcuiElementType, Integer retry, Integer interval) throws SonicRespException {
+ return findElementList(IOSSelector.CLASS_NAME.getSelector(), xcuiElementType.getType(), retry, interval);
+ }
+
+ /**
+ * find element list in device.
+ *
+ * @param selector
+ * @param value
+ * @param retry
+ * @param interval
+ * @return
+ * @throws SonicRespException
+ */
+ public List findElementList(String selector, String value, Integer retry, Integer interval) throws SonicRespException {
+ return wdaClient.findElementList(selector, value, retry, interval);
+ }
}
diff --git a/src/main/java/org/cloud/sonic/core/ios/models/IOSRect.java b/src/main/java/org/cloud/sonic/core/ios/models/IOSRect.java
index 5ace0e2..a0999e3 100644
--- a/src/main/java/org/cloud/sonic/core/ios/models/IOSRect.java
+++ b/src/main/java/org/cloud/sonic/core/ios/models/IOSRect.java
@@ -18,8 +18,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.ToString;
@Getter
+@ToString
@AllArgsConstructor
public class IOSRect {
private int x;
diff --git a/src/main/java/org/cloud/sonic/core/ios/models/SessionInfo.java b/src/main/java/org/cloud/sonic/core/ios/models/SessionInfo.java
index 5899430..ce8d1c6 100644
--- a/src/main/java/org/cloud/sonic/core/ios/models/SessionInfo.java
+++ b/src/main/java/org/cloud/sonic/core/ios/models/SessionInfo.java
@@ -18,8 +18,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.ToString;
@Getter
+@ToString
@AllArgsConstructor
public class SessionInfo {
private String sessionId;
diff --git a/src/main/java/org/cloud/sonic/core/ios/service/WdaClient.java b/src/main/java/org/cloud/sonic/core/ios/service/WdaClient.java
index f6203cc..3e6995e 100644
--- a/src/main/java/org/cloud/sonic/core/ios/service/WdaClient.java
+++ b/src/main/java/org/cloud/sonic/core/ios/service/WdaClient.java
@@ -21,6 +21,8 @@
import org.cloud.sonic.core.ios.models.TouchActions;
import org.cloud.sonic.core.tool.SonicRespException;
+import java.util.List;
+
/**
* @author Eason
* wda client interface
@@ -83,4 +85,7 @@ public interface WdaClient {
//element handler.
WebElement findElement(String selector, String value, Integer retry, Integer interval) throws SonicRespException;
+
+ //element handler.
+ List findElementList(String selector, String value, Integer retry, Integer interval) throws SonicRespException;
}
diff --git a/src/main/java/org/cloud/sonic/core/ios/service/impl/WdaClientImpl.java b/src/main/java/org/cloud/sonic/core/ios/service/impl/WdaClientImpl.java
index de56416..a4bbb56 100644
--- a/src/main/java/org/cloud/sonic/core/ios/service/impl/WdaClientImpl.java
+++ b/src/main/java/org/cloud/sonic/core/ios/service/impl/WdaClientImpl.java
@@ -30,6 +30,7 @@
import org.cloud.sonic.core.tool.SonicRespException;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
@@ -371,4 +372,50 @@ public WebElement findElement(String selector, String value, Integer retry, Inte
}
return webElement;
}
+
+ @Override
+ public List findElementList(String selector, String value, Integer retry, Integer interval) throws SonicRespException {
+ List webElementList = new ArrayList<>();
+ int wait = 0;
+ int intervalInit = (interval == null ? FIND_ELEMENT_INTERVAL : interval);
+ int retryInit = (retry == null ? FIND_ELEMENT_RETRY : retry);
+ String errMsg = "";
+ while (wait < retryInit) {
+ wait++;
+ checkSessionId();
+ JSONObject data = new JSONObject();
+ data.put("using", selector);
+ data.put("value", value);
+ BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/elements")
+ .body(data.toJSONString()));
+ if (b.getErr() == null) {
+ log.info("find elements successful.");
+ List ids = JSON.parseObject(b.getValue().toString(), ArrayList.class);
+ for (JSONObject ele : ids) {
+ String id = parseElementId(ele);
+ if (id.length() > 0) {
+ webElementList.add(new WebElementImpl(id, this));
+ } else {
+ log.error("parse element id {} failed.", ele);
+ continue;
+ }
+ }
+ break;
+ } else {
+ log.error("elements not found. retried {} times, retry in {} ms.", wait, intervalInit);
+ errMsg = b.getErr().getMessage();
+ }
+ if (wait < retryInit) {
+ try {
+ Thread.sleep(intervalInit);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (webElementList.size() == 0) {
+ throw new SonicRespException(errMsg);
+ }
+ return webElementList;
+ }
}
diff --git a/src/test/java/org/cloud/sonic/core/ios/IOSDriverTest.java b/src/test/java/org/cloud/sonic/core/ios/IOSDriverTest.java
index f5e48e9..0f5e25c 100644
--- a/src/test/java/org/cloud/sonic/core/ios/IOSDriverTest.java
+++ b/src/test/java/org/cloud/sonic/core/ios/IOSDriverTest.java
@@ -233,6 +233,13 @@ public void testFindElement() throws SonicRespException, InterruptedException {
iosDriver.pressButton(SystemButton.HOME);
}
+ @Test
+ public void testFindElementList() throws SonicRespException {
+ int eleSize = iosDriver.findElementList(XCUIElementType.WINDOW).size();
+ Assert.assertEquals(eleSize,iosDriver.findElementList("class name","XCUIElementTypeWindow").size());
+ Assert.assertEquals(eleSize,iosDriver.findElementList(IOSSelector.CLASS_NAME,"XCUIElementTypeWindow").size());
+ }
+
@AfterClass
public static void after() throws SonicRespException {
iosDriver.closeDriver();