diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Drag.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Drag.java index a6717556f..8606ce90a 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Drag.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Drag.java @@ -140,6 +140,8 @@ public class Drag extends CommandHandler { @Override public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { + // DragArguments is created on each execute which prevents leaking state + // across executions. final DragArguments dragArgs = new DragArguments(command); if (command.isElementCommand()) { diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Find.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Find.java index 6317a869d..b0ca1cca9 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Find.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/Find.java @@ -33,12 +33,13 @@ import com.android.uiautomator.core.UiSelector; /** * This handler is used to find elements in the Android UI. - * + * * Based on which {@link Strategy}, {@link UiSelector}, and optionally the * contextId, the element Id or Ids are returned to the user. - * + * */ public class Find extends CommandHandler { + // These variables are expected to persist across executions. AndroidElementsHash elements = AndroidElementsHash.getInstance(); Dynamic dynamic = new Dynamic(); public static JSONObject apkStrings = null; @@ -60,11 +61,11 @@ public class Find extends CommandHandler { /* * @param command The {@link AndroidCommand} used for this handler. - * + * * @return {@link AndroidCommandResult} - * + * * @throws JSONException - * + * * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android. * bootstrap.AndroidCommand) */ @@ -213,13 +214,16 @@ public class Find extends CommandHandler { } catch (final AndroidCommandException e) { return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage()); } catch (final ElementNotFoundException e) { - return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage()); + return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, + e.getMessage()); } catch (final UnallowedTagNameException e) { return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage()); } catch (final ElementNotInHashException e) { - return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage()); + return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, + e.getMessage()); } catch (final UiObjectNotFoundException e) { - return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage()); + return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, + e.getMessage()); } } else { try { @@ -264,9 +268,11 @@ public class Find extends CommandHandler { } catch (final AndroidCommandException e) { return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage()); } catch (final UiObjectNotFoundException e) { - return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage()); + return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, + e.getMessage()); } catch (final ElementNotFoundException e) { - return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage()); + return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, + e.getMessage()); } } } @@ -274,12 +280,12 @@ public class Find extends CommandHandler { /** * Get the element from the {@link AndroidElementsHash} and return the element * id using JSON. - * + * * @param sel * A UiSelector that targets the element to fetch. * @param contextId * The Id of the element used for the context. - * + * * @return JSONObject * @throws JSONException * @throws ElementNotFoundException @@ -295,12 +301,12 @@ public class Find extends CommandHandler { /** * Get an array of elements from the {@link AndroidElementsHash} and return * the element's ids using JSON. - * + * * @param sel * A UiSelector that targets the element to fetch. * @param contextId * The Id of the element used for the context. - * + * * @return JSONObject * @throws JSONException * @throws UiObjectNotFoundException @@ -320,7 +326,7 @@ public class Find extends CommandHandler { /** * Create and return a UiSelector based on the strategy, text, and how many * you want returned. - * + * * @param strategy * The {@link Strategy} used to search for the element. * @param text @@ -400,7 +406,7 @@ public class Find extends CommandHandler { /** * Create and return a UiSelector based on Xpath attributes. - * + * * @param path * The Xpath path. * @param attr @@ -409,7 +415,7 @@ public class Find extends CommandHandler { * Any constraint. * @param substr * Any substr. - * + * * @return UiSelector * @throws AndroidCommandException */ diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchEvent.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchEvent.java index 9ca89d7df..cd53dbc59 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchEvent.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchEvent.java @@ -35,15 +35,15 @@ public abstract class TouchEvent extends CommandHandler { return fieldObject; } - protected AndroidElement el = null; + protected AndroidElement el; - protected int clickX = -1; + protected int clickX; - protected int clickY = -1; + protected int clickY; protected Hashtable params; - protected boolean isElement = false; + protected boolean isElement; /** * @@ -56,6 +56,7 @@ public abstract class TouchEvent extends CommandHandler { @Override public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { + initalize(); try { params = command.params(); @@ -138,6 +139,18 @@ public abstract class TouchEvent extends CommandHandler { return method; } + /** + * Variables persist across executions. initialize must be called at the start + * of execute. + **/ + private void initalize() { + el = null; + clickX = -1; + clickY = -1; + params = null; + isElement = false; + } + protected void printEventDebugLine(final String methodName, final Integer... duration) { String extra = "";