suli1 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Using onData with an overlaid View won't properly click on items #151

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an Activity with a ListView and something overlyaing that ListView
2. Use onData() to select an item which is not initially overlaid by the 
overlay.  

I've outlined some code below which illustrates the problem.

layout: 

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

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:title="Hello world"
        android:layout_alignParentTop="true"
        android:background="@android:color/holo_red_dark"/>

</RelativeLayout>

Activity:

public class TestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_layout);
        ListView list = (ListView) findViewById(android.R.id.list);
        View header = new View(this);
        // Probably not an exact conversion, but close enough.
        header.setMinimumHeight((int) (getResources().getDisplayMetrics().density * 56));
        list.addHeaderView(header);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,
                new String[] {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"});
        list.setAdapter(adapter);
    }

}

@RunWith(AndroidJUnit4.class)
public class TestTest extends 
YelpJUnit4ActivityInstrumentationTestCase<TestActivity> {

    private
    public TestTest() {
        super(TestActivity.class);
    }

    @Test
    @MediumTest
    public void test_thatThisBreaks() throws JSONException, IOException {
        getActivity();
        onData(allOf(is(instanceOf(String.class)), is("A"))).perform(click());
        // Do some assertions based on what we'd expect from clicking "A"
    }
}

What is the expected output? What do you see instead?

What I'd expect to see in this case is that my item gets successfully selected.

What I see instead is that Espresso scrolls the desired view to the top of the 
list, below the Toolbar. Then it tries to click on the item.  This results in 
Espresso clicking on the Toolbar instead of the item itself. 

What version of the product are you using? On what operating system?

Espresso 2.1 on Mac OS X Mavericks.  Testing on Genymotion 2.3.0 emulators.

Please provide any additional information below.

There is a thread to discuss this issue on the android-test-kit discuss group: 
https://groups.google.com/forum/#!topic/android-test-kit-discuss/LugJjkxek3E

Original issue reported on code.google.com by ma...@yelp.com on 12 May 2015 at 4:08