Skip to content

Commit

Permalink
add BaseElement interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Dec 24, 2022
1 parent 1bf5b1b commit 8911237
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package org.cloud.sonic.driver.android.service;

import org.cloud.sonic.driver.common.models.BaseElement;
import org.cloud.sonic.driver.common.tool.SonicRespException;
import org.cloud.sonic.driver.common.models.ElementRect;

/**
* @author Eason
* web element interface
*/
public interface AndroidElement {
public interface AndroidElement extends BaseElement {

void click() throws SonicRespException;

Expand All @@ -35,9 +36,5 @@ public interface AndroidElement {

String getText() throws SonicRespException;

String getAttribute(String name) throws SonicRespException;

ElementRect getRect() throws SonicRespException;

byte[] screenshot() throws SonicRespException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public String getAttribute(String name) throws SonicRespException {
}
}

@Override
public String getUniquelyIdentifies() throws SonicRespException {
return id;
}

@Override
public ElementRect getRect() throws SonicRespException {
uiaClient.checkSessionId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cloud.sonic.driver.common.models;

import org.cloud.sonic.driver.common.tool.SonicRespException;

public interface BaseElement {
ElementRect getRect() throws SonicRespException;
String getAttribute(String name) throws SonicRespException;
// the xpath or id or csspath...
String getUniquelyIdentifies() throws SonicRespException;

// List<BaseElement> getChildren() throws SonicRespException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package org.cloud.sonic.driver.ios.service;

import org.cloud.sonic.driver.common.models.BaseElement;
import org.cloud.sonic.driver.common.models.ElementRect;
import org.cloud.sonic.driver.common.tool.SonicRespException;

/**
* @author Eason
* web element interface
*/
public interface IOSElement {
public interface IOSElement extends BaseElement {

void click() throws SonicRespException;

Expand All @@ -35,7 +36,5 @@ public interface IOSElement {

String getText() throws SonicRespException;

ElementRect getRect() throws SonicRespException;

byte[] screenshot() throws SonicRespException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void sendKeys(String text, int frequency) throws SonicRespException {
data.put("frequency", frequency);
BaseResp b = wdaClient.getRespHandler().getResp(
HttpUtil.createPost(wdaClient.getRemoteUrl() + "/session/"
+ wdaClient.getSessionId() + "/element/" + id + "/value")
+ wdaClient.getSessionId() + "/element/" + id + "/value")
.body(data.toJSONString()), 60000);
if (b.getErr() == null) {
logger.info("send key to %s.", id);
Expand Down Expand Up @@ -121,6 +121,21 @@ public ElementRect getRect() throws SonicRespException {
}
}

@Override
public String getAttribute(String name) throws SonicRespException {
wdaClient.checkSessionId();
BaseResp b = wdaClient.getRespHandler().getResp(
HttpUtil.createGet(wdaClient.getRemoteUrl() + "/session/"
+ wdaClient.getSessionId() + "/element/" + id + "/attribute/" + name), 60000);

throw new SonicRespException("ios not implemented getAttribute");
}

@Override
public String getUniquelyIdentifies() throws SonicRespException {
return id;
}

@Override
public byte[] screenshot() throws SonicRespException {
wdaClient.checkSessionId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import org.cloud.sonic.driver.common.models.BaseElement;
import org.cloud.sonic.driver.common.models.ElementRect;
import org.cloud.sonic.driver.common.tool.SonicRespException;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

Expand All @@ -29,7 +32,7 @@
@Getter
@ToString
@AllArgsConstructor
public class PocoElement {
public class PocoElement implements BaseElement {
public String currentNodeSelector = "Root";
private Payload payload;
private List<PocoElement> children;
Expand All @@ -38,6 +41,25 @@ public class PocoElement {

private long version;

@Override
// the poco given pos is a point where the origin of the coordinates will change with
// the rotation of the screen. The function and others are not uniform, so the implementation
// is not considered, you can get the pos point through the payload, and then convert it at
// the application layer
public ElementRect getRect() throws SonicRespException {
throw new SonicRespException("poco element unrealized");
}

@Override
public String getAttribute(String name) throws SonicRespException {
return currentNodeXmlElement.attr(name);
}

@Override
public String getUniquelyIdentifies() throws SonicRespException {
return currentNodeSelector;
}

@Getter
@ToString
@AllArgsConstructor
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/cloud/sonic/driver/poco/PocoDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ public void testUpdateRootCase() throws SonicRespException{
Assert.assertEquals(lastRootXml, pocoElement.getRootElement().getXmlElement().toString());
}

@Test
public void testGetAttribute() throws SonicRespException{
String expression = "poco(\"star\")[3]";
PocoElement pocoElement = pocoDriver.findElement(PocoSelector.POCO, expression);
System.out.println(pocoElement.getAttribute("_instanceId"));
assert pocoElement.getAttribute("_instanceId")!=null;
}

@AfterClass
public static void afterClass() {
pocoDriver.closeDriver();
Expand Down

0 comments on commit 8911237

Please sign in to comment.