Clean up Java server code

This commit is contained in:
bootstraponline
2014-06-09 10:01:17 -04:00
parent 0dff3896ff
commit 88702ea119
58 changed files with 267 additions and 648 deletions
@@ -1,12 +1,13 @@
package com.android.uiautomator.common;
import static io.appium.android.bootstrap.utils.API.API_18;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import static io.appium.android.bootstrap.utils.API.API_18;
public class ReflectionUtils {
private static Field enableField(final Class<?> clazz, final String field)
throws SecurityException, NoSuchFieldException {
@@ -38,7 +39,7 @@ public class ReflectionUtils {
* the touchDown / touchUp / touchMove methods.
*/
public Object getController() throws IllegalArgumentException,
IllegalAccessException, SecurityException, NoSuchFieldException {
SecurityException {
return controller;
}
@@ -18,12 +18,7 @@
package com.android.uiautomator.common;
import android.util.Log;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.core.UiWatcher;
import com.android.uiautomator.core.*;
import java.util.ArrayList;
import java.util.Collections;
@@ -1,14 +1,12 @@
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.CommandTypeException;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Hashtable;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
/**
* This proxy embodies the command that the handlers execute.
*
@@ -37,9 +35,6 @@ public class AndroidCommand {
return json.getString("action");
}
/**
* @return
*/
public AndroidCommandType commandType() {
return cmdType;
}
@@ -49,17 +44,11 @@ public class AndroidCommand {
* provide the "desElId" parameter).
*
* @return {@link AndroidElement}
* @throws ElementNotInHashException
* @throws JSONException
*/
public AndroidElement getDestElement() throws ElementNotInHashException,
JSONException {
AndroidElement destEl = null;
String destElId = null;
destElId = (String) params().get("destElId");
destEl = AndroidElementsHash.getInstance().getElement(destElId);
return destEl;
public AndroidElement getDestElement() throws JSONException {
String destElId = (String) params().get("destElId");
return AndroidElementsHash.getInstance().getElement(destElId);
}
/**
@@ -67,17 +56,11 @@ public class AndroidCommand {
* provide the "elementId" parameter).
*
* @return {@link AndroidElement}
* @throws ElementNotInHashException
* @throws JSONException
*/
public AndroidElement getElement() throws ElementNotInHashException,
JSONException {
AndroidElement el = null;
String elId = null;
elId = (String) params().get("elementId");
el = AndroidElementsHash.getInstance().getElement(elId);
return el;
public AndroidElement getElement() throws JSONException {
String elId = (String) params().get("elementId");
return AndroidElementsHash.getInstance().getElement(elId);
}
/**
@@ -132,5 +115,4 @@ public class AndroidCommand {
throw new CommandTypeException("Got bad command type: " + stringType);
}
}
}
@@ -1,42 +1,10 @@
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.AndroidCommandException;
import io.appium.android.bootstrap.handler.Clear;
import io.appium.android.bootstrap.handler.Click;
import io.appium.android.bootstrap.handler.Drag;
import io.appium.android.bootstrap.handler.DumpWindowHierarchy;
import io.appium.android.bootstrap.handler.Find;
import io.appium.android.bootstrap.handler.Flick;
import io.appium.android.bootstrap.handler.GetAttribute;
import io.appium.android.bootstrap.handler.GetDataDir;
import io.appium.android.bootstrap.handler.GetDeviceSize;
import io.appium.android.bootstrap.handler.GetLocation;
import io.appium.android.bootstrap.handler.GetName;
import io.appium.android.bootstrap.handler.GetSize;
import io.appium.android.bootstrap.handler.GetText;
import io.appium.android.bootstrap.handler.LongPressKeyCode;
import io.appium.android.bootstrap.handler.MultiPointerGesture;
import io.appium.android.bootstrap.handler.OpenNotification;
import io.appium.android.bootstrap.handler.Orientation;
import io.appium.android.bootstrap.handler.Pinch;
import io.appium.android.bootstrap.handler.PressBack;
import io.appium.android.bootstrap.handler.PressKeyCode;
import io.appium.android.bootstrap.handler.ScrollTo;
import io.appium.android.bootstrap.handler.SetText;
import io.appium.android.bootstrap.handler.Swipe;
import io.appium.android.bootstrap.handler.TakeScreenshot;
import io.appium.android.bootstrap.handler.TouchDown;
import io.appium.android.bootstrap.handler.TouchLongClick;
import io.appium.android.bootstrap.handler.TouchMove;
import io.appium.android.bootstrap.handler.TouchUp;
import io.appium.android.bootstrap.handler.UpdateStrings;
import io.appium.android.bootstrap.handler.WaitForIdle;
import io.appium.android.bootstrap.handler.Wake;
import io.appium.android.bootstrap.handler.*;
import org.json.JSONException;
import java.util.HashMap;
import org.json.JSONException;
/**
* Command execution dispatch class. This class relays commands to the various
* handlers.
@@ -86,11 +54,8 @@ class AndroidCommandExecutor {
* @param command
* The {@link AndroidCommand}
* @return {@link AndroidCommandResult}
* @throws AndroidCommandException
*/
public AndroidCommandResult execute(final AndroidCommand command)
throws AndroidCommandException {
public AndroidCommandResult execute(final AndroidCommand command) {
try {
Logger.debug("Got command action: " + command.action());
@@ -5,5 +5,5 @@ package io.appium.android.bootstrap;
*
*/
public enum AndroidCommandType {
ACTION, SHUTDOWN;
ACTION, SHUTDOWN
}
@@ -1,20 +1,19 @@
package io.appium.android.bootstrap;
import android.graphics.Rect;
import android.view.MotionEvent.PointerCoords;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.exceptions.NoAttributeFoundException;
import io.appium.android.bootstrap.utils.Point;
import io.appium.android.bootstrap.utils.UnicodeEncoder;
import android.graphics.Rect;
import static io.appium.android.bootstrap.utils.API.API_18;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import android.view.MotionEvent.PointerCoords;
import java.lang.reflect.Method;
import static io.appium.android.bootstrap.utils.API.API_18;
/**
* Proxy class for UiObject.
*
@@ -93,7 +92,7 @@ public class AndroidElement {
} else {
pos.x = rect.left + point.x;
}
if (boundsChecking == true) {
if (boundsChecking) {
if (pos.x > rect.right || pos.x < rect.left) {
throw new InvalidCoordinatesException("X coordinate ("
+ pos.x.toString() + " is outside of element rect: "
@@ -108,7 +107,7 @@ public class AndroidElement {
} else {
pos.y = rect.left + point.y;
}
if (boundsChecking == true) {
if (boundsChecking) {
if (pos.y > rect.bottom || pos.y < rect.top) {
throw new InvalidCoordinatesException("Y coordinate ("
+ pos.y.toString() + " is outside of element rect: "
@@ -121,7 +120,7 @@ public class AndroidElement {
public boolean getBoolAttribute(final String attr)
throws UiObjectNotFoundException, NoAttributeFoundException {
boolean res = false;
boolean res;
if (attr.equals("enabled")) {
res = el.isEnabled();
} else if (attr.equals("checkable")) {
@@ -176,7 +175,7 @@ public class AndroidElement {
public String getStringAttribute(final String attr)
throws UiObjectNotFoundException, NoAttributeFoundException {
String res = "";
String res;
if (attr.equals("name")) {
res = getContentDesc();
if (res.equals("")) {
@@ -252,7 +251,7 @@ public class AndroidElement {
// Instead we need to use Reflection to do it all at runtime.
Method method = this.el.getClass().getMethod("performMultiPointerGesture", PointerCoords[][].class);
Boolean rt = (Boolean)method.invoke(this.el, (Object)touches);
return rt.booleanValue();
return rt;
} else {
Logger.error("Device does not support API < 18!");
return false;
@@ -1,14 +1,12 @@
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.ElementNotFoundException;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.util.ArrayList;
import java.util.Hashtable;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.exceptions.ElementNotFoundException;
import java.util.ArrayList;
import java.util.Hashtable;
/**
* A cache of elements that the app has seen.
@@ -16,9 +14,6 @@ import com.android.uiautomator.core.UiSelector;
*/
public class AndroidElementsHash {
/**
* @return
*/
public static AndroidElementsHash getInstance() {
if (AndroidElementsHash.instance == null) {
AndroidElementsHash.instance = new AndroidElementsHash();
@@ -56,10 +51,8 @@ public class AndroidElementsHash {
*
* @param key
* @return {@link AndroidElement}
* @throws ElementNotInHashException
*/
public AndroidElement getElement(final String key)
throws ElementNotInHashException {
public AndroidElement getElement(final String key) {
return elements.get(key);
}
@@ -75,9 +68,9 @@ public class AndroidElementsHash {
*/
public AndroidElement getElement(final UiSelector sel, final String key)
throws ElementNotFoundException {
AndroidElement baseEl = null;
AndroidElement baseEl;
baseEl = elements.get(key);
UiObject el = null;
UiObject el;
if (baseEl == null) {
el = new UiObject(sel);
@@ -103,19 +96,17 @@ public class AndroidElementsHash {
* @param sel
* @param key
* @return ArrayList<{@link AndroidElement}>
* @throws ElementNotInHashException
* @throws UiObjectNotFoundException
*/
public ArrayList<AndroidElement> getElements(final UiSelector sel,
final String key) throws ElementNotInHashException,
UiObjectNotFoundException {
final String key) throws UiObjectNotFoundException {
boolean keepSearching = true;
final boolean useIndex = sel.toString().contains("CLASS_REGEX=");
final ArrayList<AndroidElement> elements = new ArrayList<AndroidElement>();
UiObject lastFoundObj = null;
UiObject lastFoundObj;
final AndroidElement baseEl = this.getElement(key);
UiSelector tmp = null;
UiSelector tmp;
int counter = 0;
while (keepSearching) {
if (baseEl == null) {
@@ -1,8 +1,7 @@
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.SocketServerException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import io.appium.android.bootstrap.exceptions.SocketServerException;
/**
* The Bootstrap class runs the socket server.
@@ -1,13 +1,11 @@
package io.appium.android.bootstrap;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import java.util.ArrayList;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import java.util.ArrayList;
/**
* Base class for all handlers.
@@ -27,8 +25,8 @@ public abstract class CommandHandler {
final ArrayList<Integer> retPos = new ArrayList<Integer>();
final UiDevice d = UiDevice.getInstance();
final Double screenX = new Double(d.getDisplayWidth());
final Double screenY = new Double(d.getDisplayHeight());
final Double screenX = (double) d.getDisplayWidth();
final Double screenY = (double) d.getDisplayHeight();
if (coordVals[0] < 1 && coordVals[1] < 1) {
retPos.add((int) (screenX * coordVals[0]));
@@ -41,12 +39,12 @@ public abstract class CommandHandler {
return retPos;
}
protected static Point GetDeviceAbsPos(final Point point)
protected static Point getDeviceAbsPos(final Point point)
throws InvalidCoordinatesException {
final UiDevice d = UiDevice.getInstance();
final Point retPos = new Point(point); // copy inputed point
final Double width = new Double(d.getDisplayWidth());
final Double width = (double) d.getDisplayWidth();
if (point.x < 1) {
retPos.x = width * point.x;
}
@@ -57,7 +55,7 @@ public abstract class CommandHandler {
+ width.toString());
}
final Double height = new Double(d.getDisplayHeight());
final Double height = (double) d.getDisplayHeight();
if (point.y < 1) {
retPos.y = height * point.y;
}
@@ -1,12 +1,11 @@
package io.appium.android.bootstrap;
import java.util.ArrayList;
import java.util.List;
import com.android.uiautomator.core.UiSelector;
import org.json.JSONArray;
import org.json.JSONException;
import com.android.uiautomator.core.UiSelector;
import java.util.ArrayList;
import java.util.List;
// Constants from
// https://android.googlesource.com/platform/frameworks/testing/+/master/uiautomator/library/core-src/com/android/uiautomator/core/UiSelector.java
@@ -86,6 +85,8 @@ public class Dynamic {
case GET_NAME:
value = result.getStringAttribute("name");
break;
default:
break;
}
return value;
@@ -203,6 +204,8 @@ public class Dynamic {
case SELECTOR_RESOURCE_ID_REGEX:
s = s.resourceIdMatches((String) param);
break;
default:
break;
}
}
}
@@ -1,26 +1,18 @@
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.AndroidCommandException;
import com.android.uiautomator.common.UiWatchers;
import io.appium.android.bootstrap.exceptions.CommandTypeException;
import io.appium.android.bootstrap.exceptions.SocketServerException;
import io.appium.android.bootstrap.handler.UpdateStrings;
import io.appium.android.bootstrap.utils.NotImportantViews;
import io.appium.android.bootstrap.utils.TheWatchers;
import org.json.JSONException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.uiautomator.common.UiWatchers;
/**
* The SocketServer class listens on a specific port for commands from Appium,
* and then passes them on to the {@link AndroidCommandExecutor} class. It will
@@ -28,18 +20,18 @@ import com.android.uiautomator.common.UiWatchers;
*/
class SocketServer {
ServerSocket server;
Socket client;
BufferedReader in;
PrintWriter out;
boolean keepListening;
ServerSocket server;
Socket client;
BufferedReader in;
BufferedWriter out;
boolean keepListening;
private final AndroidCommandExecutor executor;
private final TheWatchers watchers = TheWatchers.getInstance();
private final Timer timer = new Timer("WatchTimer");
private final TheWatchers watchers = TheWatchers.getInstance();
private final Timer timer = new Timer("WatchTimer");
/**
* Constructor
*
*
* @param port
* @throws SocketServerException
*/
@@ -58,7 +50,7 @@ class SocketServer {
/**
* Constructs an @{link AndroidCommand} and returns it.
*
*
* @param data
* @return @{link AndroidCommand}
* @throws JSONException
@@ -69,24 +61,29 @@ class SocketServer {
return new AndroidCommand(data);
}
private StringBuilder input = new StringBuilder();
/**
* When data is available on the socket, this method is called to run the
* command or throw an error if it can't.
*
*
* @throws SocketServerException
*/
private void handleClientData() throws SocketServerException {
String input = "";
char a;
AndroidCommand cmd;
String res;
try {
while ((a = (char) in.read()) != -1 && in.ready()) {
input += a;
input.setLength(0); // clear
String res;
int a;
// (char) -1 is not equal to -1.
// ready is checked to ensure the read call doesn't block.
while ((a = in.read()) != -1 && in.ready()) {
input.append((char) a);
}
Logger.info("Got data from client: " + input);
String inputString = input.toString();
Logger.info("Got data from client: " + inputString);
try {
cmd = getCommand(input);
AndroidCommand cmd = getCommand(inputString);
Logger.info("Got command of type " + cmd.commandType().toString());
res = runCommand(cmd);
Logger.info("Returning result: " + res);
@@ -108,7 +105,7 @@ class SocketServer {
/**
* Listens on the socket for data, and calls {@link #handleClientData()} when
* it's available.
*
*
* @throws SocketServerException
*/
public void listenForever() throws SocketServerException {
@@ -129,8 +126,8 @@ class SocketServer {
try {
client = server.accept();
Logger.info("Client connected");
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
out = new PrintWriter(client.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream(), "UTF-8"));
while (keepListening) {
handleClientData();
}
@@ -155,9 +152,9 @@ class SocketServer {
/**
* When {@link #handleClientData()} has valid data, this method delegates the
* command.
*
*
* @param cmd
* AndroidCommand
* AndroidCommand
* @return Result
*/
private String runCommand(final AndroidCommand cmd) {
@@ -168,7 +165,7 @@ class SocketServer {
} else if (cmd.commandType() == AndroidCommandType.ACTION) {
try {
res = executor.execute(cmd);
} catch (final AndroidCommandException e) {
} catch (final Exception e) {
res = new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage());
}
} else {
@@ -1,17 +0,0 @@
package io.appium.android.bootstrap.exceptions;
import io.appium.android.bootstrap.AndroidCommand;
/**
* An exception involving an {@link AndroidCommand}.
*
* @param msg
* A descriptive message describing the error.
*/
@SuppressWarnings("serial")
public class AndroidCommandException extends Exception {
public AndroidCommandException(final String msg) {
super(msg);
}
}
@@ -1,13 +1,14 @@
package io.appium.android.bootstrap.exceptions;
/**
* Exception for command type errors.
*
* @param msg
* A descriptive message describing the error.
*/
@SuppressWarnings("serial")
public class CommandTypeException extends Exception {
/**
* Exception for command type errors.
*
* @param msg
* A descriptive message describing the error.
*/
public CommandTypeException(final String msg) {
super(msg);
}
@@ -1,16 +0,0 @@
package io.appium.android.bootstrap.exceptions;
/**
* An exception that is thrown when an element can not be found in the cache,
* but it should be.
*
* @param msg
* A descriptive message describing the error.
* @see {@link AndroidElementHash}
*/
@SuppressWarnings("serial")
public class ElementNotInHashException extends Exception {
public ElementNotInHashException(final String message) {
super(message);
}
}
@@ -1,13 +1,13 @@
package io.appium.android.bootstrap.exceptions;
/**
* An exception that is thrown when an invalid coordinate is used.
*
* @param msg
* A descriptive message describing the error.
*/
@SuppressWarnings("serial")
public class InvalidCoordinatesException extends Exception {
/**
* An exception that is thrown when an invalid coordinate is used.
*
* @param msg
* A descriptive message describing the error.
*/
public InvalidCoordinatesException(final String msg) {
super(msg);
}
@@ -2,15 +2,15 @@ package io.appium.android.bootstrap.exceptions;
import io.appium.android.bootstrap.selector.Strategy;
/**
* An exception that is thrown when an invalid strategy is used.
*
* @param msg
* A descriptive message describing the error.
* @see {@link Strategy}
*/
@SuppressWarnings("serial")
public class InvalidStrategyException extends Exception {
/**
* An exception that is thrown when an invalid strategy is used.
*
* @param msg
* A descriptive message describing the error.
* @see {@link Strategy}
*/
public InvalidStrategyException(final String msg) {
super(msg);
}
@@ -1,14 +1,14 @@
package io.appium.android.bootstrap.exceptions;
/**
* This exception is thrown when the element doesn't have the attribute searched
* for.
*
* @param attr
* The attribute searched for.
*/
@SuppressWarnings("serial")
public class NoAttributeFoundException extends Exception {
/**
* This exception is thrown when the element doesn't have the attribute searched
* for.
*
* @param attr
* The attribute searched for.
*/
public NoAttributeFoundException(final String attr) {
super("This element does not have the '" + attr + "' attribute");
}
@@ -1,16 +1,16 @@
package io.appium.android.bootstrap.exceptions;
/**
* Exception for socket errors.
*
* @param msg
* A descriptive message describing the error.
*/
@SuppressWarnings("serial")
public class SocketServerException extends Exception {
String reason;
/**
* Exception for socket errors.
*
* @param msg
* A descriptive message describing the error.
*/
public SocketServerException(final String msg) {
super(msg);
reason = msg;
@@ -2,15 +2,15 @@ package io.appium.android.bootstrap.exceptions;
import io.appium.android.bootstrap.utils.UiSelectorParser;
/**
* An exception involving an {@link UiSelectorParser}.
*
* @param msg
* A descriptive message describing the error.
*/
@SuppressWarnings("serial")
public class UiSelectorSyntaxException extends Exception {
/**
* An exception involving an {@link UiSelectorParser}.
*
* @param msg
* A descriptive message describing the error.
*/
public UiSelectorSyntaxException(final String msg) {
super(msg);
}
@@ -1,13 +1,13 @@
package io.appium.android.bootstrap.exceptions;
/**
* This exception is thrown when the tag name is not supported
*
* @param tag
* The tag that was searched for.
*/
@SuppressWarnings("serial")
public class UnallowedTagNameException extends Exception {
/**
* This exception is thrown when the tag name is not supported
*
* @param tag
* The tag that was searched for.
*/
public UnallowedTagNameException(final String tag) {
super("Tag name '" + tag + "' is not supported in Android");
}
@@ -1,15 +1,8 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import org.json.JSONException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
/**
* This handler is used to clear elements in the Android UI.
@@ -40,9 +33,6 @@ public class Clear extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error clearing text");
}
@@ -1,19 +1,12 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.util.ArrayList;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.Hashtable;
/**
* This handler is used to click elements in the Android UI.
@@ -44,9 +37,6 @@ public class Click extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
@@ -1,21 +1,14 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import java.util.Hashtable;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Hashtable;
/**
* This handler is used to drag in the Android UI.
@@ -34,7 +27,7 @@ public class Drag extends CommandHandler {
* bootstrap.AndroidCommand)
*/
private class DragArguments {
private static class DragArguments {
public AndroidElement el;
public AndroidElement destEl;
@@ -58,7 +51,7 @@ public class Drag extends CommandHandler {
if (params.get("destElId") != JSONObject.NULL) {
destEl = command.getDestElement();
}
} catch (final ElementNotInHashException e) {
} catch (final Exception e) {
destEl = null;
}
start = new Point(params.get("startX"), params.get("startY"));
@@ -67,15 +60,14 @@ public class Drag extends CommandHandler {
}
}
private AndroidCommandResult drag(final DragArguments dragArgs)
throws JSONException {
private AndroidCommandResult drag(final DragArguments dragArgs) {
Point absStartPos = new Point();
Point absEndPos = new Point();
final UiDevice device = UiDevice.getInstance();
try {
absStartPos = GetDeviceAbsPos(dragArgs.start);
absEndPos = GetDeviceAbsPos(dragArgs.end);
absStartPos = getDeviceAbsPos(dragArgs.start);
absEndPos = getDeviceAbsPos(dragArgs.end);
} catch (final InvalidCoordinatesException e) {
return getErrorResult(e.getMessage());
}
@@ -91,13 +83,12 @@ public class Drag extends CommandHandler {
return getSuccessResult(rv);
}
private AndroidCommandResult dragElement(final DragArguments dragArgs)
throws JSONException {
private AndroidCommandResult dragElement(final DragArguments dragArgs) {
Point absEndPos = new Point();
if (dragArgs.destEl == null) {
try {
absEndPos = GetDeviceAbsPos(dragArgs.end);
absEndPos = getDeviceAbsPos(dragArgs.end);
} catch (final InvalidCoordinatesException e) {
return getErrorResult(e.getMessage());
}
@@ -120,7 +111,7 @@ public class Drag extends CommandHandler {
} else {
Logger.info("Dragging the element with id " + dragArgs.el.getId()
+ " to destination element with id " + dragArgs.destEl.getId()
+ " with steps: " + dragArgs.steps.intValue());
+ " with steps: " + dragArgs.steps);
try {
final boolean rv = dragArgs.el.dragTo(dragArgs.destEl.getUiObject(),
dragArgs.steps);
@@ -15,6 +15,7 @@ import java.io.File;
* platform/frameworks/testing/+/master/uiautomator
* /library/core-src/com/android/uiautomator/core/UiDevice.java
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public class DumpWindowHierarchy extends CommandHandler {
// Note that
// "new File(new File(Environment.getDataDirectory(), "local/tmp"), fileName)"
@@ -1,12 +1,14 @@
package io.appium.android.bootstrap.handler;
import static io.appium.android.bootstrap.utils.API.API_18;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.*;
import io.appium.android.bootstrap.exceptions.ElementNotFoundException;
import io.appium.android.bootstrap.exceptions.InvalidStrategyException;
import io.appium.android.bootstrap.exceptions.UiSelectorSyntaxException;
import io.appium.android.bootstrap.exceptions.UnallowedTagNameException;
import io.appium.android.bootstrap.selector.Strategy;
import io.appium.android.bootstrap.utils.ElementHelpers;
import io.appium.android.bootstrap.utils.NotImportantViews;
@@ -20,6 +22,8 @@ import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import static io.appium.android.bootstrap.utils.API.API_18;
/**
* This handler is used to find elements in the Android UI.
* <p/>
@@ -30,7 +34,7 @@ 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;
static JSONObject apkStrings = null;
UiSelectorParser uiSelectorParser = new UiSelectorParser();
/*
@@ -88,7 +92,7 @@ public class Find extends CommandHandler {
Logger.debug(selectors.toString());
try {
int finalizer = 0;
JSONArray pair = null;
JSONArray pair;
List<AndroidElement> elementResults = new ArrayList<AndroidElement>();
final JSONArray jsonResults = new JSONArray();
// Start at 1 to skip over all.
@@ -97,7 +101,7 @@ public class Find extends CommandHandler {
Logger.debug("Parsing selector " + selIndex);
pair = (JSONArray) selectors.get(selIndex);
Logger.debug("Pair is: " + pair);
UiSelector sel = null;
UiSelector sel;
// 100+ int represents a method called on the element
// after the element has been found.
// [[4,"android.widget.EditText"],[100]] => 100
@@ -204,7 +208,6 @@ public class Find extends CommandHandler {
array.put(results.get(a));
}
}
} catch (final ElementNotInHashException e) {
} catch (final ElementNotFoundException e) {
}
}
@@ -222,10 +225,6 @@ public class Find extends CommandHandler {
return getSuccessResult(result);
} catch (final InvalidStrategyException e) {
return getErrorResult(e.getMessage());
} catch (final UnallowedTagNameException e) {
return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage());
} catch (final AndroidCommandException e) {
return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage());
} catch (final UiSelectorSyntaxException e) {
return new AndroidCommandResult(WDStatus.UNKNOWN_COMMAND, e.getMessage());
} catch (final UiObjectNotFoundException e) {
@@ -246,10 +245,9 @@ public class Find extends CommandHandler {
* @return JSONObject
* @throws JSONException
* @throws ElementNotFoundException
* @throws ElementNotInHashException
*/
private JSONObject fetchElement(final UiSelector sel, final String contextId)
throws JSONException, ElementNotFoundException, ElementNotInHashException {
throws JSONException, ElementNotFoundException {
final JSONObject res = new JSONObject();
final AndroidElement el = elements.getElement(sel, contextId);
return res.put("ELEMENT", el.getId());
@@ -261,12 +259,11 @@ public class Find extends CommandHandler {
*
* @param indexPath
* @return
* @throws ElementNotInHashException
* @throws ElementNotFoundException
* @throws JSONException
*/
private JSONObject fetchElementByIndexPath(final String indexPath)
throws ElementNotInHashException, ElementNotFoundException, JSONException {
throws ElementNotFoundException, JSONException {
UiSelector sel = new UiSelector().index(0);
Integer curIndex;
List<String> paths = Arrays.asList(indexPath.split("/"));
@@ -274,7 +271,7 @@ public class Find extends CommandHandler {
// element, since it will refer to the root element, which we already have
paths = paths.subList(2, paths.size());
for (final String index : paths) {
curIndex = new Integer(index);
curIndex = Integer.valueOf(index);
// get a new selector which selects the current selector's child at the
// correct index
sel = sel.childSelector(new UiSelector().index(curIndex));
@@ -293,11 +290,9 @@ public class Find extends CommandHandler {
* @return JSONObject
* @throws JSONException
* @throws UiObjectNotFoundException
* @throws ElementNotInHashException
*/
private JSONArray fetchElements(final UiSelector sel, final String contextId)
throws JSONException, ElementNotInHashException,
UiObjectNotFoundException {
throws JSONException, UiObjectNotFoundException {
final JSONArray resArray = new JSONArray();
final ArrayList<AndroidElement> els = elements.getElements(sel, contextId);
for (final AndroidElement el : els) {
@@ -328,9 +323,6 @@ public class Find extends CommandHandler {
} catch (final ElementNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
}
}
if (multiple) {
@@ -352,12 +344,10 @@ public class Find extends CommandHandler {
* Boolean that is either only one element (false), or many (true)
* @return UiSelector
* @throws InvalidStrategyException
* @throws AndroidCommandException
* @throws ElementNotFoundException
*/
private List<UiSelector> getSelector(final Strategy strategy,
final String text, final boolean many) throws InvalidStrategyException,
AndroidCommandException, UnallowedTagNameException,
ElementNotFoundException, UiSelectorSyntaxException {
final List<UiSelector> selectors = new ArrayList<UiSelector>();
UiSelector sel = new UiSelector();
@@ -1,18 +1,12 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import java.util.Hashtable;
/**
* This handler is used to flick elements in the Android UI.
@@ -63,7 +57,7 @@ public class Flick extends CommandHandler {
throws JSONException {
Point start = new Point(0.5, 0.5);
Point end = new Point();
Double steps = null;
Double steps;
final Hashtable<String, Object> params = command.params();
final UiDevice d = UiDevice.getInstance();
@@ -93,7 +87,7 @@ public class Flick extends CommandHandler {
Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed));
steps = 1250.0 / speed + 1;
start = GetDeviceAbsPos(start);
start = getDeviceAbsPos(start);
end = calculateEndPoint(start, xSpeed, ySpeed);
} catch (final InvalidCoordinatesException e) {
return getErrorResult(e.getMessage());
@@ -1,18 +1,11 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.NoAttributeFoundException;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import java.util.Hashtable;
/**
* This handler is used to get an attribute of an element.
@@ -52,9 +45,6 @@ public class GetAttribute extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // el is null
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
@@ -1,9 +1,9 @@
package io.appium.android.bootstrap.handler;
import android.os.Environment;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import android.os.Environment;
/**
* This handler is used to get the data dir.
@@ -1,14 +1,12 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to get the size of the screen.
*
@@ -1,16 +1,10 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import android.graphics.Rect;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.Rect;
/**
* This handler is used to get the text of elements that support it.
*
@@ -1,15 +1,8 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import org.json.JSONException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
/**
* This handler is used to get the text of elements that support it.
@@ -39,8 +32,6 @@ public class GetName extends CommandHandler {
return getSuccessResult(el.getContentDesc());
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
@@ -1,19 +1,11 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import android.graphics.Rect;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.Rect;
import com.android.uiautomator.core.UiObjectNotFoundException;
/**
* This handler is used to get the size of elements that support it.
*
@@ -45,9 +37,6 @@ public class GetSize extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
@@ -1,15 +1,8 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import org.json.JSONException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
/**
* This handler is used to get the text of elements that support it.
@@ -38,9 +31,6 @@ public class GetText extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
@@ -1,22 +1,19 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import java.lang.reflect.Method;
import java.util.Hashtable;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.SystemClock;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import com.android.uiautomator.common.ReflectionUtils;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Method;
import java.util.Hashtable;
/**
* This handler is used to LongPressKeyCode.
@@ -1,23 +1,15 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.lang.reflect.Method;
import android.view.MotionEvent.PointerCoords;
import com.android.uiautomator.common.ReflectionUtils;
import io.appium.android.bootstrap.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import static io.appium.android.bootstrap.utils.API.API_18;
import android.view.MotionEvent.PointerCoords;
import java.lang.reflect.Method;
import com.android.uiautomator.common.ReflectionUtils;
import static io.appium.android.bootstrap.utils.API.API_18;
public class MultiPointerGesture extends CommandHandler {
@@ -72,7 +64,7 @@ public class MultiPointerGesture extends CommandHandler {
PointerCoords[][].class);
final Boolean rt = (Boolean) pmpg.invoke(utils.getController(),
(Object) pcs);
if (rt.booleanValue()) {
if (rt) {
return getSuccessResult("OK");
} else {
return getErrorResult("Unable to perform multi pointer gesture");
@@ -83,8 +75,6 @@ public class MultiPointerGesture extends CommandHandler {
"Cannot perform multi pointer gesture on device below API level 18");
}
}
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) {
Logger.debug("Exception: " + e);
e.printStackTrace();
@@ -1,11 +1,11 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import static io.appium.android.bootstrap.utils.API.API_18;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to open the notification shade on the device.
@@ -1,18 +1,11 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.OrientationEnum;
import java.util.Hashtable;
import android.os.RemoteException;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import android.os.RemoteException;
import com.android.uiautomator.core.UiDevice;
import java.util.Hashtable;
/**
* This handler is used to get or set the orientation of the device.
@@ -1,18 +1,10 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.util.Hashtable;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import com.android.uiautomator.core.UiObjectNotFoundException;
import java.util.Hashtable;
/**
* This handler is used to pinch in/out elements in the Android UI.
@@ -45,17 +37,15 @@ public class Pinch extends CommandHandler {
el = command.getElement();
if (el == null) {
return getErrorResult("Could not find an element with elementId: "
+ (String) params.get("elementId"));
+ params.get("elementId"));
}
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) { // JSONException, NullPointerException, etc.
return getErrorResult("Unknown error:" + e.getMessage());
}
Logger.info("Pinching " + direction + " " + percent.toString() + "%"
+ " with steps: " + steps.toString());
boolean res = false;
boolean res;
if (direction.equals("in")) {
try {
res = el.pinchIn(percent, steps);
@@ -1,11 +1,10 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to press back.
*
@@ -1,15 +1,13 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import java.util.Hashtable;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.uiautomator.core.UiDevice;
import java.util.Hashtable;
/**
* This handler is used to PressKeyCode.
@@ -4,18 +4,11 @@ import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import java.util.Hashtable;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
/**
* This handler is used to scroll to elements in the Android UI.
*
@@ -77,8 +70,6 @@ public class ScrollTo extends CommandHandler {
return getSuccessResult(result);
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final NullPointerException e) { // el is null
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) {
@@ -1,64 +0,0 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.util.ArrayList;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
/**
* This handler is used to set attributes on elements that support it.
*
*/
public class SetAttribute 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)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command)
throws JSONException {
if (command.isElementCommand()) {
boolean res;
try {
final AndroidElement el = command.getElement();
res = el.click();
return getSuccessResult(res);
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
} else {
final Hashtable<String, Object> params = command.params();
final Double[] coords = { Double.parseDouble(params.get("x").toString()),
Double.parseDouble(params.get("y").toString()) };
final ArrayList<Integer> posVals = absPosFromCoords(coords);
final boolean res = UiDevice.getInstance().click(posVals.get(0),
posVals.get(1));
return getSuccessResult(res);
}
}
}
@@ -1,19 +1,11 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import java.util.Hashtable;
/**
* This handler is used to set text in elements that support it.
@@ -55,9 +47,6 @@ public class SetText extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
@@ -1,20 +1,13 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import java.util.Hashtable;
import org.json.JSONException;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;
import io.appium.android.bootstrap.utils.Point;
import org.json.JSONException;
import java.util.Hashtable;
/**
* This handler is used to swipe.
@@ -49,8 +42,6 @@ public class Swipe extends CommandHandler {
final AndroidElement el = command.getElement();
absStartPos = el.getAbsolutePosition(start);
absEndPos = el.getAbsolutePosition(end, false);
} catch (final ElementNotInHashException e) {
return getErrorResult(e.getMessage());
} catch (final UiObjectNotFoundException e) {
return getErrorResult(e.getMessage());
} catch (final InvalidCoordinatesException e) {
@@ -60,8 +51,8 @@ public class Swipe extends CommandHandler {
}
} else {
try {
absStartPos = GetDeviceAbsPos(start);
absEndPos = GetDeviceAbsPos(end);
absStartPos = getDeviceAbsPos(start);
absEndPos = getDeviceAbsPos(end);
} catch (final InvalidCoordinatesException e) {
return getErrorResult(e.getMessage());
}
@@ -1,13 +1,12 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import java.io.File;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to TakeScreenshot.
*
@@ -1,11 +1,10 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
import com.android.uiautomator.common.ReflectionUtils;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
/**
* This handler is used to perform a touchDown event on an element in the
@@ -1,22 +1,13 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.android.bootstrap.exceptions.ElementNotInHashException;
import android.graphics.Rect;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.Hashtable;
import org.json.JSONException;
import android.graphics.Rect;
import com.android.uiautomator.core.UiObjectNotFoundException;
/**
* This handler is and abstract class that contains all the common code for
* touch event handlers.
@@ -90,8 +81,6 @@ public abstract class TouchEvent extends CommandHandler {
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final ElementNotInHashException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) {
return getErrorResult(e.getMessage());
}
@@ -1,14 +1,12 @@
package io.appium.android.bootstrap.handler;
import android.os.SystemClock;
import com.android.uiautomator.common.ReflectionUtils;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
import android.os.SystemClock;
import com.android.uiautomator.common.ReflectionUtils;
import com.android.uiautomator.core.UiObjectNotFoundException;
/**
* This handler is used to long click elements in the Android UI.
*
@@ -1,11 +1,10 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
import com.android.uiautomator.common.ReflectionUtils;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
/**
* This handler is used to perform a touchMove event on an element in the
@@ -1,11 +1,10 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
import com.android.uiautomator.common.ReflectionUtils;
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.Logger;
import java.lang.reflect.Method;
/**
* This handler is used to perform a touchUp event on an element in the Android
@@ -3,15 +3,13 @@ package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.handler.Find;
import io.appium.android.bootstrap.Logger;
import org.json.JSONObject;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import org.json.JSONObject;
/**
* This handler is used to update the apk strings.
*
@@ -1,14 +1,12 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import org.json.JSONException;
import java.util.Hashtable;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import org.json.JSONException;
import java.util.Hashtable;
/**
* This handler is used to clear elements in the Android UI.
@@ -1,11 +1,10 @@
package io.appium.android.bootstrap.handler;
import android.os.RemoteException;
import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import android.os.RemoteException;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to power on the device if it's not currently awake.
@@ -4,13 +4,18 @@ import io.appium.android.bootstrap.exceptions.InvalidStrategyException;
/**
* An emumeration of possible strategies.
*
*/
public enum Strategy {
CLASS_NAME(0, "class name"), CSS_SELECTOR(1, "css selector"), ID(2, "id"), NAME(
3, "name"), LINK_TEXT(4, "link text"), PARTIAL_LINK_TEXT(5,
"partial link text"), INDEX_PATHS(7, "index paths"), DYNAMIC(8, "dynamic"), ACCESSIBILITY_ID(
9, "accessibility id"), ANDROID_UIAUTOMATOR(10, "-android uiautomator");
CLASS_NAME("class name"),
CSS_SELECTOR("css selector"),
ID("id"),
NAME("name"),
LINK_TEXT("link text"),
PARTIAL_LINK_TEXT("partial link text"),
INDEX_PATHS("index paths"),
DYNAMIC("dynamic"),
ACCESSIBILITY_ID("accessibility id"),
ANDROID_UIAUTOMATOR("-android uiautomator");
public static Strategy fromString(final String text)
throws InvalidStrategyException {
@@ -25,52 +30,13 @@ public enum Strategy {
+ "' is not supported on Android");
}
private final int strategyCode;
private final String strategyName;
private Strategy(final int code, final String name) {
strategyCode = code;
private Strategy(final String name) {
strategyName = name;
}
public int compareTo(final String anotherString) {
return strategyName.compareTo(anotherString);
}
public int compareToIgnoreCase(final String str) {
return strategyName.compareToIgnoreCase(str);
}
public boolean contains(final CharSequence s) {
return strategyName.contains(s);
}
public boolean contentEquals(final CharSequence cs) {
return strategyName.contentEquals(cs);
}
public boolean contentEquals(final StringBuffer sb) {
return strategyName.contentEquals(sb);
}
public boolean endsWith(final String suffix) {
return strategyName.endsWith(suffix);
}
public boolean equalsIgnoreCase(final String anotherString) {
return strategyName.equalsIgnoreCase(anotherString);
}
public int getStrategyCode() {
return strategyCode;
}
public String getStrategyName() {
return strategyName;
}
public boolean matches(final String regex) {
return strategyName.matches(regex);
}
}
}
@@ -40,8 +40,7 @@ public abstract class ElementHelpers {
List<AndroidElement> result = new ArrayList<AndroidElement>();
List<AccessibilityNodeInfo> nodes = new ArrayList<AccessibilityNodeInfo>();
for (int index = 0; index < elements.size(); index++) {
AndroidElement element = elements.get(index);
for (AndroidElement element : elements) {
AccessibilityNodeInfo node = elementToNode(element);
if (!nodes.contains(node)) {
nodes.add(node);
@@ -1,9 +1,9 @@
package io.appium.android.bootstrap.utils;
import static io.appium.android.bootstrap.utils.API.API_18;
import com.android.uiautomator.core.UiDevice;
import static io.appium.android.bootstrap.utils.API.API_18;
public abstract class NotImportantViews {
// setCompressedLayoutHeirarchy doesn't exist on API <= 17
// http://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo.html#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
@@ -2,7 +2,6 @@ package io.appium.android.bootstrap.utils;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.Logger;
public class TheWatchers {
@@ -18,13 +18,10 @@ public class UnicodeEncoder {
for (int i = 0; i < chars.length; i++) {
int cp = Character.codePointAt(chars, i);
if (cp > 0x7F) {
if (cp >= 0xE000 && cp <= 0xE040) {
// Selenium uses a Unicode PUA to cover certain special characters
// see https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/Keys.java
// these should juse be passed through as is.
return false;
}
return true;
// Selenium uses a Unicode PUA to cover certain special characters
// see https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/Keys.java
// these should juse be passed through as is.
return !(cp >= 0xE000 && cp <= 0xE040);
}
}
return false;