Monkeyrunner doesn't touch webview
Asked Answered
A

3

6

I need to test android app which includes WebView with buttons.

Monkeyrunner works fine for all parts of the app except WebView. Button in WebView just ignores touches from Monkeyrunner. I see that button is clicked because it became grey but then button does nothing. If I use mouse on emulator or finger on real device then button works great.

I see from logcat that touch event was sent to the app but there is no action from the app.

Some code:

final WebView w = (WebView) findViewById(R.id.webView1);
String summary = "<html><body><b>Google</b><form action=http://google.com><input type=submit><input type=text></form></body></html>";
w.loadData(summary, "text/html", null);

Layout:

 <Button android:id="@+id/button1" android:text="Click me!" />
 <WebView android:id="@+id/webView1" />

Monkeyrunner py:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(10)
# android.widget.Button COORDINATES - THIS WORKS FINE
device.touch(10,100, 'DOWN_AND_UP')
# WEBVIEW BUTTON COORDINATES - BUTTON DOESN'T WORK
device.touch(200,200, 'DOWN_AND_UP')

I had tried separately DOWN delay UP - the same result. Monkeyrunner from Python or from inside Java do not work too. Flavors and wrappers for monkeyrunner like ChimpChat do not work.

I think it should work because there are so many web/HTML5 apps and it couldn't be true that all of them are not tested. But it appears opposite. Any ideas or suggestions how to enforce touch event for WebView components?

Adsorbate answered 9/2, 2013 at 2:29 Comment(7)
Are you testing on a device or emulator?Sermon
At least it should be Emulator. I prefer both.Adsorbate
It works for me (as it is) on a device but fails on emulator.Sermon
Have you tried a device (which) and fails?Sermon
I run it on Samsung Galaxy SIII which has Android 4.1.1Adsorbate
Samsung Galaxy SIII which has Android 4.1.1 has the same result as Emulator. Button changes color as it was touched but then doesn't do the action. Just as described in the original post. And, Emulator works (actually does not) in the same way.Adsorbate
Did anyone figure this out? I am running into the same issue. The suggestion of using keyboard to navigate doesn't work for my needs as I would not know how to navigate there using keyboard.Trehalose
A
3

This was a bug which I had reported to Android team. Some people had confirmed it. However with time it was merged with another bug and later that another bug was closed as "works as designed". Fortunately after few next Android versions it started to work as it supposed to do.

Adsorbate answered 13/5, 2015 at 12:54 Comment(0)
C
0

I've tested the sample code that you've provided and I was able to perform a touch event on the WebView Control without any problems. There are a few ways that I could think of that will make it work for you:

  • Make sure that the touch is at the correct location, note that the touch function uses screen pixels and not dip which will most likely be different when you try to test on multiple devices. You can get the exact location of the button using the "Pointer Location" in the "Dev Tools" app which comes with your emulator.
  • You can use keyboard events instead of touch events to navigate the UI. For example, the sample app that you provided can be done like this:

    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
    device = MonkeyRunner.waitForConnection(10)
    device.press('KEYCODE_DPAD_DOWN')
    device.press('KEYCODE_DPAD_CENTER')
    

    and will produce the desired effect

Carlocarload answered 17/2, 2013 at 6:30 Comment(0)
Z
0

This isn't an answer but I though it might help.

Square released a new instrumentation testing framework called "Spoon". It allows you to do everything you would like and it works pretty well on the few tests I ran. I haven'y tried out webviews but I think it should cover those too. It was created by Jake Wharton (the guy behind ActionBarSherlock). Here's the link if you would like to try it out:

http://square.github.com/spoon/

Zuckerman answered 18/2, 2013 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.