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();
        }
    
    }
    
  • 相关阅读:
    Android学习之多线程开发总结<二>
    Android学习之多线程开发总结<一>
    Android代码模版整理<一>
    Android学习之Bluetooth开发总结<续3>
    Android学习—自定义组件
    Android学习之解析XML
    Android学习—自定义对话框Dialog
    Android学习之Bluetooth开发总结<续2>
    Android学习之Bluetooth开发总结<续>
    .Net Core 发布项目时出现警告提示“不建议指定此包的版本”的解决办法
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/6837484.html
Copyright © 2011-2022 走看看