Reputation: 1172
I want to know how can I get IDs or names of UI elements used in a mobile application that are used in mobile automation testing like appium, monkey-talk, xamarian etc.
Upvotes: 6
Views: 3867
Reputation: 923
Steps 1: Launch the appium inspector by clicking the inspector button:
Step 2: Set the APK / IPA file path (application file path) as shown below:
Step 3 : Click on Start Session, now you will be navigated to Recorder window:
Click the application UI and perform required action “Selected Element” Tab ie, Tap, SendKeys for entering the text etc.
Selected UI Elements will get exported to Recorder tab after recording the UI Elements of all the elements we can export the Java file.
Upvotes: 0
Reputation: 1172
C#
In my case this piece of code resolved my issue:
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'm using Gherkin language using Xamarin in which Repl() command opens a new cmd in which you can type the tree command and get the tree structure of ui elements on the specific screen you are. This is shown in the image below:
Upvotes: 1
Reputation: 46943
What I explain is for my system (Windows 7), but my explanations should be easily translateable to other systems too.
Prerequisites:
<ANDROID_HOME>
(including the sdk
folder itself)<ANDROID_HOME>/SDK Manager.exe
. Select the latest Android SDK Tools and Android SDK Platform-tools and install them<ANDROID_HOME/platform-tools/adb.exe devices
- if there is at least one device in the list you are good to go.Once you have all that:
Run <ANDROID_HOME>/tools/uiautomatorviewer.bat
. this will open a screen that allows you to take screenshots of the conencted device. See below image:
The screenshot is taken via clicking the button under the purple rectangle, whcih I added artificially. The red one is added by the tool, because I hover the element of interest. You can observe the elements properties on the right. These are usually the properties you would use for testing native application.
If you want to test elements that are loaded in WebView
then it would be better if you use Chrome remote debugging for obtaining the correct selectors.
Footnote:
As I see you are making the very first steps in mobile automation testing, which is an area I am pretty interested into, may I suggest you take a look at the ATMOSPHERE Android test automation framework. Disclaimer: I am one of its creators. Still - it is freely available and open sourced. We also beleive it provides capabilities not supported in other frameworks and is easy to start with so I hope it will be useful for you!
Upvotes: 7