dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.62k stars 347 forks source link

Different screen coordinates when using UIAutomator vs ViewServer #127

Closed mwasilew closed 9 years ago

mwasilew commented 9 years ago

When trying to automate one of the apps, I encounter the problem with UIAutomator: view refreshed too frequently. After googling for a while I found a hint encouraging to use ViewServer instead of UIAutomator. The problem is that I'm getting different widget coordinates when using ViewServer. This means taps are not happening in correct places and automation doesn't work. Example when using dump:

UIAutomator case

dump -x
...
            android.widget.LinearLayout android:id/buttonPanel  (732, 1332, 1096, 140)
               android.widget.Button android:id/button2 Do Not Accept (1390, 1348, 260, 108)
               android.widget.Button android:id/button1 Accept (1650, 1348, 154, 108)

ViewServer case

dump -F -x
...
            android.widget.LinearLayout id/buttonPanel None (32, 1282, 1096, 140)
               android.widget.Button id/button3  (32, 1282, 0, 0)
               android.widget.Space NO_ID None (32, 1282, 634, 0)
               android.widget.Button id/button2 Do Not Accept (690, 1298, 260, 108)
               android.widget.Button id/button1 Accept (950, 1298, 154, 108)
      android.view.ViewStub id/action_mode_bar_stub None (32, 32, 0, 0)

It also seems the layout is slightly different.

Using 'tap input' with first set of coords (from UIAutomator) works fine. The second set doesn't work. I'm using Vellamo 3 as example. It's running on Nexus 10. Any hints how to soleve/fix it?

dtmilano commented 9 years ago

Thanks for reporting it. The difference between the backends is certainly a problem. I would need your help in order to identify the problem and provide the solution. I don't think AndroidViewClient is manipulating the given coordinates a lot, so the possibility also exists that the problem be in ViewServer as well or for some reason the coordinates obtained are relative to a different window. For starters, the number of Views dumped greatly differs between both.

It would be great if you can include a screenshot of the Vellamo screen you are using so we can run the same tests. I'm using VELLAMO 3.1.

dtmilano commented 9 years ago

I found one way of exposing the problem. If you connect adb to your device (or run your emulator) and then:

$ culebra -uG

and

$ culebra -FuG

both at the same time you'll have 2 windows showing the device.

Then, press CTRL+Z on both (to show target zones) you may end up with different zones highlighted in both windows.

mwasilew commented 9 years ago

I tried both culebra calls and there is no difference. I'm stuck in the EULA screen of Vellamo 3.1. vellamo1

CTRL+Z doesn't highlight anything on this screen unfortunately. I checked it with home screen on this device and on Nexus 7. I'm getting pretty colourful rectangles there, but not in this dialog.

Note: I managed to get back on track by disabling animations in Vellamo. UIAutomator doesn't complain about too frequent refreshes any more.

dtmilano commented 9 years ago

I tried culebra on the EULA screen and it works for me. When I click on ACCEPT the line generated in the script is (notice the difference is case):

    self.vc.findViewWithTextOrRaise(u'Accept', root="ROOT").touch()

which of course follows a

    self.vc.dump(window=-1)

On Wed, Jan 14, 2015 at 11:23 AM, mwasilew notifications@github.com wrote:

I tried both culebra calls and there is no difference. I'm stuck in the EULA screen of Vellamo 3.1. [image: vellamo1] https://cloud.githubusercontent.com/assets/618901/5742353/4f65ef20-9c09-11e4-9536-6acae9374b3b.png

CTRL+Z doesn't highlight anything on this screen unfortunately. I checked it with home screen on this device and on Nexus 7. I'm getting pretty colourful rectangles there, but not in this dialog.

Note: I managed to get back on track by disabling animations in Vellamo. UIAutomator doesn't complain about too frequent refreshes any more.

— Reply to this email directly or view it on GitHub https://github.com/dtmilano/AndroidViewClient/issues/127#issuecomment-69943096 .

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

mwasilew commented 9 years ago

So are you getting the colourful rectangles on EULA screen when pressing CTRL+Z in culebra (with GUI) ? The culebra window is larger than my screen. Maybe this is the reason. On the other hand I'm getting the rectangles on other views.

dtmilano commented 9 years ago

If the window is larger use --scale=float option, for example --scale=0.5

On Thu, Jan 15, 2015 at 9:26 AM, mwasilew notifications@github.com wrote:

So are you getting the colourful rectangles on EULA screen when pressing CTRL+Z in culebra (with GUI) ? The culebra window is larger than my screen. Maybe this is the reason. On the other hand I'm getting the rectangles on other views.

— Reply to this email directly or view it on GitHub https://github.com/dtmilano/AndroidViewClient/issues/127#issuecomment-70092249 .

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients