美文网首页
定制AppiumBootstrap.jar

定制AppiumBootstrap.jar

作者: yangzai | 来源:发表于2017-07-13 16:37 被阅读638次
    1. 下载源码,直接用idea打开会报错,要导入依赖包:android.jar、uiautomator.jar
    2. 修改源码:
      例如在Find类execute方法中添加找不到element打印日志
        if (!multiple) {
            for (int i = 0; i < selectors.size() && !found; i++) {
              try {
                Logger.debug("Using: " + selectors.get(i).toString());
                result = fetchElement(selectors.get(i), contextId);
                found = result != null;
              } catch (final ElementNotFoundException ignored) {
                //在这添加打印日志
                Logger.debug("FoundException: " + ignored.toString());
              }
            }
          } else {
            List<AndroidElement> foundElements = new ArrayList<AndroidElement>();
            for (final UiSelector sel : selectors) {
            ....
              try {
                Logger.debug("Using: " + sel.toString());
                final List<AndroidElement> elementsFromSelector = fetchElements(
                    sel, contextId);
                foundElements.addAll(elementsFromSelector);
              } catch (final UiObjectNotFoundException ignored) {
                //在这添加打印日志
                Logger.debug("FoundException: " + ignored.toString());
              }
            }
            ....
          }
    
    
    1. 用adb forward tcp:4724 tcp:4724映射端口
    2. 利用uiautomatorhelpr编译运行AppiumBootstrap.jar
      此时手机端开始监听4724端口
    3. 给手机端发消息测试下是否通了
        public class PCClient {
    
            public static void main(String[] args) throws IOException {
                System.out.println("任意字符, 回车键发送Toast");
                Scanner scanner = new Scanner(System.in);
                while (true) {
                    String msg = scanner.next();
                    sendMsg(msg);
                }
            }
    
            public static void sendMsg(String msg) throws IOException {
                Socket socket = new Socket("127.0.0.1", 4724);
                DataInputStream dis = new DataInputStream(socket.getInputStream());
                DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
                dos.writeUTF(msg);
                socket.close();
            }
        }
    
    1. 将编译好的AppiumBootstrap.jar(在bin目录下)复制到appium工程的
    2. node_modules/appium-android-bootstrap/bootstrap/bin目录下。

    输出结果:


    这时候就有我们定制的输出语句了

    主意:
    如果手机端uiautomator一直运行会导致下次无法启动,可以使用adb shell ps | find "uiautomator"
    命令查找该进程,并用adb命令杀死adb shell kill [pid]


    QQ图片20180129192831.jpg

    相关文章

      网友评论

          本文标题:定制AppiumBootstrap.jar

          本文链接:https://www.haomeiwen.com/subject/jgzwhxtx.html