zoukankan      html  css  js  c++  java
  • [UiAutomator篇][3] 打开音乐应用的测试脚本

    package qq.test;
    
    
    import android.content.Context;
    import android.content.Intent;
    import android.support.test.InstrumentationRegistry;
    import android.support.test.filters.SdkSuppress;
    import android.support.test.runner.AndroidJUnit4;
    import android.support.test.uiautomator.By;
    import android.support.test.uiautomator.UiDevice;
    import android.support.test.uiautomator.Until;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import static org.hamcrest.core.IsNull.notNullValue;
    import static org.junit.Assert.assertThat;
    
    /**
     * Instrumentation test, which will execute on an Android device.
     *
     * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
     */
    @RunWith(AndroidJUnit4.class)
    @SdkSuppress(minSdkVersion = 18)
    public class ChangeTextBehaviorTest {
    
        private static final String BASIC_SAMPLE_PACKAGE
                = "com.android.music";
        private static final int LAUNCH_TIMEOUT = 5000;
        private static final String STRING_TO_BE_TYPED = "UiAutomator";
        private UiDevice mDevice;
    
        public void startMainActivityFromHomeScreen() {
            // Initialize UiDevice instance
            mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    
            // Start from the home screen
            mDevice.pressHome();
    
            // Wait for launcher
            final String launcherPackage = mDevice.getLauncherPackageName();
            assertThat(launcherPackage, notNullValue());
            mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
                    LAUNCH_TIMEOUT);
    
            // Launch the app
            Context context = InstrumentationRegistry.getContext();
            final Intent intent = context.getPackageManager()
                    .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
            // Clear out any previous instances
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(intent);
    
            // Wait for the app to appear
            mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
                    LAUNCH_TIMEOUT);
        }
        @Test
        public void testMusic(){
            startMainActivityFromHomeScreen();
        }
    
    }
    
  • 相关阅读:
    双11享Go了吗?2017阿里双11在线峰会续写科技盛宴!
    python django 原生sql 获取数据
    python 操作mysql
    django post 请求传参
    Django post 报错
    django get请求传参
    windows8.1下装kali linux 2017.3双系统(最新版)
    Django 速成
    Galera将死——MySQL Group Replication正式发布
    Galera将死——MySQL Group Replication正式发布
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/6837484.html
Copyright © 2011-2022 走看看