mirror of
https://github.com/appium/appium.git
synced 2026-02-09 11:18:51 -06:00
Prevent leaking state across executions
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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<String, Object> 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 = "";
|
||||
|
||||
Reference in New Issue
Block a user