stephenwang1011 / robotium

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

clickOnView does not work on some phones #211

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the Robotium Test case. This launches my android application. This has 4 
ImageView buttons at the bottom. Use solo.waitForActivity(...) to wait and make 
sure this page is completely loaded.

2. use solo.getView(button_id) to get the imageView and then solo.clickOnView 
to click on this ImageView.

3: This works on LG Optimus P500 or all other phones that are classified by 
android as normal for actual screen sizes and density.

But for phones where actual screen sizes and density is small, it does not 
work, example (also does not work for high):
    LG Optimus Me P350
    Samsung Galaxy Fix

More information about screen size at:
http://developer.android.com/guide/practices/screens_support.html

After putting logs in robotium code, I found that in Clicker.java, in method 
clickOnScreen(View view, boolean longClick), a call is made to android 
"getLocationOnScreen", to find out where to to click on the view. This returns 
x and y co-ordinates in pixels.
But this is returning Density-independent pixel (dp), and not the actual pixel 
position on the phone.

For our LG Optimus Me P350, which is classified as "small", the density is 
about .75 of the normal size.

So, in the same method, we modified the code to reduce the pixels we got by .75.

float x = xy[0] + (viewWidth / 2.0f);
float y = xy[1] + (viewHeight / 2.0f);
x=(float) 0.75*x
y=(float) 0.75*y

Now the click works !!!

This is obviously not the final solution, but it does point to the problem. We 
should find the density factor from some android API.

Original issue reported on code.google.com by sandeepa...@gmail.com on 18 Jan 2012 at 5:26

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. It is definitely worth a research :)

Original comment by renasr...@gmail.com on 19 Jan 2012 at 2:30

GoogleCodeExporter commented 9 years ago
So what Clicker is trying to do is press the exact center of the View. There's 
an issue that I've run into where if the center falls EXACTLY in the last row 
of pixels, the Clicker can't click it anymore. Your "fix" might be working just 
because you're shifting the click target to be higher than the center. 

Also, as far as I know, nothing in the Android View code speaks "dp", 
everything is converted from DPs to plain PXs as soon as the elements are 
rendered. 

Original comment by david...@gmail.com on 1 Feb 2012 at 10:28

GoogleCodeExporter commented 9 years ago
I guess I forgot to mention that the real fix should be that if the click 
target falls on the edges, then the Clicker must do some scrolling before 
trying to click.

Original comment by david...@gmail.com on 1 Feb 2012 at 10:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@davidmon, do you have a sample app that exhibits the issue that you are 
describing?

Original comment by renasr...@gmail.com on 4 Apr 2012 at 12:12

GoogleCodeExporter commented 9 years ago
Unfortunately there is no way to find the density factor. Will reopen issue if 
someone finds a way to detect this.

Original comment by renasr...@gmail.com on 10 Apr 2012 at 6:47

GoogleCodeExporter commented 9 years ago
I'm facing the same issue. please tell me if this issue has been fixed? and how 
to fix it? I'm writing a program to simulate some action on Android. In case we 
need to get location of the view and simulate action 'click'. It runs well on 
Android 2. But in Android 4, It always click on wrong position. I got device 
density though displaymatrix on emulator (android development kit). It's 1.0.

Original comment by pyra...@gmail.com on 22 May 2012 at 10:20

GoogleCodeExporter commented 9 years ago
Have you added the below line to the AndroidManifest.xml of the application 
under test?

<supports-screens android:anyDensity="true"/> 

Original comment by renasr...@gmail.com on 22 May 2012 at 10:24

GoogleCodeExporter commented 9 years ago
does this go for the samsung exhibit II as well? solo.clickOnView(popup); 
(popup is a View type) is failing, but works on another samsun phone and an 
emulator. 

I've just added the <supports-screens andriod:anyDensity="true"/> and still not 
working.

Thanks.

Original comment by kali...@gmail.com on 7 Jun 2012 at 10:25