mardi 23 janvier 2018

Testing Pull To Refresh with Robotium

somebody know how i can test the Pull to Refresh function with Robotium? I have an SwipeRefreshLayout, and it work very fine, i have set the adapter and all the necessary. But know i nedd to test it with Robotium but i don't have any idea..

This is my test class, i have do some test..

package com.example.dario.apobus;


import android.annotation.TargetApi;
import android.graphics.PointF;
import android.support.annotation.UiThread;
import android.support.test.annotation.UiThreadTest;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.test.ActivityInstrumentationTestCase2;
import android.view.Gravity;
import android.view.ViewGroup;

import com.robotium.solo.Solo;

import junit.framework.Assert;

@TargetApi(8)
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
    public Solo solo;

    public MainActivityTest() {
        super(MainActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }
    @UiThread
    public void testHelloWorld() throws Exception {
      //  Assert.assertTrue(solo.searchText("Hello blank fragment"));


        //solo.sendKey(Solo.MENU);

        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                ((DrawerLayout)  solo.getView(R.id.drawer_layout)).openDrawer(Gravity.START);




            }
        });
        solo.clickOnMenuItem(solo.getString(R.string.action_nearest_bus_stop));

        solo.scrollToTop();
        solo.scrollUp();
        solo.scrollRecyclerViewToTop(0);
        solo.scrollRecyclerViewToTop(1);
        solo.sendKey(Solo.UP);
        Assert.assertTrue(solo.waitForText("Bus Stop #1"));
    }


    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }
}

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".fragments.BusStopListFragment">
    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:logo="@drawable/splash_image"
        app:title="@string/fragment_bus_stop_list_title"
        />
    <android.support.v4.widget.SwipeRefreshLayout

        android:id="@+id/swipe_refresh_layout"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/bus_stop_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       />
    </android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire