mirror of
https://github.com/appium/appium.git
synced 2026-02-15 06:20:22 -06:00
add getLocation for android
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
package io.appium.android.bootstrap;
|
||||
|
||||
import io.appium.android.bootstrap.exceptions.AndroidCommandException;
|
||||
import io.appium.android.bootstrap.handler.WaitForIdle;
|
||||
import io.appium.android.bootstrap.handler.Clear;
|
||||
import io.appium.android.bootstrap.handler.Click;
|
||||
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.GetDeviceSize;
|
||||
import io.appium.android.bootstrap.handler.GetLocation;
|
||||
import io.appium.android.bootstrap.handler.GetName;
|
||||
import io.appium.android.bootstrap.handler.GetText;
|
||||
import io.appium.android.bootstrap.handler.Orientation;
|
||||
import io.appium.android.bootstrap.handler.SetText;
|
||||
import io.appium.android.bootstrap.handler.Swipe;
|
||||
import io.appium.android.bootstrap.handler.WaitForIdle;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -40,6 +41,7 @@ class AndroidCommandExecutor {
|
||||
map.put("getAttribute", new GetAttribute());
|
||||
map.put("getDeviceSize", new GetDeviceSize());
|
||||
map.put("find", new Find());
|
||||
map.put("getLocation", new GetLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
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 org.json.JSONObject;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
import com.android.uiautomator.core.UiObjectNotFoundException;
|
||||
|
||||
/**
|
||||
* This handler is used to get the text of elements that support it.
|
||||
*
|
||||
*/
|
||||
public class GetLocation 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()) {
|
||||
return getErrorResult("Unable to get location without an element.");
|
||||
}
|
||||
|
||||
try {
|
||||
final JSONObject res = new JSONObject();
|
||||
final AndroidElement el = command.getElement();
|
||||
final Rect bounds = el.getBounds();
|
||||
res.put("x", bounds.left);
|
||||
res.put("y", bounds.top);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -401,7 +401,7 @@ Android.prototype.getAttribute = function(elementId, attributeName, cb) {
|
||||
};
|
||||
|
||||
Android.prototype.getLocation = function(elementId, cb) {
|
||||
cb(new NotYetImplementedError(), null);
|
||||
this.proxy(["element:getLocation", {elementId: elementId}], cb);
|
||||
};
|
||||
|
||||
Android.prototype.getSize = function(elementId, cb) {
|
||||
|
||||
@@ -66,6 +66,17 @@ describeWd('get attribute', function(h) {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should be able to get element location', function(done) {
|
||||
h.driver.elementByName('Animation', function(err, el) {
|
||||
should.not.exist(err);
|
||||
el.getLocation(function(err, loc) {
|
||||
should.not.exist(err);
|
||||
[0].should.include(loc.x);
|
||||
[183].should.include(loc.y);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
// TODO: tests for checkable, checked, clickable, focusable, focused,
|
||||
// longClickable, scrollable, selected
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user