jeudi 31 mai 2018

Android UI testing - custom dialog

I need help with Android UI testing. I use Expresso to testing my Login Activity class and i don't know how can i test that custom dialog was show.

This is my code: Test:

@Test
public void validation_return_success() throws InterruptedException {
    /** Set up */
    onView(withId(R.id.editTextUserName)).perform(typeText("username"), closeSoftKeyboard());
    onView(withId(R.id.editTextPassword)).perform(typeText("password"), closeSoftKeyboard());

    /** Execute */
    onView(withId(R.id.loginBtn)).perform(click());

    /** Validation */
    onView(withId(R.id.dialog_progress)).check(matches(isDisplayed()));

This is my ProgressDialog create (Its class ProgresDialog.class and I have layout progress_dialog.xml):

 ProgressDialog
            .newInstance(getString(R.string.progress_authenticating))
            .show(getSupportFragmentManager(), "progress");

And this is my layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dialog_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="24dp"
android:paddingLeft="32dp"
android:paddingRight="48dp"
android:paddingTop="24dp">

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/tvContent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="24dp"
    android:text="wait..."
    android:textSize="16sp" />

Some help how can i test it that after put username and password and click to button will be show dialog... Show the dialog is success end. I try lots of options which i found on internet but nothing work... I stack on dialog which don't hide.

Sorry for my english.

Aucun commentaire:

Enregistrer un commentaire