Skip to content

Commit

Permalink
Merge pull request #93 from caofengbin/feature/add_isDisplay
Browse files Browse the repository at this point in the history
feat:参考W3C规范在BaseElement中增加常用的isDisplayed方法
  • Loading branch information
caofengbin authored Jun 27, 2023
2 parents d02e5f7 + c51f2ac commit 32d0255
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,10 @@ public byte[] screenshot() throws SonicRespException {
throw new SonicRespException(b.getErr().getMessage());
}
}

@Override
public boolean isDisplayed() throws SonicRespException {
String result = getAttribute("displayed");
return Boolean.parseBoolean(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ public interface BaseElement {
String getUniquelyIdentifies() throws SonicRespException;

// List<BaseElement> getChildren() throws SonicRespException;
/**
* Is this element displayed or not?
* This method avoids the problem of having to parse an element's "style" attribute.
*
* @return whether the element is displayed
*/
boolean isDisplayed() throws SonicRespException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,19 @@ public byte[] screenshot() throws SonicRespException {
throw new SonicRespException(b.getErr().getMessage());
}
}

@Override
public boolean isDisplayed() throws SonicRespException {
wdaClient.checkSessionId();
BaseResp b = wdaClient.getRespHandler().getResp(
HttpUtil.createGet(wdaClient.getRemoteUrl() + "/session/"
+ wdaClient.getSessionId() + "/element/" + id + "/displayed"));
if (b.getErr() == null) {
logger.info("get %s displayed,result is %s.", id, b.getValue().toString());
return Boolean.parseBoolean(b.getValue().toString());
} else {
logger.error("get %s displayed failed.", id);
throw new SonicRespException(b.getErr().getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public String getUniquelyIdentifies() throws SonicRespException {
return currentNodeSelector;
}

@Override
public boolean isDisplayed() throws SonicRespException {
throw new SonicRespException("poco element unrealized");
}

@Getter
@ToString
@AllArgsConstructor
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/cloud/sonic/driver/ios/IOSDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ public void testSetAppiumSettings() throws SonicRespException {
iosDriver.setAppiumSettings(new JSONObject());
}

@Test
public void testIsDisplayed() throws SonicRespException {
String value = "name CONTAINS 'QDII' AND label CONTAINS 'QDII' AND enabled == true AND visible == true";
IOSElement element1 = iosDriver.findElement(IOSSelector.PREDICATE, value);
System.out.println(element1.getUniquelyIdentifies() + ",isDisplayed=" + element1.isDisplayed());
System.out.println(element1.getUniquelyIdentifies() + ",rect=" + element1.getRect());

IOSElement element2 = iosDriver.findElement(IOSSelector.ACCESSIBILITY_ID, "QDII");
System.out.println(element2.getUniquelyIdentifies() + ",isDisplayed=" + element2.isDisplayed());
System.out.println(element2.getUniquelyIdentifies() + ",rect=" + element2.getRect());
}

@AfterClass
public static void after() throws SonicRespException {
iosDriver.closeDriver();
Expand Down

0 comments on commit 32d0255

Please sign in to comment.