简体   繁体   中英

Android MonkeyRunner - app closes when clicking on button

I am trying to use MonkeyRunner to login on my virtual device with my gmail address. The issue is that the app closes when clicking on the New button in the google store app.

I am using Genymotion as an emulator.

Here is my script:

import os
import sys
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

device = MonkeyRunner.waitForConnection()

device.startActivity(component='com.google.android.gsf.login/com.google.android.gsf.login.AccountIntroUIActivity')
device.touch(426, 1140, MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(5)

I have also a logcat ouput here , but I didn't see anything really helpful in it.

I don't really know where to look. I have several ideas:

  1. could it be because I am trying to monkey test an app which is not mine? but a google app?
  2. could it be Genymotion handling incorrectly clicks? (typing seems to be ok, it is when it tries to go to the next intent that it fails)

POSSIBLE SOLUTION 1:

So as far as I can see in your code; your package is: com.google.android.gsf.login and your activity is: com.google.android.gsf.login.AccountIntroUIActivity

I know that the usage in the monkeyrunner sample code here is as follows:

runComponent = package + '/' + activity
device.startActivity(component=runComponent)

But it didnt work in my case as well and the app closed. Try using it as below:

package = com.google.android.gsf.login
activity = .AccountIntroUIActivity

runComponent = package + '/' + activity
device.startActivity(component=runComponent)

This works for me. Give it a try yourself as well.

POSSIBLE SOLUTION 2:

It is not a problem to test the apps that is not your with monkeyrunner. Because you are not using the source code at all. So, my suggestion is that make sure you are pressing on the correct buttons or fields when you use device.touch() . This might be causing the issue.

You can try AndroidViewClient/culebra it may not solve your problem as it's very difficult to tell exactly what your problem is, but it would simplify your script development for sure.

Start the Activity manually so it's on the screen.

Run

$ culebra --start-activity=com.google.android.gsf.login/.AccountIntroUIActivity --find-views-with-text=on -o /tmp/script.py

Edit script.py , find the line containing the button you want to touch and add the touch() method. For example if it was

no_id79 = vc.findViewWithTextOrRaise(u'New')

you can add

no_id79.touch()

Then when you run script.py , the Activity will start and the button will be touched.

The issue is that you need to go through the Settings/Add account to be able to create an account. You cannot call the com.google.android.gsf.login.AccountIntroUiActivity directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM