在ui automation android

时间:2017-03-15 10:10:15

标签: android ui-automation

在Android app中ui自动化期间获取错误。我已经实现了简单的LoginScreen,其中包含两个编辑文本,一个用于电子邮件,一个用于密码,一个登录按钮。运行测试类时,我总是遇到这种类型的线程错误。任何人都可以告诉我为什么会出现这个错误。我已经为另一个项目实现了相同的代码,那个时候也面临着这个错误。

错误: -

Thread[Compiler,5,system]
                                                                         dalvik.system.NativeStart.run(Native Method)

                                                                       Thread[Binder_2,5,main]
                                                                         dalvik.system.NativeStart.run(Native Method)

                                                                       Thread[ReferenceQueueDaemon,5,system]
                                                                         java.lang.Object.wait(Native Method)
                                                                         java.lang.Object.wait(Object.java:364)
                                                                         java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:130)
                                                                         java.lang.Thread.run(Thread.java:841)



Thread[Binder_1,5,main]
                                                                     dalvik.system.NativeStart.run(Native Method)

                                                                   Thread[FinalizerDaemon,5,system]
                                                                     java.lang.Object.wait(Native Method)
                                                                     java.lang.Object.wait(Object.java:401)
                                                                     java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
                                                                     java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
                                                                     java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
                                                                     java.lang.Thread.run(Thread.java:841)

                                                                   Thread[FinalizerWatchdogDaemon,5,system]
                                                                     java.lang.Object.wait(Native Method)
                                                                     java.lang.Object.wait(Object.java:364)
                                                                     java.lang.Daemons$FinalizerWatchdogDaemon.waitForObject(Daemons.java:230)
                                                                     java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:207)
                                                                     java.lang.Thread.run(Thread.java:841)

                                                                   Thread[Instr: android.support.test.runner.AndroidJUnitRunner,5,main]
                                                                     dalvik.system.VMStack.getThreadStackTrace(Native Method)
                                                                     java.lang.Thread.getStackTrace(Thread.java:579)
                                                                     java.lang.Thread.getAllStackTraces(Thread.java:521)
                                                                     android.support.test.runner.MonitoringInstrumentation.getThreadState(MonitoringInstrumentation.java:501)
                                                                     android.support.test.runner.MonitoringInstrumentation.dumpThreadStateToOutputs(MonitoringInstrumentation.java:496)
                                                                     android.support.test.runner.MonitoringInstrumentation.waitForActivitiesToComplete(MonitoringInstrumentation.java:307)
                                                                     android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:273)
                                                                     android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:282)
                                                                     android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:271)
                                                                     android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

                                                                   Thread[GC,5,system]
                                                                     dalvik.system.NativeStart.run(Native Method)

                                                                   Thread[JDWP,5,system]
                                                                     dalvik.system.NativeStart.run(Native Method)

                                                                   Thread[OkHttp ConnectionPool,5,main]
                                                                     java.lang.Object.wait(Native Method)
                                                                     java.lang.Thread.parkFor(Thread.java:1205)
                                                                     sun.misc.Unsafe.park(Unsafe.java:325)
                                                                     java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:197)
                                                                     java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2056)
                                                                     java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:435)
                                                                     java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
                                                                     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
                                                                     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                     java.lang.Thread.run(Thread.java:841)

                                                                   Thread[hwuiTask1,5,main]
                                                                     dalvik.system.NativeStart.run(Native Method)

                                                                   Thread[Signal Catcher,5,system]
                                                                     dalvik.system.NativeStart.run(Native Method)

                                                                   Thread[main,5,main]
                                                                     android.os.BinderProxy.transact(Native Method)
                                                                     android.app.ActivityManagerProxy.finishActivity(ActivityManagerNative.java:2272)
                                                                     android.app.Activity.finish(Activity.java:4216)
                                                                     android.support.test.runner.MonitoringInstrumentation$ActivityFinisher.run(MonitoringInstrumentation.java:655)
                                                                     android.os.Handler.handleCallback(Handler.java:733)
                                                                     android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     android.os.Looper.loop(Looper.java:136)
                                                                     android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                     java.lang.reflect.Method.invokeNative(Native Method)
                                                                     java.lang.reflect.Method.invoke(Method.java:515)
                                                                     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                     dalvik.system.NativeStart.main(Native Method)

MainActivity.java

public class MainActivity extends AppCompatActivity {
    Button btn_login;
    EditText et_username,et_password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_login=(Button)findViewById(R.id.btn_login);
        et_username=(EditText) findViewById(R.id.et_username);
        et_password=(EditText)findViewById(R.id.et_password);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String email_enter = et_username.getText().toString();
                String pass_enter = et_password.getText().toString();
                userLogin(email_enter,pass_enter);
            }
        });
    }

    public void userLogin(String emailenter, String passenter) {
        Intent i = new Intent(MainActivity.this,SecondActivity.class);
        startActivity(i);
    }

MainActivityTest.java

public class MainActivityTest{
    UiDevice device;
    MainActivity loginScre;
    public void setUp() throws Exception {
        loginScre = new MainActivity();
    }
    @Test
    public void getIntValue() throws Exception {
        device = UiDevice.getInstance(getInstrumentation());
        device.pressHome();
        device.wait(Until.hasObject(By.desc("Apps")), 3000);
        UiObject2 appsButton = device.findObject(By.desc("Apps"));
        appsButton.click();
        device.wait(Until.hasObject(By.desc("LoginDemo")), 3000);
        UiObject2 calculatorApp = device.findObject(By.text("LoginDemo"));
        calculatorApp.click();
        UiObject editText = new UiObject(new UiSelector().resourceId("example.com.logindemo:id/et_username"));
        editText.setText("abc@gmail.com");
        String emainEnter = editText.getText().toString();
        UiObject psswrd = new UiObject(new UiSelector().resourceId("example.com.logindemo:id/et_password"));
        psswrd.click();
        psswrd.setText("abc23$");
        String psswrdEnter = "abc23$";
        device.wait(Until.hasObject(By.text("Login")), 1000);
        UiObject2 buttonlogin = device.findObject(By.text("Login"));
        buttonlogin.click();
        loginScre.userLogin(emainEnter, psswrdEnter);
    }

0 个答案:

没有答案