(C) tools and methods to obtain elements

(A) element positioning tool ---- Appium

1. After installing appium-desktop-V1.9.1 (also can install the latest), installed, run Appium

2. When the following screen, click Start Server V1.9.1, start the service

3. officially entered appium interface, click Start Inspector Session, to enter the following interface:

Entering Appium Inspector (a positioner) below, where the configuration information needed Desired Capabilities (need to add the necessary information to the code):

Here at Android as an example:

platformName:  Android

platformVersion: Android version

deviceName: Android machine name

appPackage: app package name

appActivity:  Activity名称

Obtaining deviceName not previously talked about, in fact, open the Debug mode in android device, connected to the computer, open CMD enter: adb devices

4. Click Save As .......... To save, set up after the information is stored in the "Saved Capability Sets" in ease of use, you can click Start Session to start the corresponding app, and use this to get the elements will be a bit slow,

 

Below, start Mail

 

As shown below, click on the clock icon in the top right corner of the red circle on the emergence of the information in the figure below, this information is to be used to locate the alarm-interface elements

 

The method used to obtain the above-described elements is relatively slow, the second described below;

(B) the elements of positioning tool ---- uiautomatorviewer

Uiautomatorviewer is Android SDK comes with an element positioning tool, but if APP page elements and more cases, the tool will crash, get less than the elements, in fact, comes with a new version of appium positioning functions, if they can be used directly, you do not need to use uiautomatorviewer

1. Open the android SDK directory E: \ Android \ android-sdk \ tools, double-click operation uiautomatorviewer.bat

Note: In many cases this does not open, not very recommended

(三)用截图的方式来获取元素

可以用截图的方式,这个方式比较快,但是比较繁琐,下面来介绍一下操作步骤:
1.新建一个.txt文件夹,在文件夹内写入一下几行命令:

@echo
adb shell uiautomator dump /sdcard/app.uix
adb pull /sdcard/app.uix F:\uix\app.uix
adb shell screencap -p /sdcard/app.png
adb pull /sdcard/app.png F:\uix\app.png

pause

2.命令写好后,将文件保存,然后将刚刚那个.txt文件后缀改为.bat,如下图,我将uni.txt改成了uni.bat文件

3.将android设备打开调试模式,连接到电脑,将要定位元素所在界面打开,然后运行刚刚那个.bat文件;例如:我要定位到时钟应用,就将时钟所在界面截图下来

点击.bat的文件后,界面是这样的

 

出现上图,就说明运行成功了,j截图已经保存到F:\uix  文件夹了

4.打开android SDK目录E:\Android\android-sdk\tools,双击运行uiautomatorviewer.bat

选好了,后就如下图所示,这样就可以获取界面元素了

 

Guess you like

Origin www.cnblogs.com/xiongxiaoyan/p/11271849.html