In the Android automation test, uiautomator modifies uiautomatorviewer to fail to obtain the dynamic interface.

Source: Internet
Author: User

In the first article:


Comparison of controls obtained by hierarchyviewer and uiautomatorviewer in android automated testing (1)


I said that an error will be reported when uiautomatorviewer obtains the dynamic interface. The error is as follows:




Today, when I learned uiautomator and used dumpWindowHierarchy () to obtain control information, I found that this method can obtain dynamic interface information. This makes up for the defect of uiautomatorviewer. Next we will post the process to you.


The predecessors wrote a lot about how to compile the information of java engineering files. I will give you the connections I learned.


Http://blog.csdn.net/robinzhou/article/details/8447058


I will focus on it. Java code:


package com.ibm.test;import java.io.File;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.core.UiObjectNotFoundException;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class MyUIauto extends UiAutomatorTestCase {private static final String TAG = "MyUIauto";public void testPressHome() throws UiObjectNotFoundException {File file = new File("/data/local/tmp/local/tmp/qian.xml");UiDevice uiDevice = getUiDevice();//uiDevice.pressHome();String realPath = "qian.xml";uiDevice.dumpWindowHierarchy(realPath);}}

I have read the dumpWindowHierarchy method source code:


    public void  [More ...] dumpWindowHierarchy(String fileName) {        AccessibilityNodeInfo root = getAutomatorBridge().getQueryController().getAccessibilityRootNode();        if(root != null) {            AccessibilityNodeInfoDumper.dumpWindowToFile(                    root, new File(new File(Environment.getDataDirectory(),                            "local/tmp"), fileName));        }    }


The default directory on the official website is/data/local/tmp, but the local/tmp directory is added from the source code. The merged directory is the/data/local/tmp directory. This is also the cause of the error caused by creating a directory at first. It always reports a file-free error in/data/local/tmp. Later, I found the source code. Source code Website:


Http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.2_r1/com/android/uiautomator/core/UiDevice.java#UiDevice.dumpWindowHierarchy%28java.lang.String%29


After compiling the java project, use the ant command to generate the jar package, push the jar package to the device, and open the stopwatch. Run the script to get the xml file and capture the local file. View the xml file as follows:


 
 
  
   
    
     
      
       
        
       
      
     
    
    
     
      
       
        
         
         
        
       
       
        
        
        
       
       
        
       
      
     
    
    
     
      
       
        
         
         
        
       
       
        
         
         
        
       
       
        
         
         
        
       
       
        
         
         
        
       
      
     
    
   
  
 

Therefore, this method is the best way to obtain controls.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.