The Dumpwindowhierarchy of Bootstrap

Source: Internet
Author: User
Tags appium

Dumpwindowhierarchy


Package Io.appium.android.bootstrap.handler;import Android.os.environment;import Com.android.uiautomator.core.uidevice;import Io.appium.android.bootstrap.androidcommand;import Io.appium.android.bootstrap.androidcommandresult;import Io.appium.android.bootstrap.commandhandler;import Io.appium.android.bootstrap.utils.notimportantviews;import java.io.file;/** * This handler are used to Dumpwindowhierarchy. * https://android.googlesource.com/* Platform/frameworks/testing/+/master/uiautomator */library/core-src/com/ Android/uiautomator/core/uidevice.java */@SuppressWarnings ("resultofmethodcallignored") public class Dumpwindowhierarchy extends CommandHandler {//Note that//"New File (Environment.getdatadirectory ()," local/t  MP "), FileName)"//is directly from the Uidevice.java source code.  Private static final File Dumpfolder = new file (Environment.getdatadirectory (), "local/tmp");  private static final String Dumpfilename = "Dump.xml"; private static final File DumpFile = newFile (Dumpfolder, dumpfilename);    private static void Deletedumpfile () {if (dumpfile.exists ()) {dumpfile.delete ();    }} public static Boolean dump () {dumpfolder.mkdirs ();    Deletedumpfile (); try {//dumpwindowhierarchy often has a nullpointerexception uidevice.getinstance (). Dumpwindowhierarchy (DumpFil    ENAME);      } catch (Exception e) {e.printstacktrace ();      If there ' s an error then the dumpfile may exist and is empty.    Deletedumpfile ();  } return dumpfile.exists ();   }/* * @param command the {@link Androidcommand} used for this handler. * * @return {@link Androidcommandresult} * * @throws jsonexception * * @see Io.appium.android.bootstrap.CommandH   Andler#execute (io.appium.android. * Bootstrap. Androidcommand) */@Override public Androidcommandresult Execute (final androidcommand command) {notimportantviews.    Discard (true);  return Getsuccessresult (Dump ()); }}

This method may be unsuccessful on some machines and many people do not know much about this method, and I have done a long event of the development of functional traversal tools, specifically studied this method, look at the article I wrote earlier to understand what it does:


Dumpwindowhierarchy


It is to get all the control information of the current phone interface, and then save the tree structure in the/data/local/tmp directory of the Dump.xml file, so we see the definition of the above class has a lot about the path, the file string, that's why, This dumpwindowhierarchy of Appium is the first to prohibit layout compression based on the different settings of the API. If the API is more than 18, then start the layout compression, which is useful for us to get helpful control information. Then execute the dump () method, the Dump method will first create the directory, of course, the directory will generally exist, no need to create. Then delete the Dump.xml file, because to create a new, you must delete the old, so as not to get the control information, Dump.xml still have the information returned. and then call


Uidevice.getinstance (). Dumpwindowhierarchy (Dumpfilename);

Save the control tree information in the file.


(The Android website is finally ready!) )

The Dumpwindowhierarchy of Bootstrap

Related Article

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.