天天看点

手机自动化测试:appium源码分析之bootstrap十七 2

控件

performMultiPointerGesture

public boolean performMultiPointerGesture(PointerCoords[] ...touches) {

    try {

      if (API_18) {

        // The compile-time SDK expects the wrong arguments, but the runtime

        // version in the emulator is correct. So we cannot do:

        //   `return el.performMultiPointerGesture(touches);`

        // 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;

      } else {

        Logger.error("Device does not support API < 18!");

        return false;

      }

    } catch (final Exception e) {

      Logger.error("Exception: " + e + " (" + e.getMessage() + ")");

      return false;

    }

  }

UiObject中有直接可以调用的performMultiPointerGesture方法,为什么还要用反射呢。上面的方法里的注释是这样解释的:编译的时候sdk会认为参数是错误的,但是运行时却认为是正确的,所以只有在运行时调用才能保证正确性。反射调用的就是运行时的环境,所以它使用了反射调用了performMultiPointerGesture。

点组