如何随机点击按钮

时间:2023-01-27 15:47:47

I have a menu with x number of buttons that all go to different pages the problem is I have to start at the button at the top n go down I'm order for it work without crashing. If I click on the second or third button without going to the prior buttons I get a crash. I'm not sure if this is the emulator or is there some java code I can put that will allow me to click any button at random? Thanks.

我有一个带有x个按钮的菜单,所有按钮都会转到不同的页面,问题是我必须从顶部的按钮开始n向下我要求工作而不会崩溃。如果我点击第二个或第三个按钮而不转到之前的按钮我就会崩溃。我不确定这是模拟器还是我可以放一些java代码,这样我可以随机点击任何按钮?谢谢。

package com.android.nameofmyappy;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;


public class Mainmenu extends Activity { 

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenu);

    Button Next = (Button) findViewById(R.id.bs);
    Next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Bs.class);
            startActivityForResult(myIntent, 0);

    Button Next = (Button) findViewById(R.id.pa);
    Next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Pa.class);
            startActivityForResult(myIntent, 0);

};
});
};
});
}
}

that is a part of the code i have more buttons that have different id and lead to diff pages successfully if i start at the top button and work to the bottom but i would like to be able to click on any button at random...

这是代码的一部分我有更多的按钮具有不同的ID并导致差异页成功,如果我从顶部按钮开始工作到底部但我希望能够随机点击任何按钮...

1 个解决方案

#1


2  

One way to perform UI fuzzy testing (randomly interacting with all UI element, such as buttons) is monkey runner, you can use adb:

执行UI模糊测试(随机与所有UI元素交互,如按钮)的一种方法是猴子跑步者,你可以使用adb:

adb shell monkey -p <your app's package name> -v 500

This will randomly press anything 500 times to test against crashes.

这将随机按任意500次以测试崩溃。

#1


2  

One way to perform UI fuzzy testing (randomly interacting with all UI element, such as buttons) is monkey runner, you can use adb:

执行UI模糊测试(随机与所有UI元素交互,如按钮)的一种方法是猴子跑步者,你可以使用adb:

adb shell monkey -p <your app's package name> -v 500

This will randomly press anything 500 times to test against crashes.

这将随机按任意500次以测试崩溃。