RobotiumTech / robotium

Android UI Testing
http://www.robotium.org
Apache License 2.0
2.86k stars 786 forks source link

clickLongInList does not work on a gridView #732

Closed renas closed 9 years ago

renas commented 9 years ago

From lena...@gmail.com on January 25, 2015 07:04:21

What steps will reproduce the problem? 1. attach a long click listener on a gridview object

  1. call solo.clickLongInList(0); (assuming cell number 0) 3. What is the expected output? the onItemLongCLickListener to be called on the gridview

What do you see instead? nothing happens

What version of the product are you using? Robotium Solo 5.2.1

On what operating system? Android 4.4 Please provide any additional information below. here is my work code gridView.setAdapter(pictureAdapter); gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { editing = !editing; pictureAdapter.setEditing(editing); return true; } }); and this is my test code public void test7ClickOnGallery_longClickOnCellShouldShowX() { solo.sleep(1000); // wait for grid items to load solo.clickLongInList(0); GridView gridView = solo.getView(GridView.class, 0); if(gridView.getAdapter().getCount()>0) { View firstCell = gridView.getChildAt(0); PictureGridAdapter pictureGridAdapter = (PictureGridAdapter) gridView.getAdapter(); Assertions.assertThat(pictureGridAdapter.isEditing()).isTrue(); PictureGridViewHolder vh = (PictureGridViewHolder) firstCell.getTag(); Assertions.assertThat(vh.isEditing()).isTrue(); assertThat(vh.getImageButton()).isVisible();

    }
}

the above version of the test does not call the longItemClickListener

this version of the test does - and so it passes public void test7ClickOnGallery_longClickOnCellShouldShowX() { solo.sleep(1000); GridView gridView = solo.getView(GridView.class, 0); if(gridView.getAdapter().getCount()>0) { View firstCell = gridView.getChildAt(0); solo.clickLongOnView(firstCell); PictureGridAdapter pictureGridAdapter = (PictureGridAdapter) gridView.getAdapter(); Assertions.assertThat(pictureGridAdapter.isEditing()).isTrue(); PictureGridViewHolder vh = (PictureGridViewHolder) firstCell.getTag(); Assertions.assertThat(vh.isEditing()).isTrue(); assertThat(vh.getImageButton()).isVisible();

    }
}

Original issue: http://code.google.com/p/robotium/issues/detail?id=653

renas commented 9 years ago

From renasr...@gmail.com on January 26, 2015 17:48:07

Thanks for reporting this. Would it be possible for you to share an app that exhibits this issue?

Owner: renasr...@gmail.com

renas commented 9 years ago

From lena...@gmail.com on January 28, 2015 01:27:06

After further investigations it seems that it just doesnt find the right gridview, if i have a ViewPager fragment with several fragments that contain a listview/gridview in them, and the viewpager pages are not 100% in width (less than 100%). My mistake was that I assumed that solo clicks on the currently visible gridview, and it seems that it doesnt. It clicks on the first list/grid that it finds, which is not visible, but is in a viewpager which has a partially visible page - to reproduce that, I'd have to give you my current, app, which I cannot do

renas commented 9 years ago

From renasr...@gmail.com on February 06, 2015 07:47:18

You can specify which View to click with clickLongInList(int line, int index)

Status: WontFix