xiaofans / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

solo.clickOnButton(name/id) not working in a loop. #407

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.make a ListView.
2.create a button inside each screen which is displayed when we click ListView
3.Iterate over each element in ListView and click the button everytime.

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

It should click the button everytime. But it clicks only for the first time, 
doesn't click after that.

What version of the product are you using? On what operating system?
robotium 3.6, windows xp

Please provide any additional information below.

Original issue reported on code.google.com by raghav.mahajan000@gmail.com on 7 Mar 2013 at 1:48

GoogleCodeExporter commented 9 years ago
Please paste the test case. 

Original comment by renasr...@gmail.com on 7 Mar 2013 at 2:12

GoogleCodeExporter commented 9 years ago
for(int i=0; i < list.getAdapter().getCount(); i++){
            solo.clickOnView(getViewAtIndex(list, i, getInstrumentation()));

            solo.assertCurrentActivity("DetailsActivity not found", "DetailsActivity");
            Button fullDetails = (Button) solo.getCurrentActivity().findViewById(
                    R.id.btn);
                solo.sleep(2000);
                //solo.waitForView(fullDetails, 4000, true);
                solo.clickOnView(fullDetails);
                    solo.goBack();
                  }         

public View getViewAtIndex(final ListView listElement, final int indexInList, 
Instrumentation instrumentation) {
        ListView parent = listElement;
        if (parent != null) {
            if (indexInList <= parent.getAdapter().getCount()) {
                scrollListTo(parent, indexInList, instrumentation);
                int indexToUse = indexInList - parent.getFirstVisiblePosition();
                return parent.getChildAt(indexToUse);
            }
        }
        return null;
    }

    public <T extends AbsListView> void scrollListTo(final T listView,
            final int index, Instrumentation instrumentation) {
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                listView.setSelection(index);
            }
        });
        instrumentation.waitForIdleSync();
    }

Original comment by raghav.mahajan000@gmail.com on 7 Mar 2013 at 2:17

GoogleCodeExporter commented 9 years ago
This is an issue with your code. 

Instead of this:

Button fullDetails = (Button) solo.getCurrentActivity().findViewById(
                    R.id.btn);

Use 

Button fullDetails = (Button) solo.getView)(
                    R.id.btn);

and use solo.scrollListToLine() instead of the method you have pasted. 

Original comment by renasr...@gmail.com on 7 Mar 2013 at 2:25

GoogleCodeExporter commented 9 years ago
I changed it to what you said..but still not working.. it doesn't click button 
after first time.

Original comment by raghav.mahajan000@gmail.com on 7 Mar 2013 at 2:41