The positioning of the app element failed, what should I do? When I saw how I did it, I was stunned!

Fans will encounter errors similar to the following when positioning elements in their daily android app automation testing work:

 


Then ask the blogger, what is the situation?

I usually send kindly care:

1)adb能识别到设备吗?
2)设备有被其它的程序在占用吗?
3)ADT的版本正确吗?

After the fans have confirmed the above care, the feedback will still encounter such an error.

In order not to affect the enthusiasm for learning, the following three positioning methods will be provided, and there is always one that can allow you to locate the element smoothly! !

The premise of each tool positioning:

  1. At least one android device can be identified through the adb devices command;
  2. The device is not currently occupied by any other application;

The first one: android ADT comes with its own tool: uiAutormatorViewer

The error screenshot at the beginning of the article comes from this tool.

For versions above android 4.2, the built-in automated testing framework is uiAutomator.

uiAutomatorViewer is its element positioning tool.

If you want to use UiAutomator for automated testing, you need to master the java language.
 

Install:

uiAutomatorViewer is part of the Android Debugging Tools (ADT). So you only need to install ADT (no need to install SDK).

  1. Install Android Studio
  1. On the startup page of Android Studio, select Configure -> SDK Manager in the lower right corner

The following picture will pop up: Select Android SDK -> SDK Tools, click the check box in the picture, click OK to enter the installation, and close Android Studio after the installation is complete. Remember the path corresponding to the Android SDK Location in the figure.

 

use:

1. Find the ADT installation directory, find the uiAutomatorViewer program in the tools/bin directory, and double-click to open it.

For example: the directory of ADT is: /Users/liyuan/Library/Android/sdk

 

(Ps: The pro-test currently does not support versions above jdk1.8. So in order to start successfully, you must install jdk1.8.

If jdk11 and jdk1.8 are installed under mac, you need to edit the uiautomatorviewer file, find javaCmd="java",

Change to javaCmd="/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java"

/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java is the java.png corresponding to jdk1.8 version)

2) Positioning elements.

 

The second type: appium inspector of appium

Appium is currently the most popular open source app functional testing framework.

Supports automated testing of IOS and Android at the same time, and also supports multi-language (python/java/C#...png)

Install:

As long as appium is installed, there will be appium inspector.

Appium desktop download address: http://appium.io/

(Ps: You need to install nodejs first, and then install the appium program.)

use:

  1. After starting appium desktop, click the first button in the upper right corner

 

  1. In the following interface that opens, fill in the information as shown in the figure:

 

  1. According to the startup parameters, the corresponding app will be opened, and then the pages in the app will be intercepted.

 

The third type: weditor in python version uiAutomator2

An app automation testing framework implemented in python language.

Install:

Install uiAutomator2: pip install -U uiautomator2

Install the positioning tool weditor: pip install -U weditor

After the installation is complete: Run the command line: weditor --help to confirm whether the installation is successful.

 

use:

  1. Command line input: weditor will automatically open a page shown in 2) in the browser.

!

 

  1. Select Android, enter the serial number of the device, and click connect. Click Dump Hierarchy to see the information of the element.

Summarize:

The above three types of positioning tell you: Any framework for automated testing of apps will provide you with a corresponding positioning tool!

The UiAutomator test framework that comes with android provides uiAutomatorViewer.

The appium testing framework provides appium inspector.

The uiAutomator2 test framework implemented by python provides weditor

In the process of app automation testing, you can use any one to help you locate elements.


Have you lost your studies?

Guess you like

Origin blog.csdn.net/a448335587/article/details/131809905