老李推荐:第14章7节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-获取版本号 1

老李推荐:第14章7节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-获取版本号

 

  poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-84505200。

这里获取的版本号有两个,一个是ViewServer自身的版本号,一个是ViewServer当前使用协议的版本号。

我们这里为什么需要获取ViewServer版本以及其协议版本呢?其实主要原因是ViewServer有些功能在老版本上是不支持的,比如HierarchyViewer在列出当前所有Activity窗口的时候,针对获取焦点的窗口会根据不同的ViewServer协议版本而作不同处理,请看源码示例:

316     public static Window[] loadWindows(IHvDevice hvDevice, IDevice device) {  

317         ArrayList<Window> windows = new ArrayList<Window>();  

318         DeviceConnection connection = null;  

319         ViewServerInfo serverInfo = getViewServerInfo(device);  

320         try {  

321             connection = new DeviceConnection(device);  

322             connection.sendCommand("LIST"); //$NON-NLS-1$  

323             BufferedReader in = connection.getInputStream();  

324             String line;  

325             while ((line = in.readLine()) != null) {  

  

...  

          Window w = new Window(hvDevice, line.substring(index + 1), id);  

          windows.add(w);  

        }  

342             // Automatic refreshing of windows was added in protocol version 3.  343             // Before, the user needed to specify explicitly that he wants to  344             // get the focused window, which was done using a special type of  

345             // window with hash code -1.  

346             if (serverInfo.protocolVersion < 3) {  

347                 windows.add(Window.getFocusedWindow(hvDevice));  

348             }  

    } catch (Exception e) {  

     ...  

      }  

    }  

代码14-7-1 协议版本作用示例DeviceBridge-loadWindows

原文地址:https://www.cnblogs.com/poptest/p/5103242.html