From 68c299f1e2e83f671572952f60a80bc3743f37e9 Mon Sep 17 00:00:00 2001 From: Sravan Medrapu Date: Fri, 6 Jan 2017 18:20:49 +0530 Subject: [PATCH 1/2] Refactored PressBack to ignore return status --- .../io/appium/uiautomator2/handler/PressBack.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/appium/uiautomator2/handler/PressBack.java b/app/src/main/java/io/appium/uiautomator2/handler/PressBack.java index 9670fc803..f385bb2a4 100644 --- a/app/src/main/java/io/appium/uiautomator2/handler/PressBack.java +++ b/app/src/main/java/io/appium/uiautomator2/handler/PressBack.java @@ -4,7 +4,6 @@ import io.appium.uiautomator2.http.AppiumResponse; import io.appium.uiautomator2.http.IHttpRequest; import io.appium.uiautomator2.server.WDStatus; -import io.appium.uiautomator2.utils.Logger; import static io.appium.uiautomator2.utils.Device.back; @@ -16,13 +15,9 @@ public PressBack(String mappedUri) { @Override public AppiumResponse safeHandle(IHttpRequest request) { - boolean status = back(); - if (status) { - Logger.info("Pressed Back"); - return new AppiumResponse(getSessionId(request), WDStatus.SUCCESS, status); - } else { - Logger.info("Unable to Press Back"); - return new AppiumResponse(getSessionId(request), WDStatus.UNKNOWN_ERROR, status); - } + back(); + // Press back returns false even when back was successfully pressed. + // Always return true. + return new AppiumResponse(getSessionId(request), WDStatus.SUCCESS, true); } } From fd898029ba16551c61d83e91d1007e84b2335042 Mon Sep 17 00:00:00 2001 From: Sravan Medrapu Date: Tue, 10 Jan 2017 14:51:17 +0530 Subject: [PATCH 2/2] Refactored Drag JSON Body --- .../io/appium/uiautomator2/unittest/test/HandlersTest.java | 5 ++++- app/src/main/java/io/appium/uiautomator2/handler/Drag.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/androidTestE2eTest/java/io/appium/uiautomator2/unittest/test/HandlersTest.java b/app/src/androidTestE2eTest/java/io/appium/uiautomator2/unittest/test/HandlersTest.java index e64599212..3bbb04d50 100644 --- a/app/src/androidTestE2eTest/java/io/appium/uiautomator2/unittest/test/HandlersTest.java +++ b/app/src/androidTestE2eTest/java/io/appium/uiautomator2/unittest/test/HandlersTest.java @@ -180,7 +180,7 @@ public void dragAndDropTest() throws JSONException, InterruptedException { String destElementId = new JSONObject(new JSONObject(destElement).get("value").toString()).get("ELEMENT").toString(); JSONObject dragBody = new JSONObject(); - dragBody.put("element", srcElementId); + dragBody.put("elementId", srcElementId); dragBody.put("destElId", destElementId); dragBody.put("startX", startX); dragBody.put("startY", startY); @@ -191,6 +191,9 @@ public void dragAndDropTest() throws JSONException, InterruptedException { response = drag(dragBody.toString()); boolean result = (Boolean) getValueInJsonObject(response, "value"); assertTrue("Drag status from src to dest should be true. ", result); + + String dragStatus = findElement(By.id("io.appium.android.apis:id/drag_result_text")); + assertEquals("Dropped!", getText(dragStatus)); } @Test diff --git a/app/src/main/java/io/appium/uiautomator2/handler/Drag.java b/app/src/main/java/io/appium/uiautomator2/handler/Drag.java index 24754079e..c7115c4f6 100644 --- a/app/src/main/java/io/appium/uiautomator2/handler/Drag.java +++ b/app/src/main/java/io/appium/uiautomator2/handler/Drag.java @@ -30,7 +30,7 @@ public AppiumResponse safeHandle(IHttpRequest request) { final DragArguments dragArgs; try { dragArgs = new DragArguments(request); - if (getPayload(request).has(ELEMENT_ID_KEY_NAME)) { + if (getPayload(request).has("elementId")) { return dragElement(dragArgs, request); } else { return drag(dragArgs, request); @@ -133,8 +133,8 @@ public DragArguments(final IHttpRequest request) throws JSONException { JSONObject payload = getPayload(request); - if (payload.has(ELEMENT_ID_KEY_NAME)) { - String id = payload.getString(ELEMENT_ID_KEY_NAME); + if (payload.has("elementId")) { + String id = payload.getString("elementId"); el = KnownElements.getElementFromCache(id); } if (payload.has("destElId")) {