How to get validation error message from EdiText in android native application by using UIAUTOMATOR

940 views Asked by At

I am trying to automate a native application in android.In that application I have login functionality.I automated the positive flow.Now I am trying to get the error message which is showing in a popup if i wont fill the Email field.This popup is not identify by the UIAUTOMATORVIEWER.

I am using python and UIAUTOMATOR.Someone please suggest me how to get the error message which is showing in the popup.

Below I am attaching the image. error message in popup.

I want to print 'Field cannot be empty' message shown in the popup.

print self.d(text='Email').text

giving the 'Email' text not the 'Field cant be empty' message.

2

There are 2 answers

0
Syed Nazar Muhammad On

I just wrote this code to give you a path. Do advancements as per your requirment :

Xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/tv_email"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/Black"
        android:text="Email"
        android:textColor="@color/White" />

    <TextView
        android:id="@+id/tv_pass"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/Black"
        android:layout_below="@+id/tv_email"
        android:text="Password"
        android:textColor="@color/White" />

    <FrameLayout 
        android:id="@+id/frame_for_email_error"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/tv_email"
        android:visibility="gone">

        <TextView
        android:id="@+id/tv_pass"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/Gray"
        android:text="Field cannot be empty"
        android:textColor="@color/Black" />

    </FrameLayout>

</RelativeLayout>

And when your Email is !(email.length>0) do like this:

Java code:

FrameLayout frame = (FrameLayout) findviewbyid(R.id.frame_for_email_error);

frame.setvisibility(View.Visible);
0
Inês On

I'm sorry to tell you but you can't. I've had that same problem (for that exact situation and others). All UiAutomator can see is what uiAutomatorViewer identifies.

P.s.: This is also why UiAutomator doesn't read/find an object that is not currently visible on the screen.