简体   繁体   中英

MobileFirst Test Workbench ClassCastException during test execution

MobileFirst Test Workbench 8.7 (include in MobileFirst Platform 7.0) Tested device: android 4.4.2 Tested app: native application Android SDK Tools : 23.0.2 Android SDK Platforms-tools : 20 Android SDK Build-tools : 19.1

During test execution, following exception is reported after click event on listView element. This error was not reported while recording test case.

Exception thrown: ClassCastException: android.widget.ListView cannot be cast to android.widget.RelativeLayout
  at com.xx.yy.CatalNavFragment.onItemClick(CatalNavFragment.java:267)
  at android.widget.AdapterView.performItemClick(AdapterView.java:308)
  at android.widget.AbsListView.performItemClick(AbsListView.java:1478)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.actions.Action_itemclickposition.performAction(Action_itemclickposition.java:40)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.actions.Action.performAction(Action.java:101)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.ATestStep$1.run(ATestStep.java:502)
  at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356)
  at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)

Code that raises exception:

 @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        ContentValues niveau = (ContentValues) catalNavAdapter
                .getItem(position);

        id_niveau = niveau.getAsString(CatalProvider.KEY_ID);
        Long niveau_usg = niveau.getAsLong(CatalProvider.KEY_NIVEAU);
        RelativeLayout rlyt = (RelativeLayout) view; //!! EXCEPTION IS RAISED HERE
        TextView txtLibelle = (TextView) rlyt.getChildAt(0);
        Bundle i = new Bundle();
        if (niveau_usg > 0) {
            String subcategory = txtLibelle.getText().toString();
            CatalProdFragment CPF = new CatalProdFragment();
            i.putString("id_niveau", id_niveau);
            i.putLong("niveau_usg", niveau_usg);
            i.putString("subcategory", subcategory);
            i.putString("category", extras.getString("category"));
            CPF.setArguments(i);
            TabHolderFragmentActivity.getMainScreenActivity().pushFragments(parentTab, CPF, CPF
                    .getClass().getSimpleName(), true, true);
        } else {
            CatalNavFragment CNF = new CatalNavFragment();
            i.putString("id_niveau", id_niveau);
            i.putString("category", catalNavAdapter.getData().get(position)
                    .getAsString("libelle"));// category);
            CNF.setArguments(i);
            TabHolderFragmentActivity.getMainScreenActivity().pushFragments(parentTab, CNF, CNF
                    .getClass().getSimpleName(), true, true);
        }
        setExitPageBoolean(false);
    }

ListView layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/catalpage"
    android:background="@color/greybg" >

    <include
        android:id="@+id/include_conatiner"
        layout="@layout/produits_container" />

    <TextView
        android:id="@+id/catal_list_title"
        style="@style/screenHeader"
        android:layout_below="@id/include_conatiner"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="5dp"
        android:gravity="center_vertical"
        android:text="@string/produits_header"
        android:visibility="gone" />

    <ListView
        android:id="@android:id/list"
        style="@style/catal_list"
        android:layout_below="@+id/catal_list_title" />

    <TextView
        android:id="@id/android:empty"
        style="@style/texte.error"
        android:layout_below="@+id/catal_list_title" />

</RelativeLayout>

Listview item layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlyt_cat_nav_item"
    style="@style/catal_list_item" >

    <TextView
        android:id="@+id/catal_nav_libelle"
        style="@style/texte.titre.center"
        android:layout_width="wrap_content"
        android:layout_marginLeft="5dp"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/catal_nav_count_libelle"
        style="@style/texte_parent_right"
        android:padding="5dp"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/catal_nav_id_niveau"
        style="@style/hidden" />

</RelativeLayout>

Thanks for your help

Mathieu

problem comes from a little bug in rtw 8.7 and older version (to make short, some parameter passed to listener are erroneous. position is ok, view isn't) contact our support for 8.7 hotfix, or wait for 8.7.0.1 that include it (should be available very soon)

Jerome Bozier Senior Software Engineer IMB RTW mobile for android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM