How can I get identifiers, names or x paths for ui elements used in a mobile application (Android / iOS) to test mobile automation?

I want to know how I can get the identifiers or names of user interface elements that are used in a mobile application, which are used in mobile automation tests like appium, monkey-talk, xamarian, etc.

+5
source share
2 answers

What I explain for my system (Windows 7), but my explanations should be easily translated to other systems.

Background

  • When you want to test for Android automation, you should always install the Android SDK, so I assume you already did this. Allows you to call the path to the sdk folder <ANDROID_HOME> (including the sdk folder)
  • Run <ANDROID_HOME>/SDK Manager.exe . Select the latest version of Android SDK Tools and Android SDK Platform-tools and install them.
  • Connect the device you want to check:
    • Or run the emulator - it automatically connects to your system.
    • Or connect a physical device and install the appropriate USB drivers. You cna make sure that the device is connected to the command <ANDROID_HOME/platform-tools/adb.exe devices - if there is at least one device in the list.

Once you have it all:

Run <ANDROID_HOME>/tools/uiautomatorviewer.bat . this will open a screen that allows you to take screenshots of the condensed device. See below image:

enter image description here

The picture was taken with the button under the purple rectangle, which I added artificially. Red is added by the tool because I find an element of interest. You can see the properties of the elements on the right. These are usually the properties that you used to test your own application.

If you want to test elements loaded in WebView , then it would be better to use Chrome remote debugging to get the correct selectors.


Footnote:

As I can see, you are taking the first steps in testing mobile automation systems, and this is a very interesting area, I can offer you a look at the ATMOSPHERE Android Test Automation System. Disclaimer: I am one of its creators. Nevertheless - it is freely available and open. We also believe that it provides features that are not supported in other frameworks and that they are easy to get started, so I hope it will be useful for you!

+5
source

WITH#

In my case, this piece of code resolved my problem:

  private IApp _app = ScenarioContext.Current.Get<IApp>("Application"); private readonly ILoginScreen _loginScreen; private readonly IMainMenuScreen _mainMenuScreen; public Login(ILoginScreen loginScreen, IMainMenuScreen mainMenuScreen) { _app.Repl(); _loginScreen = loginScreen; _mainMenuScreen = mainMenuScreen; } 

I use the Gherkin language, using Xamarin, in which the Repl () command opens a new cmd, in which you can enter the tree command and get the tree structure of the ui elements on a specific screen. This is shown in the figure below:

Xamarin UI Test

+1
source

Source: https://habr.com/ru/post/1259038/


All Articles