From c51f2acd6771380aaf5862f88209d8633ecbc77c Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Tue, 27 Jun 2023 20:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83W3C=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=9C=A8BaseElement=E4=B8=AD=E5=A2=9E=E5=8A=A0=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E7=9A=84isDisplayed=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/service/impl/AndroidElementImpl.java | 6 ++++++ .../sonic/driver/common/models/BaseElement.java | 7 +++++++ .../driver/ios/service/impl/IOSElementImpl.java | 15 +++++++++++++++ .../sonic/driver/poco/models/PocoElement.java | 5 +++++ .../org/cloud/sonic/driver/ios/IOSDriverTest.java | 12 ++++++++++++ 5 files changed, 45 insertions(+) diff --git a/src/main/java/org/cloud/sonic/driver/android/service/impl/AndroidElementImpl.java b/src/main/java/org/cloud/sonic/driver/android/service/impl/AndroidElementImpl.java index d4b42c9..29c8c7f 100644 --- a/src/main/java/org/cloud/sonic/driver/android/service/impl/AndroidElementImpl.java +++ b/src/main/java/org/cloud/sonic/driver/android/service/impl/AndroidElementImpl.java @@ -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); + } } diff --git a/src/main/java/org/cloud/sonic/driver/common/models/BaseElement.java b/src/main/java/org/cloud/sonic/driver/common/models/BaseElement.java index 9233cd1..de19361 100644 --- a/src/main/java/org/cloud/sonic/driver/common/models/BaseElement.java +++ b/src/main/java/org/cloud/sonic/driver/common/models/BaseElement.java @@ -11,4 +11,11 @@ public interface BaseElement { String getUniquelyIdentifies() throws SonicRespException; // List 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; } diff --git a/src/main/java/org/cloud/sonic/driver/ios/service/impl/IOSElementImpl.java b/src/main/java/org/cloud/sonic/driver/ios/service/impl/IOSElementImpl.java index 460e7a7..f589c56 100644 --- a/src/main/java/org/cloud/sonic/driver/ios/service/impl/IOSElementImpl.java +++ b/src/main/java/org/cloud/sonic/driver/ios/service/impl/IOSElementImpl.java @@ -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()); + } + } } diff --git a/src/main/java/org/cloud/sonic/driver/poco/models/PocoElement.java b/src/main/java/org/cloud/sonic/driver/poco/models/PocoElement.java index fb525fc..78f1763 100644 --- a/src/main/java/org/cloud/sonic/driver/poco/models/PocoElement.java +++ b/src/main/java/org/cloud/sonic/driver/poco/models/PocoElement.java @@ -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 diff --git a/src/test/java/org/cloud/sonic/driver/ios/IOSDriverTest.java b/src/test/java/org/cloud/sonic/driver/ios/IOSDriverTest.java index 88a5d22..e4cc306 100644 --- a/src/test/java/org/cloud/sonic/driver/ios/IOSDriverTest.java +++ b/src/test/java/org/cloud/sonic/driver/ios/IOSDriverTest.java @@ -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();