Skip to content

Commit

Permalink
Merge pull request #49 from sravanmedarapu/master
Browse files Browse the repository at this point in the history
Refactored PressBack to ignore return status
  • Loading branch information
sravanmedarapu authored Jan 11, 2017
2 parents 5aaa508 + fd89802 commit dceb1d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/io/appium/uiautomator2/handler/Drag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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")) {
Expand Down
13 changes: 4 additions & 9 deletions app/src/main/java/io/appium/uiautomator2/handler/PressBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}

0 comments on commit dceb1d6

Please sign in to comment.