From 736dc7491c094e698fbd8ca153852fc692155b08 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Fri, 28 Oct 2022 20:46:59 +0800 Subject: [PATCH] fix : old uia2 --- .../service/impl/AndroidElementImpl.java | 14 ++++++------ .../android/service/impl/UiaClientImpl.java | 22 +++++++++---------- .../driver/android/AndroidDriverTest.java | 1 + 3 files changed, 19 insertions(+), 18 deletions(-) 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 652a037..5877767 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 @@ -43,7 +43,7 @@ public AndroidElementImpl(String id, UiaClient uiaClient) { public void click() throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createPost(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createPost(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/click")); if (b.getErr() == null) { logger.info("click element %s.", id); @@ -65,7 +65,7 @@ public void sendKeys(String text, boolean isCover) throws SonicRespException { data.put("text", text); data.put("replace", isCover); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createPost(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createPost(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/value") .body(data.toJSONString()), 60000); if (b.getErr() == null) { @@ -80,7 +80,7 @@ public void sendKeys(String text, boolean isCover) throws SonicRespException { public void clear() throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createPost(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createPost(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/clear"), 60000); if (b.getErr() == null) { logger.info("clear %s.", id); @@ -94,7 +94,7 @@ public void clear() throws SonicRespException { public String getText() throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createGet(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createGet(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/text")); if (b.getErr() == null) { logger.info("get %s text %s.", id, b.getValue().toString()); @@ -109,7 +109,7 @@ public String getText() throws SonicRespException { public String getAttribute(String name) throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createGet(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createGet(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/attribute/" + name)); if (b.getErr() == null) { logger.info("get %s attribute %s result %s.", id, name, b.getValue().toString()); @@ -124,7 +124,7 @@ public String getAttribute(String name) throws SonicRespException { public ElementRect getRect() throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createGet(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createGet(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/rect")); if (b.getErr() == null) { ElementRect elementRect = JSON.parseObject(b.getValue().toString(), ElementRect.class); @@ -140,7 +140,7 @@ public ElementRect getRect() throws SonicRespException { public byte[] screenshot() throws SonicRespException { uiaClient.checkSessionId(); BaseResp b = uiaClient.getRespHandler().getResp( - HttpUtil.createGet(uiaClient.getRemoteUrl() + "/session/" + HttpUtil.createGet(uiaClient.getRemoteUrl() + "/wd/hub/session/" + uiaClient.getSessionId() + "/element/" + id + "/screenshot"), 60000); if (b.getErr() == null) { logger.info("get element %s screenshot.", id); diff --git a/src/main/java/org/cloud/sonic/driver/android/service/impl/UiaClientImpl.java b/src/main/java/org/cloud/sonic/driver/android/service/impl/UiaClientImpl.java index 7221f60..44972ce 100644 --- a/src/main/java/org/cloud/sonic/driver/android/service/impl/UiaClientImpl.java +++ b/src/main/java/org/cloud/sonic/driver/android/service/impl/UiaClientImpl.java @@ -121,7 +121,7 @@ public void setSessionId(String sessionId) { public void newSession(JSONObject capabilities) throws SonicRespException { JSONObject data = new JSONObject(); data.put("capabilities", capabilities); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session").body(data.toJSONString())); + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session").body(data.toJSONString())); if (b.getErr() == null) { SessionInfo sessionInfo = JSON.parseObject(b.getValue().toString(), SessionInfo.class); setSessionId(sessionInfo.getSessionId()); @@ -137,7 +137,7 @@ public void newSession(JSONObject capabilities) throws SonicRespException { @Override public void closeSession() throws SonicRespException { checkSessionId(); - respHandler.getResp(HttpUtil.createRequest(Method.DELETE, remoteUrl + "/session/" + sessionId)); + respHandler.getResp(HttpUtil.createRequest(Method.DELETE, remoteUrl + "/wd/hub/session/" + sessionId)); logger.info("close session successful!"); } @@ -153,7 +153,7 @@ public void checkSessionId() throws SonicRespException { public WindowSize getWindowSize() throws SonicRespException { if (size == null) { checkSessionId(); - BaseResp b = respHandler.getResp(HttpUtil.createGet(remoteUrl + "/session/" + sessionId + "/window/:windowHandle/size")); + BaseResp b = respHandler.getResp(HttpUtil.createGet(remoteUrl + "/wd/hub/session/" + sessionId + "/window/:windowHandle/size")); if (b.getErr() == null) { size = JSON.parseObject(b.getValue().toString(), WindowSize.class); logger.info("get window size %s.", size.toString()); @@ -171,7 +171,7 @@ public void sendKeys(String text, boolean isCover) throws SonicRespException { JSONObject data = new JSONObject(); data.put("text", text); data.put("replace", isCover); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/keys") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/keys") .body(data.toJSONString())); if (b.getErr() == null) { logger.info("send key %s.", text); @@ -187,7 +187,7 @@ public void setPasteboard(String contentType, String content) throws SonicRespEx JSONObject data = new JSONObject(); data.put("contentType", contentType.toUpperCase(Locale.ROOT)); data.put("content", Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8))); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/appium/device/set_clipboard") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/appium/device/set_clipboard") .body(data.toJSONString())); if (b.getErr() == null) { logger.info("set pasteboard %s.", content); @@ -202,7 +202,7 @@ public byte[] getPasteboard(String contentType) throws SonicRespException { checkSessionId(); JSONObject data = new JSONObject(); data.put("contentType", contentType.toUpperCase(Locale.ROOT)); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/appium/device/get_clipboard") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/appium/device/get_clipboard") .body(data.toJSONString())); if (b.getErr() == null) { byte[] result = Base64.getMimeDecoder().decode(b.getValue().toString()); @@ -217,7 +217,7 @@ public byte[] getPasteboard(String contentType) throws SonicRespException { @Override public String pageSource() throws SonicRespException { checkSessionId(); - BaseResp b = respHandler.getResp(HttpUtil.createGet(remoteUrl + "/session/" + sessionId + "/source"), 60000); + BaseResp b = respHandler.getResp(HttpUtil.createGet(remoteUrl + "/wd/hub/session/" + sessionId + "/source"), 60000); if (b.getErr() == null) { logger.info("get page source."); return b.getValue().toString(); @@ -250,7 +250,7 @@ public AndroidElement findElement(String selector, String value, Integer retry, JSONObject data = new JSONObject(); data.put("strategy", selector); data.put("selector", value); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/element") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/element") .body(data.toJSONString())); if (b.getErr() == null) { logger.info("find element successful."); @@ -292,7 +292,7 @@ public List findElementList(String selector, String value, Integ JSONObject data = new JSONObject(); data.put("strategy", selector); data.put("selector", value); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/elements") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/elements") .body(data.toJSONString())); if (b.getErr() == null) { logger.info("find elements successful."); @@ -329,7 +329,7 @@ public List findElementList(String selector, String value, Integ public byte[] screenshot() throws SonicRespException { checkSessionId(); BaseResp b = respHandler.getResp( - HttpUtil.createGet(remoteUrl + "/session/" + sessionId + "/screenshot"), 60000); + HttpUtil.createGet(remoteUrl + "/wd/hub/session/" + sessionId + "/screenshot"), 60000); if (b.getErr() == null) { logger.info("get screenshot."); return Base64.getMimeDecoder().decode(b.getValue().toString()); @@ -344,7 +344,7 @@ public void setAppiumSettings(JSONObject settings) throws SonicRespException { checkSessionId(); JSONObject data = new JSONObject(); data.put("settings", settings); - BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/session/" + sessionId + "/appium/settings") + BaseResp b = respHandler.getResp(HttpUtil.createPost(remoteUrl + "/wd/hub/session/" + sessionId + "/appium/settings") .body(data.toJSONString())); if (b.getErr() == null) { logger.info("set appium settings %s.", settings.toJSONString()); diff --git a/src/test/java/org/cloud/sonic/driver/android/AndroidDriverTest.java b/src/test/java/org/cloud/sonic/driver/android/AndroidDriverTest.java index 9d0ee9d..1f270cb 100644 --- a/src/test/java/org/cloud/sonic/driver/android/AndroidDriverTest.java +++ b/src/test/java/org/cloud/sonic/driver/android/AndroidDriverTest.java @@ -117,6 +117,7 @@ public void testFindElement() throws SonicRespException, InterruptedException, I w.click(); String text = UUID.randomUUID().toString().substring(0, 6) + "中文"; w.sendKeys(text); + w.sendKeys(text, true); Assert.assertEquals(text, w.getText()); w.clear(); androidDriver.setDefaultFindElementInterval(null, 3000);