austgl / robotium

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

Cannot find EditText that is offscreen in a ScrollView #163

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1. A app, reproducing the problem is attached. 
2. The following tests provokes the problem:
    public void testAfterToggelingVisibilityEditTextShouldHaveIndex5() {
        //Hide keyboard
        solo.goBack();
        solo.clickOnButton(0);
        solo.enterText(5, "Visible");
        assertNotNull(solo.getEditText("Visible"));
    }

What is the expected output? What do you see instead?
Expected the text "Visible" to be entered into EditText with index 5. 

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

Please provide any additional information below.

I've been digging a bit at the issue, and the last EditText gets removed from 
the list of current EditTexts because it "isViewSufficientlyShown" returns 
false. 
The height of the containing (at least on a Desire HD) ScrollView is 800. 
This causes "(xyView[1] + (viewHeight/2.0f) > getScrollListWindowHeight(view))" 
to evaluate to false because the EditText in question has a y index of above 
1000. 

I'm more than willing to provide a fix but I have a question regarding 
isViewSufficientlyShown's contract:
isViewSufficientlyShown() supposed to return true only if the view is currently 
on the visible part of the screen? (akin to ViewAsserts.assertOnScreen()). 

Or is it OK if it returns "true" if view is in a ScrollView/ListView and can be 
scrolled to? 
Ie. instead if using "getHeight" doing something similar to  
"computeVerticalScrollRange()".  

Original issue reported on code.google.com by e...@lesspainful.com on 21 Sep 2011 at 11:10

Attachments:

GoogleCodeExporter commented 9 years ago
That is according to design. If the component is not visible on the screen then 
you can not interact with it. What you need to do is to scroll down until it is 
visible on the screen. So add scrollDown() between clickOnButton(0) and 
enterText(5, "Visible").

Original comment by renasr...@gmail.com on 22 Sep 2011 at 8:02

GoogleCodeExporter commented 9 years ago

Ok. 
I have a few questions regarding the design.

If I scroll down will the index change depending on how many EditText are 
presently on screen?
The issue arose when using the same test on two devices with different screen 
sizes. 
So a given EditText might be off screen depending on screen resolution and it 
will be difficult to determine the correct index because it depends on screen 
size/resolution. 

I will probably try and add functionality that solves my current issue.
That is: A variant of "solo.enterText" where the indexes are independent of 
what EditTexts are currently on screen. 
The variant should ensure that the EditText is on screen before entering text 
into it. 

Would you prefer a solo.enterText variant with a extra parameter or a new 
method name?

I will issue a pull request when its done and you can see if its something you 
would like to pull into master. 

Thanks for the prompt reply. 

Original comment by erik.mej...@gmail.com on 22 Sep 2011 at 11:34

GoogleCodeExporter commented 9 years ago
The design was implemented to make the various solo methods behave similar on 
ScrollViews and ListViews. The views in ListViews only exist if they are shown 
on the screen. So if an EditText needs scrolling to be shown in a ListView then 
Robotium will not know that it exists until it is actually shown on the screen. 

Original comment by renasr...@gmail.com on 22 Sep 2011 at 3:01

GoogleCodeExporter commented 9 years ago
Hi,

I face the same problem. Robotium says Unable to find item when EditText is 
offscreen in scroll view. when I scroll drown then index of EditText is 
changing. I cant even access them with R.id because they are generated 
programmatically

Please Help.
Thank you.

Original comment by bhanu7...@gmail.com on 9 May 2014 at 10:43

GoogleCodeExporter commented 9 years ago
@bhanu, what methods are you using? If you use enterText() then it will 
automatically scroll until it finds the EditText. 

Original comment by renasr...@gmail.com on 9 May 2014 at 11:33

GoogleCodeExporter commented 9 years ago
Hi,
Thank you for your quick response. ya I am using enterText() method but it take 
index as one of its parameters rite??
for example. Here is my code  
  if(solo.searchText("Address")){
           solo.enterText(4, "Address");
       }

I cant fill Address in Address edittext

Original comment by bhanu7...@gmail.com on 9 May 2014 at 11:41

GoogleCodeExporter commented 9 years ago
You should remove the searchText and just use enterText.

Original comment by renasr...@gmail.com on 9 May 2014 at 11:51

GoogleCodeExporter commented 9 years ago
I can Scroll to that particular EditText but unable to fill values in it 
because it changes its EditText index. The EditText which is at 5th place 
should have index as 5. but as the screen is scrolling the index is changing to 
1. when I tried to enter value in 5th EditText by giving its index as 1 is 
working fine but I cant do this for all controls because I cant predict the 
exact index of the controls after the screen is scrolledup.

Please help I am unable to go further.. I am just stucked.

Thank you.

Original comment by bhanu7...@gmail.com on 9 May 2014 at 11:58

GoogleCodeExporter commented 9 years ago
No.. I am sorry if I dont use searchText() I cant find the item which is 
offscreen.

Original comment by bhanu7...@gmail.com on 9 May 2014 at 12:00

GoogleCodeExporter commented 9 years ago
So enterText does not scroll until it finds the edit text?

Original comment by renasr...@gmail.com on 9 May 2014 at 12:39

GoogleCodeExporter commented 9 years ago
yeah...

Original comment by bhanu7...@gmail.com on 9 May 2014 at 12:49

GoogleCodeExporter commented 9 years ago
Would it be possible for you to send me your apk?

Original comment by renasr...@gmail.com on 9 May 2014 at 12:50

GoogleCodeExporter commented 9 years ago
hmmmm.... sorry I cant send it..

Original comment by bhanu7...@gmail.com on 9 May 2014 at 1:01

GoogleCodeExporter commented 9 years ago
Hi,
Can you please give me any solution for that. Actually please tell me are there 
only two ways to access an element in Robotium.?? one with index and the other 
with R.id...
Is there any way to access elements rather than these two ways??

Please Help,
Thank you.

Original comment by bhanu7...@gmail.com on 12 May 2014 at 11:34