Giter VIP home page Giter VIP logo

xpath_uiautomatorviewer's Introduction

自定义uiautomatorviewer xpath功能

  • 在使用自动化测试中需要定位元素.一般都是使用sdk下面的uiautomatorviewer,而此工具只能定位id,class,name等,但是没有xpath

  • 超级链接 - 源码下载uiautomatorviewer

  • 需要依赖的文件

    • 对应的android.jar
    • com.google.guava_XXX.jar
    • common.jar
    • ddmlib.jar
    • org.eclipse.core.commands_XXX.jar
    • org.eclipse.equinox.common_XXX.jar
    • org.eclipse.jface_XXX.jar
    • org.eclipse.swt.XXX.jar
  • org.eclipse.jdt.core.prefs 这里的设置文件要注意下,有时候会报错java的编译版本错误,此坑坑得我太深

  • com.android.uiautomator:存放uiautomatorviewer工具的GUI界面代码,其中主入口UiAutomatorViewer.java文件里面有main函数入口,工具的窗口就在此创建。

  • com.android.uiautomator.actions:存放所有anction操作,如:Device screenshot 、open等。

  • com.android.uiautomator.tree:存放tree封装,dump出来的xml解析成一棵完整的tree,这个包是核心包。

代码修改部分

com.android.uiautomator.tree

UiNode.class

// 我的新增
    private String getNodeClassAttribute() {
  		return this.mAttributes.get("class");
  	}
	
	  //我的新增
    public String getXpath()
    {
        String className=getNodeClassAttribute();
        String xpath="//"+className;
        String text = getAttribute("text");
        if(text !=null&& !text.equals(""))
        {
            xpath += "[@text='"+text+"']";
            return xpath;
        }else 
        {
            return getAttribute("content-desc") !=""?
                    xpath+"[@content-desc='"+getAttribute("content-desc")+"']"
                    :xpath+"[@index='"+getAttribute("index")+"']";
        }

    }

UiHierarchyXmlLoader.calss

//我的新增
    private UiNode mTmpNode ;
	public BasicTreeNode parseXml(String xmlPath) {
                    //我的修改
                    if (mParentNode != null) {
                        mParentNode.addChild(mWorkingNode);
                        //System.out.println(mNodeList.size());
                        if(mWorkingNode.getParent()!=null){
                        	String xpath = ((UiNode)mWorkingNode).getXpath();
                        	((UiNode)mWorkingNode).addAtrribute("xpath",xpath);
                        }
                        mNodeList.add(mWorkingNode);

                        //System.out.println(mNodeList.size());
                    }

pic.png

xpath_uiautomatorviewer's People

Contributors

louis-me avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.