????2. Action??CommandHandler???????
??????????????????????????action????????????????????????‘click’????????????????????е????????????????????????????????????е?????????AndroidCommandExecutor???????????HashMap map?????????飺

class AndroidCommandExecutor {
private static HashMap<String?? CommandHandler> map = new HashMap<String?? CommandHandler>();
static {
map.put("waitForIdle"?? new WaitForIdle());
map.put("clear"?? new Clear());
map.put("orientation"?? new Orientation());
map.put("swipe"?? new Swipe());
map.put("flick"?? new Flick());
map.put("drag"?? new Drag());
map.put("pinch"?? new Pinch());
map.put("click"?? new Click());
map.put("touchLongClick"?? new TouchLongClick());
map.put("touchDown"?? new TouchDown());
map.put("touchUp"?? new TouchUp());
map.put("touchMove"?? new TouchMove());
map.put("getText"?? new GetText());
map.put("setText"?? new SetText());
map.put("getName"?? new GetName());
map.put("getAttribute"?? new GetAttribute());
map.put("getDeviceSize"?? new GetDeviceSize());
map.put("scrollTo"?? new ScrollTo());
map.put("find"?? new Find());
map.put("getLocation"?? new GetLocation());
map.put("getSize"?? new GetSize());
map.put("wake"?? new Wake());
map.put("pressBack"?? new PressBack());
map.put("pressKeyCode"?? new PressKeyCode());
map.put("longPressKeyCode"?? new LongPressKeyCode());
map.put("takeScreenshot"?? new TakeScreenshot());
map.put("updateStrings"?? new UpdateStrings());
map.put("getDataDir"?? new GetDataDir());
map.put("performMultiPointerGesture"?? new MultiPointerGesture());
map.put("openNotification"?? new OpenNotification());
map.put("source"?? new Source());
map.put("compressedLayoutHierarchy"?? new CompressedLayoutHierarchy());
}
???????map?????????????pc???????????action??????????????action???????????????Щ????CommandHandler???????????????????????CommandHandler????????execute?????????????????
???????????action??????AndroidElement???????????UiObject el?????????????????????
????UiDevice????action??????UiDevice???????
????UiScrollable????action??????UiScrollable???????
????UiAutomator??5????????е?action???????InteractionController??????????????QueryController???????á????????????UiAutomator??????????????????????????????????????????????????????????UiAutomator??????????????
???????????????compressedLayoutHierarchy
???????action??CommandHandler??????????????????????AndroidCommandExecutor??execute?????У?
public AndroidCommandResult execute(final AndroidCommand command) {
try {
Logger.debug("Got command action: " + command.action());
if (map.containsKey(command.action())) {
return map.get(command.action()).execute(command);
} else {
return new AndroidCommandResult(WDStatus.UNKNOWN_COMMAND??
"Unknown command: " + command.action());
}
} catch (final JSONException e) {
Logger.error("Could not decode action/params of command");
return new AndroidCommandResult(WDStatus.JSON_DECODER_ERROR??
"Could not decode action/params of command?? please check format!");
}
}
????????????????AndroidCommand????????json?????action??????????
????????????????map?????action?????CommandHandler?????????????
??????????????????????execute??????????????
????3. ?????????
?????????????????????getText???action?????CommandHandler?????????AndroidElement?????????????????????
public class GetText 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()) {
// Only makes sense on an element
try {
final AndroidElement el = command.getElement();
return getSuccessResult(el.getText());
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT??
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error");
}
} else {
return getErrorResult("Unable to get text without an element.");
}
}
}
????????????????????AndroidCommand??getElement??????
????????????????AndroidCommand????????pc???????json????????’params‘???????’elementId'
??????????????id???????????????Appium Android Bootstrap??????????AndroidElement????????????AndroidElement???????
?????????????AndroidElement????????getText??????
?????????????AndroidElement??????UiObject????????getText???????????????
????4. С??
????bootstrap?????appium??pc??????????json?????????????ж????
????cmd: ???????action???????shutdown
????action??????????action????????????action??????click
????params:??????????Щ????????????????????AndroidElementHash????????????????????'elementId'
????????????json????????????
????AndroidCommandExecutor?????AndroidCommand????????????action
????????action?map???????????????????CommandHandler??????????????
??????????????????execute?????????????